Archives for category: Uncategorized

I’ve been thinking a lot lately about the way we work with and represent programs: almost exclusively as text files, while they actually have much more structure than that. Python has seemed like a good language to experiment with, so I’ve been looking at the formal grammar of python expressed here as an EBNF (Extended Backus Nauer Form) grammar. This lead me to think, “I should write an EBNF parser of some sort.” The linked page suggests there is a piece of the python build process that consumes the given document and generates a language parser. Parsing a document to generate a new parser. Maybe even its own parser. Seems cool. I also thought, “Know what else is cool? Haskell. I never gave Haskell enough love. I should learn more Haskell (for great good).” So I installed Haskell for Windows (because I work on a Windows laptop these days), fired up powershell, and remembered just how daunting it can be to look at that Haskell prompt:

HaskellPrelude

Also, I wasn’t exactly sure what it should do. So it consumes a grammar, but what does it produce. Another program for consuming grammars? Depending on how we define consuming a grammar, I could do that pretty easily with a program that ignores its arguments and returns itself (think about it). Clearly that’s not what’s intended. Regardless, best to start getting dirty and figure it out as we go. But, still the matter of that pesky intimidating prompt. What to do? Well, maybe I’ll want to split strings by some character (that may be sufficient to parse an EBNF. The parser it generates won’t be able to rely on that). So I try a few commands:

Prelude> split ' ' "Hello World"

<interactive>:1:1: error:
 Variable not in scope: split :: Char -> [Char] -> t

Okay. No split function. So let’s write it. Probably want something recursive (I always jump to recursion. But not before I jump to recursion), but that means we’re probably not working in the prompt. So I opened a file, and eventually wound up with this:

split :: (Eq a) => a -> [a] -> [[a]]
split x [] = []
split x (y:[]) 
 | x == y = split x []
 | otherwise = [[y]]
split x (y1:y2:ys)
 | x == y1 = split x $ y2:ys
 | x == y2 = [y1]:split x ys
 | otherwise = (((:) y1 $ head $ split x $ y2:ys):) $ tail $ split x $ y2:ys

Not the most elegant Haskell one has ever seen. Regardless, let’s look at what this means (this is as much for me as it is for you).

split :: (Eq a) => a -> [a] -> [[a]]

This line is the type signature of the function. Without going into detail about the specifics of the symbols, it states that for any type “a” that is a member of the typeclass “Eq” (which means we can compare things of that type with each other for equality e.g. ints, characters, most things) we define this function to take an “a”, a list of “a” and return a list of lists of “a”. The use of the same symbol to delimit the operands and to indicate the return type is intentional. We can also read this as, “Take an ‘a’, return a function that takes a list of ‘a’ and returns a list of lists of ‘a’.” Neat.

split x [] = []

Now we use pattern matching to specify some cases. If the first operand is anything (x) and the second is an empty list, we want to return an empty list (which was not initially obvious to me. Why not a list containing a single empty list? I actually went back and filled this in once I was convinced).

split x (y:[])

If we get a list with a single element ‘y’ (y:[] means a list beginning with y and ending with an empty list), let’s consider some more specific cases:

 | x == y = split x []

If x== y, get rid of y (its our delimiter) and continue processing the rest of the list.

 | otherwise = [[y]]

Otherwise, just return a list of a list containing y.

split x (y1:y2:ys)

If we have a list with at least 2 things, then we can handle the meat of the problem:

 | x == y1 = split x $ y2:ys

If the first element is our delimiter, ignore it and proceed. The $ means, evaluate the right fully instead of taking the first thing you see (Haskell favors left association). Without the $, Haskell would attempt to evaluate (split x y2): ys which is nonsense and would disagree with our type declaration.

 | x == y2 = [y1]:split x ys

If the first element is not our delimiter and the second element is, we want to return the first element as its own list, and then the result of the rest of the list. Here left association makes things simpler.

 | otherwise = (((:) y1 $ head $ split x $ y2:ys):) $ tail $ split x $ y2:ys

Lastly, if neither of them are the delimiters, then (split x $ y2:ys) will represent how we would split everything ignoring the first character. We know it won’t be an empty list, so we can take the head and tail of it. We want to attach y1 to the head of the list, and reattach that to the tail of the list. And what do you know?

HaskellSuccess

It worked.

Now to the parsing…

Ah the salad days of my youth, when waking up from slumber required nothing more than a slight beam of sunlight, or a soft call from my mother; nothing more was needed for me to spring from my bed, bright-eyed and bushy-tailed and ready to take on a new day full of joy and excitement.

(Well that’s how I remember it, okay)

Since those days, however, waking up has become something different; something to be dreaded; something to be rebelled against on weekends, and indefinitely delayed with snooze buttons. And when I do eventually convince myself that my sweet slumber is less important than the mundane activities I have laid out ahead of me, I resolutely drag my sorry corpse out from under my covers. Bleary-eyed, I grope weakly for the light switch (my last hope in these dim moments to shock myself into some sort of alertness). Then, all is white, and my pupils dilate painfully, bringing me into the land of the living once more.

There has to be a better way.

This morning, I slept through my alarm, and only managed to wake up with a half hour to get showered, dressed, eat, and bike to work. My morning was terrible, I didn’t eat, and narrowly avoided a fatal collision with a jogger in my mad rush to be at work on time. However, for the last two months, mornings like this have been few and far between. This morning prompted me to write a post about what I’ve been doing lately (and did wrong today) to improve my mornings , and reduce my JMR (jogger manslaughter rate).

1. Never Hit Snooze. Ever.

I’m still convinced that had I never had an alarm clock with a snooze button, I’d be able to wake up like a kid on Christmas. Unfortunately, snoozing has become a firmly ingrained habit, to the point that I can set my alarm clock across the room from me and still manage to hit snooze without getting out of bed. (I don’t know how it happens. Just call me Mr. Fantastic). However, on the odd morning where I wake up and realize I do not have time to hit the snooze button (which involves noticing the time, remembering what day it is, and comprehending how much I have to do to get ready, all before my hand hits the snooze button) and I do get up, I find that I’m much more alert and comfortable than when I get up after snoozing even once. Lately I’ve been applying this with reasonable success. I have more presence of mind and don’t need to worry about getting trapped in an endless cycle of poor sleep and strange  dreams that involve ringing things.

This morning, however, I slept straight through my alarm. The snooze button was, therefore, not the culprit. Bringing us to…

2. Do Something in the Morning

Having an actual reason for getting up in the morning helps an awful lot, especially if that reason is something better than going to work (/school). Back when I was getting ready for my grading, I was waking up to complete part of my requirements. While this was a more motivating reason than the job I was later attending, it was not all that exciting (“Yes! 160 more pushups!”)

One thing I do like a lot is eating, especially breakfast foods. One of my fondest summer memories is family breakfasts on the Georgian Bay: eggs, bacon, toast, pancakes, fried potatoes, or whatever else we saw fit to have that day. I’ve thus taken to making large (occasionally too large) breakfasts. While I’m sure my cholesterol has gone up (lol I’m 19. What do I care? I’m going to live forever.) having something to do in the morning that I enjoy is an awesome motivator to get out of that dastardly bed!

This morning, I fully intended to make toad in a hole (fried egg in a hole in a piece of bread) and pancakes, along with a bowl of cereal (Reese Puffs) and fruit. I didn’t get to do this unfortunately (my breakfast consisted of a single plum. There is no emoticon to show how I feel about that). The intention, however, was there, so surely this could not be the culprit either!

This brings us to…

3. Be Less Comfortable

So this part requires a bit of an explanation, as I kind of stumbled upon this. I used to never like making my bed- no, I hated it. So I never did it. At some point last year, some switch inside me flipped, and I grew to really admire a properly made bed. So I began going out of my way to not only make my bed, but to make it as near to perfect as I can. This meant hospital corners and a very tight tuck. I did not go so far as to involve a ruler in these antics, and I never achieved a bed that I could bounce a quarter off of (damn fitted bed-spread…) but I did achieve something that gave a feeling of serenity to some deep, mildly-obsessive part of me. Sleeping under the covers of such a bed, however, invariably destroys all of that work. While it is not a terrible concession to re-make the bed in the morning, during a couple of particularly warm nights, I decided I would be better served by sleeping on top of my bed with a small blanket. I found that I got both a better sleep and I was more alert when I woke up, nearly recreating the readiness I felt as a child. I was not, however, overly comfortable (key plot point).

On Sunday, I participated in an event called the Spartan Sprint in Toronto (which they naturally held in Oro-Medonte Township). Not only did I race, but prior to that I volunteered all day as a gladiator (using a pugil stick (giant Q-tip) to knock people down as they neared the end of the race; thousands of people). By the time I got home on Sunday night, I was exhausted and starting to really feel the days exertions, so I was in need of some comfort. I felt there was no harm in sleeping under the covers. And like most addictive things, the first hit was just great. I slept well, woke up on time, and Monday was just fine. However, as I progressed along this path, the ugly side of the covers showed themselves. Literally. I hadn’t made the bed Monday morning, and so it was all too inviting come Monday night, and I made the mistake of sleeping under the covers for a second night in a row. Thus, in seeking the womb-like comfort of my loose, unmade bed, my entire life fell apart (more or less). I did sleep in two hours after all…

While this post should be viewed as a glaring indictment of the life-sabotaging “comforter” industry, it should not be viewed as critical of sleeping in, in general. It is nice to do when one has such a luxury, and probably has health benefits (sleeping for an unlimited period of time rather than a limited one certainly seems like it would help balance out one’s sleep schedule). I’ve just found that the three things listed here have been very effective at helping me break my addiction to oversleeping.

It’s back.

And this time, it’s flexible.

Actually it’s not. And by it, I mean me. So I’m going to fix that. In three weeks.

At least, that’s the goal. The plan is to do 15 minutes of stretching 4 times a day for the next 3 weeks. “Is this really going to be enough to achieve the splits?” you may ask. Well, to be honest, I have no idea. What I do know, is that I am more productive and enjoy my life more, when I’m working towards a goal and pushing myself. So, the blog is back, and so is a regimen. The regimen for this is going to be as follows:

Session 1:

  • 5 minutes isometric left splits
  • 5 minutes isometric right splits
  • 5 minutes isometric centre splits

Session 2:

  • 5 minutes butterfly sit
  • 5 minutes kneeling groin stretch
  • 5 minutes V-sit

Session 3:

  • 5 minutes left pigeon sit
  • 5 minutes right pigeon sit
  • 5 minutes hanging hamstring stretch

Session 4:

  • 5 minutes left splits
  • 5 minutes right splits
  • 5 minutes centre splits

I like this breakdown a lot, as it begins and ends with the positions that I’m working towards. Also, the first session is designed to tire the muscles that are going to be resisting the position, and it ends with relaxed stretching which will give me a good indicator of how close I am to my goal.

I’ll update with results as I go.

P.S. I’m currently nowhere near the splits. At least 18″ off the ground.

Cheers

Update:

Considering how hard I failed at this and lost interest, I would love to delete this post, but for the sake of my journalistic integrity, I will leave it as a grim-reminder of making commitments with little reason to follow through on them. Splits are still a work in progress, but with nothing near the intensity as was presented in this post. Any further updates will likely occur in their own posts.

Hello, new or returning reader!

A couple of noteworthy things happened this week: I nearly landed a btwist, smashed my foot into the ground, climbed the CN tower, and participated in the October Crispin Shiai in Acton. The btwist, for those of you who don’t know, is an advanced kick in martial arts and a beginner’s kick in “tricking” (combination of gymnastics and martial arts that while having elements of both winds up really being neither). The body rotates 360° while parallel with the ground, landing on the leg that was jumped off of. It looks like this:

So my goal is to land the kick by the end of the week. Unfortunately, since I’m still not landing the kick, and am practicing on fairly firm mats, some scratches and bruises are unavoidable, including, but not limited to landing on the outside edge of my foot while spinning in the air. This resulted in my foot swelling up and me not being able to walk properly for two days. So I’m going to contact Dynamo and Kips to find out about their respective open gym programs, as they have things like soft mats, and foam pits which would be a big help. Also, since I want to eventually teach the demo team how to do this kick, it would be good to have some better options than telling them to throw the kick until they figure out how to land it. On a somewhat more positive note than the sorry state of my foot, I’ve been working on the triple kick (jump, side kick, split kick, roundhouse kick, land) which is coming along nicely. I can basically do jump, side kick, split kick, land, and jump, split kick, roundhouse kick, land, so it shouldn’t be too much of a stretch to get the whole kick. As well I can do a sort of crappy sideswipe, which looks like this:

So I have a gainer and a doubleleg left which I’ve made no progress on at all, and once I have them all individually, I’ll be putting them into combinations. I’ll then be able to make my video and complete that part of my preparation. I’m still a couple of weeks away on that at least.

As well, yesterday I participated in the Enbridge CN Tower Climb for the United Way. This was the corporate climb which I did with a group from work. It’s a fundraiser in which you raise at least $60.00 and then go climb all 1,776 steps of the tower (from the base level up to the main observation area). We got there at 6:30 AM, finished climbing around 8:00 AM, and my official time up the stairs was 18:01 (minutes:seconds). I was pretty winded. After this, I drove to Acton for the October Crispin Shiai, which is a small open level tournament. I spent a good 4 hours judging younger and lower belt competitors before they began the adult black belt divisions (always at the end of the day so they keep their judges). It wasn’t a great showing on my part, and the other competitors did very well in all of the events (weapons, kata, sparring, self defense). I had forgotten a pair of nunchucks at home, so I did my sai kata for the weapons division, receiving 2nd place, did Seipai for the kata division, receiving 4th place, and the sparring division was small (only 3 of us); I won my first match and lost my second, receiving 2nd place. So not an awful showing (I’ve definitely had worse) but not as well as I had hoped. I was pretty tired by the end of that day, and as a result of throwing a few jumping kicks in my sai kata onto the hard gymnasium floor, both feet hurt now.

So, let’s get to the weekly recap:

Monday:

  • 140 Push ups
  • 140 Sit ups
  • 14 rounds of Seipai
  • 40 minutes meditation
  • 2 acts of kindness

Tuesday:

  • 140 Push ups
  • 140 Sit ups
  • 14 rounds of Seipai
  • 20 minutes meditation
  • 1 act of kindness

Wednesday:

  • 140 Push ups
  • 140 Sit ups
  • 1 round of Seipai
  • 14 acts of kindness
  • 2 rounds of sparring

Thursday:

  • 140 Push ups
  • 140 Sit ups
  • 28 rounds of Seipai
  • 40 minutes meditation
  • 3 acts of kindness
  • 16 rounds of sparring

Friday:

  • 140 Push ups
  • 140 Sit ups
  • 14 rounds of Seipai
  • 20 minutes meditation
  • 4 acts of kindness

Saturday:

  • 140 Push ups
  • 140 Sit ups
  • 14 rounds of Seipai
  • 20 minutes meditation
  • 5 acts of kindness

Sunday:

  • 140 Push ups
  • 140 Sit ups
  • 14 rounds of Seipai
  • 20 minutes meditation
  • 6 acts of kindness

So for Week 2 I did: 980 Push ups, 980 Sit ups, 99 rounds of Seipai, 140 minutes of meditation, 18 rounds of sparring, and 36 acts of kindness. I didn’t get my jogging in this week, so that’s the plan for tonight.

Cumulatively, I have: 1,540 Push ups, 1,540 Sit ups, 155 rounds of Seipai, 200 minutes of meditation, 28 rounds of sparring, 10 km jogging, and 36 acts of kindness. I’m still low on my acts of kindness by 41, which means with 11 days down and 61 to go I need to be doing about 8 acts per day if I’m going to catch up by the end. I’m not sure if I’m just the Grinch, or if I just don’t remember most of the things I do. I’d suspect it’s the latter, which is why I downloaded a tally app to my phone so I can keep a running total through the day. It’s only 9:19 as of writing this and I already have 2, so I may not be the Grinch. On the other hand those Whos are very annoying…

Until next week, Cheers!