mikegrouchy.com

New Theme…again!

So I decided to go very minimal with the theme this time. Its kind of the direction I have been moving for awhile. I am probably going to make a few more changes, but not much, I am very pleased in general. What do you think? Let me know in the comments!

Lambda functions in Python – A Quick Introduction.

While I am a bit of a programming language pragmatist and generally choose what I feel is the best language for the job, the language I use for work and most of my personal projects, big and small is Python. Python is a solid programming language with a lot of great features but one of my favorite language features that Python has is Lambda’s.

Lambdas are basically 1 line functions that are not bound to a variable name(anonymous) which are created at runtime. The idea itself for lambda functions comes from functional languages like Lisp and while its certainly not the same lambdas are still very powerful constructs in python. Lets look at some examples to make this concept a bit clearer.

A normal function in python looks like this:

def fun(x):
        print x+25
 
fun(35)

the equivalent lambda function would be:

fun = lambda x: x +25
 
fun(35)

Both examples above will return the same result. Some additional things to remember about lambda functions:
1. a lambda function can be executed without assigning to a variable.
2. lambdas do not include return statements as they are expressions which are expected to return a result.
3. lambdas can be used anywhere a function can be used.
4. lambdas can not be longer than 1 line.

Here is another basic but hopefully clearer use of for lambda functions:

class Book():
   def __init__(self,  author="", title=""):
       self.author = author
       self.title = title
 
booklist = [Book("Douglas Coupland", "Microserfs"), Book("Neil Gaiman", "American Gods"), Book("Frank Herbert", "Dune")]
 
#sort books by title using a lambda function
booklist.sort(lambda x,y: cmp(x.title, y.title) )
 
#sort books by author using a lambda function
booklist.sort(lambda x,y: cmp(x.author, y.author))

I think all of this about lambda functions is pretty self explanatory but if you have any questions leave them in the comments and I will answer them in this post or a follow up post. I also have not tested these basic examples, so if you try it out and see any issues, let me know and I will fix it up here.

New Job at SWIX!

So I have left the public service and am now working for a small startup called SWIX. I just started this week but it has been a great experience so far both the Scott Lake and Craig Fitzpatrick have been amazing since I started(plus they are fun guys to work with). Its a really interesting project and I am sure its going to be a hit when it launches. In the meantime check out the SWIX website and check back because I will sure to let everyone know when SWIX launches.

Hawaii is amazing

I am feeling more relaxed now than I have felt in a long time. Myself and Nicole are loving Hawaii. If I had the opportunity to work and live here I defiantly would. This place is great! Just a week and a bit more and I will be back in Ottawa and back to blogging as usual.

Cheers!

P.S. I tried this beer, I think its called “Blue Wave”? (its not “blue moon”) Correct me if I am wrong on the name. Anyone know if you can get this in Canada, it was delicious!

On Vacation – Two More Weeks Until New Posts

So I haven’t blogged in over a week now(and I was doing so good at being consistent!), I have been back in Newfoundland for Matthew and Krista’s Wedding. The wedding went well and was beautiful so congrats to the newly married couple!

Now for the second half of mine and Nicole’s vacation we are leaving tomorrow morning for Hawaii for another two weeks.In that time I doubt I will get an opportunity to blog so this is probably the last post you will see for these two weeks. In the meantime I am still on the job hunt and I have to fill out an coding application for a local startup company( probably on the plane tomorrow) because I have not been able to find the time to do it.

Anyway, keep coding, I hope everyone enjoys the rest of their summer!

Text Algorithms Book

I was just cruising Hacker News and saw a post pointing to a book on text algorithms. I took a quick scan through it and it looks like a good read, has plenty of algorithms for text processing, their applications and proofs for certain algorithms. So check it out Text Algorithms[PDF] .

Old Python code – Mp3 utilities

As I have been saying, I have been looking around to dig up code I have written and I actually found some mp3 utility code I had written, it is certainly not finished or even code I would probably write right now(or even particularly good) but its code I wrote a couple of years ago that someone may actually find use of.

The code contains:

  • a playlist class for reading and extending .m3u playlists
  • a song class for individual mp3s(reading id3 tags and whatnot)
  • a utility class for doing some things with the multiple playlists and whatnot.

I also wrote an interface in wxwidgets, but that isn’t working so I don’t have that. That being said, the code is a little light on error checking and exception handling. This might be fun to fool around with so I think after I get back from Hawaii I will mess around with the code for a bit, add the error handing and all of that, write some unit tests to test the code and whip up a command line interface or a gui so people can actually use it.

In the mean time, I have stuck the code up on GitHub, snag it if you like!

pymp3util on GitHub

Backup, or Things to not do like me.

So I have been looking around for some old code I have written to criticize(or post on github) and it led me to go looking around this blog for code I had written since I started writing this. The first thing I realized is that I am terrible at backup, I actually have non of the code that I had originally linked, prime example: LDAP authentication using TLS in Java
(EDIT: Thanks to Gedge this is back up. He pointed me to a project we worked on a couple of years ago. I had written a Java servlet to implement this. So I extracted the code from the servlet and hopefully now people can take it an modify that code for their own needs(as its not very complete.)

That peice of code, I cannot find anywhere and I remember spending a fair amount of time making that work.   I thought I had backed up a copy of everything on the server when I moved from Media Temple however I must not have, because I cannot find it on any of the servers I have.

I think soon I am going to have to buy some space from Amazon S3 for backups.

As a little aside to how much I such at backups I had a job interview today and some of the things we talked about was objects and whatnot. One of the questions the interviewer asked me was about passing by reference and passing by value, and we talked about Java just a little bit, and it seems I answered this question differently today then I did over 2 years ago. This is kind of funny, because I said today that you pass primitives by value and Objects by reference, oddly enough I was more right then than I was now.
(just made sure the old post was actually correct, thanks Gedge, I don’t know why I went off on a tangent there at the end :P )

Its really funny when you aren’t working with something every day how the little details slip your mind and you start to just generalize.

Anyway, lesson for today seems to be don’t backup your code or answer interview questions like me :)

Things I like: Rubular

Recently Josh wrote a blog post about regex and it brought the thought of having an on-hand regex tester around.

When I am testing regexes I usually just pop open a python console to test my regex using the built in regex lib(I actually use the python console to test a lot of things). However, when I want something a bit more visual I go to the web and use Rubular. It is a Ruby regular expression editor, but it normally serves my purposes just fine for languages besides ruby(as I don’t find myself coding much ruby). When using the regexes tested there in other languages you may need to escape certain characters or handle some other language specific funkiness, but its still pretty great to get you on the right track. So you should check it out!

pywol: Python Wake on Lan

I was looking for a reason to try GitHub out so I decided to release a module for doing Wake on Lan in Python.

It was actually the subject of my Code WTF post , so I thought I would jazz it up and put it up on GitHUB as well as commit the new version back into the project It originally came from.

It currently is unfinished but its in a state good enough to integrate into your project if you needed some code to handle Wake on Lan functionality. That being said, I will be adding some additions to it so it can be used from command line and a few other things.

anyway, check it out on GitHub, you can grab the code or branch it.

Aside: The verdict on git is that I like it alot. I also like GitHub alot. If am seriously considering upgrading my GitHub account and I have only used it for around an hour.