# Keeping the Fun Alive

Entered on [2014-12-16 Tue 14:53]

Over the last few years, with college done and friends scattered out over the US. It’s been hard to keep in touch and, every time I do see people, we talk about how we’d like to keep in better touch.

I was reading Blaster Nation, today (all of it!) and it made me miss my friends. So I set up a mumble server and a Google Calendar, and we’re going to see if we can play games together, even just randomly, but also in some planned state.

In my mind, it could be something like twitch, or steam, or maybe really it should be like meetup for playing with friends.

Maybe that would be a fun project?

# Cooking with websockets

Entered on [2014-12-05 Fri 12:57]

I finally got Chirp working with websockets! Well, it had worked before, but just sent down all the chirps that existed. Now it updates in real-time when someone else chirps. Though, it sends it to everyone, so don’t say anything you’d want kept secret!

Eventually, I’d want to send messages only to followers and have them show up in the nav bar as notifications, but this was mostly meant as a proof of concept, anyway. I’d much rather go write a new sql library for lisp, now, that try to finish everything. At some point, paging chirps so you can scroll to fetch more would be good.

This was sort of my minimum product for this project, but I might polish it more as I have time.

# Playing with the MOP

Entered on [2014-12-01 Mon 15:30]

I was poking around at my project, Chirp, today and finally decided to deal with a strange bug I was having. When I sent JSON down to the AngularJS controller that renders the page, dates were always coming back as the time the request was made at. This was strange, since the database records of the chirps store when they were created, and the time should have been that. The one I was testing was over a week old.

Eventually, I realized that in the slot definition

(created-at :type clsql:wall-time
:initform (clsql:get-time))


the time stamp would always be the current if the time wasn’t set on the instance when the database was read.

I’d recently started using clsql-helper to get instances of classes back from complicated SQL queries. By ‘complicated’ I mean ‘contains a basic join.’ Apparently, CLSQL doesn’t feel it needs to do that. I wish I knew why.

In any event, when I used clsql-helper, the dates were wrong, when I used clsql‘s built-in #'select, the dates were correct. So it slowly dawned on me that clsql-helper was doing something wrong. Sure enough, it wasn’t converting the string that the time stamp returned into the wall-time instance that clsql expected.

So I took the chance to play around with the MOP a bit and wrote code to convert the values to the right type, looking at their slot definitions in the class.

(defun get-slot-by-name (name class)
(find name (closer-mop:class-direct-slots (find-class class))
:key (lambda (slot)
(intern (symbol-name (closer-mop:slot-definition-name slot))
*package*))))

(defun coerce-value-to-column-type (class column value)
(let ((type (clsql-sys::specified-type (get-slot-by-name column class))))
(coerce-value-to-db-type value type)))


With that code, you just do something like

(coerce-value-to-column-type class coulmn data)


and things come out the right way.

# Literate Programming with Emacs

Entered on [2014-11-21 Fri 17:17]

Tried out literate programming a bit today using some info from Sacha Chua’s blog (mostly). It’s actually pretty difficult to figure out how to make it work and what was strangest for me was that I can’t figure out how to put a whole bunch of code blocks into the same file. It seems like you need to specify a :tangle filename for every block!

#+begin_src clojure :tangle "chapter1.clj"
...
#+end_src


What I was really hoping for was defining a new file at each section. John Zahng invited me to work on SICP in Clojure with him and I thought it was a particularly good case for trying out org-mode’s literate programming functionality. After an hour or two of trying, though, I don’t know how to make it do what I want. I can get it to dump all of the code into a file with the same name as my .org file, but that’s it. I’m not really sure how I’d want to use this to write a large project of any kind.

# Getting Lisp to run on heroku

For a while, I’d been working on cloning twitter in Lisp, since I’d been playing with Lisp web frameworks (weblocks, hunchentoot, caveman, clack) for a while. Now that I know so much more about web development, it seemed like a perfect chance. Also, with hunchensocket around, I could do push notifications with websockets, too, which Rails can’t without third party services.

I have a site up now, at Chirp, after many hours of beating my head against the wall. I thought I’d write down some major points for others who try to sort the madness out.

1. Your app will be compiled, don’t expect it to behave like you’re running it from the REPL.

I had my configuration defined using envy’s (defconfig) in the top level of a file. That meant that all of the configurations were defined at compile time, when the environment variables I was using weren’t defined. So, I had a few nil’s in my configurations.

Now, I wrap the (defconfig)‘s in a function call when the app starts up. Works like a charm.

2. You don’t own the database, you just get to use it.

CLSQL doesn’t have permission do do a number of things you might have been doing on your own database server. I had a helper function that made the database and tables if they didn’t exist. I got a lot of complaining about “template1,” which seems to be some internal postgres thing that administrators get access to. Don’t use (clsql:probe-database) or (clsql:create-database), they both try to do things they’re not allowed to.

3. Getting environment variables is a necessary evil.

Environment variables are not a first-class part of the lisp world, but they’re not too hard to get to. Heroku uses a lot of them to show you your configuration, pay special attention to PORT and DATABASE_URL.

You can get at these two ways. ASDF has a private (getenv) function, which is handy and generally available. If you’re using SBCL, you can also (require 'sb-posix) and use (sb-posix:getenv). It has a sibling, (sb-posix:setenv), should you need it.

Hopefully, we’ll make a better, more user-friendly buildpack, soon.

# Starting Over All Over Again

So, back in July I took the plunge and decided that I wasn’t cut out for the world of Academia. Grad school was taking an emotional toll that was turning into a physical toll and wasn’t paying the fulfillment dividends that it needed to. I’d spent years acquiring very specific skills in quantum computing research that people didn’t value at all. The pay was terrible. The social environment was terrible. The management was terrible. It was time to leave.

So I went ahead and enrolled in App Academy, which my friend Scott had done before. So, for the last two months, I’ve spent every waking hour programming (well, maybe a few reading and playing Dota). I know Ruby, Rails, Javascript, Backbone (learning Angular) and I already knew Common Lisp.

Most importantly, I feel like it’s a good life choice. I miss doing physics, but the universities have made it such a horrible environment to work in, it’s not worth it to me, anymore. I’m happy I get to keep problem-solving in programming and, if I’m lucky, I’ll find a job that uses my considerable skills in debugging and engineering.

The Job search starts today and I’m confident it will give me a fuller life than a career in Physics was offering.

# Injera and Company

Tonight is an exciting night. Tonight, I’m making Ethiopian food for the first time. During my time as a grad student, I barely cooked (or wrote) anything, let alone something new. So, I’m very excited to be doing something new tonight.

A few days ago, I started preparing the dough to make Injera, the national bread of Etiopia and, as far as I’m going to count, my first sourdough bread. The recipe is really simple, once you’ve found some teff flour. All you do is mix it with water and wait for it to start to go bad!

Aside from finding the teff flour, the other difficult part of this (and it gets much easier afterwards) is finding berbere spice mix. I have no idea where to do this in Kitchener, so I found this recipe that suggests how you can make your own. It doesn’t contain ground lentils, which another site suggested was part of the mix, but I’m not one to work too hard at accuracy. I’ll be using tomato sauce instead of tomato paste, as well, and grinding up my own chilis, probably with a blender (I did end up doing that, and only using half the suggested amount).

I found a helpful article on the Toronto Sun website that contains some vegetarian recipes for the various toppings that go on the Injera, so I’ll use that!

After sitting out for a day, covered with a damp towel, the teff mixture smelled a bit odd, which seemed right for sourdough. I had tried to make the batter once before, and it had grown mold, being left alone for three days. That might just be our apartment in the summer, though. I wonder if the wintertime would require a longer fermentation time.

Ideally, the bread is made like a thick crepe, but it didn’t run very quickly in my pan, so it ended up fairly thick and misshapen, but it did bubble in a way similar to the bread I’ve gotten at restaurants. Apparently, many Ethiopian places in North America cut their teff flour with wheat flour in order to make the flavor less intense, and I wonder how that affects the consistency of the dough itself. I might have to try, just to see if it makes it easier to cook.

# The Martians

Recently, I’ve been reading The Martians by Kim Stanley Robinson. It’s a book of short stories related to his {Red,Green,Blue} Mars books, which I enjoyed a lot. He managed to create a fully bleievable world with exciting new things going on and, at the same time, create a cast of characters who are believeable and complex – something that is somewhat rare for science fiction. The science is pretty fun, too, but pplied in a very human way.

Some of the stories have been misses for me, as one would expect. For example: I don’t really care enough about mountain climbing for the story about climbing Olympus Mons to have made a huge impact on me. The one that I just read, however, Arthur Sternbach brings the Curveball to Mars, was a wonderful example of the best of Kim Stanley Robinson. It is, as you might guess, about playing baseball on Mars. It features the aspects of Mars that Robinson tends to bring up – the lower gravity, the shorter distance to the horizon – but he makes it interesting every time he brings it up by showing how those things really affect the everyday lives of people on Mars. In this case, the baseball field needs to be much larger – with a fraction of the gravity on Earth, it would be pretty simple to hit a home run otherwise. But, once you’ve done that and considered the shortened horizon, it means the field stretches out almost to the horizon around you.

The story also went into the culture of Baseball on Mars, suggesting that the Martians had only learned it from videos and so, didn’t do many things that the protagonist, a visiting American, took for granted. Things like heckling or calling to each other on the field about what they were doing. They also had never seen a curveball.

In any event, it was a good story and I’d recommend it.

# KwartzLab

Tonight, Sarah and I went with some friends to the local makerspace, KwartzLab, in Kitchener. It was a ‘bring your own project’ night, though only a few people were there while we were.

There was a pretty impressive array of machinery represented, although, from what I’ve read of makerspaces, it was probably pretty run of the mill. 3D printer, laser cutter, …. the usual.

One thing that we saw that I’ve never heard of before was a knitting machine. It was a long line of hooks that the knitted piece hang on. You slide a piece back and forth across and it somehow automatically knits! Apparently, they’re also programmable, which is nice. Unfortunately, though, it seems most are programmed with punch cards and the woman operating it claimed that they predated modern computers!

Hopefully, we’ll manage to make it back for their Tuesday night open house to work on something. It was nice being around a bunch of people working on projects.

# Mining on Linux

This weekend, I decided to look into crypto currencies again.  Three years ago, I poked around bitcoin and managed to find a site that would give you 1/1000th of a bitcoin for free, just to get people to use the currency.  Now, there are lots of new currencies online and who knows which will become as popular as Bitcoin, although I expect some of them will make it.  I, personally, like the vibe of Dogecoin, which has a level of seriousness I find appropriate for currencies anyway.

I set about trying to mine some on Fedora 20.  I am the sort of Linux user who tolerates very little non-free code on the machine and graphics-related topics especially give me pause.  It seemed worthwhile to me to figure out how to get a miner running on the open-source drivers, then.  I was happy to find that Tom Stellard, a mesa developer, posted on his blog about getting mining working with the open radeon drivers.

The trick, it turns out, was getting a new enough version of mesa, clang, and LLVM to get things working.  I ended up having to install fedora-release-rawhide and then running

sudo yum install mesa mesa-libOpenCL clang llvm --enablerepo=rawhide

to get the appropriate bits.

Now I’m chugging away at ~160Mhashes/s, which seems to be pretty slow by modern standards, but within a factor of 2 of what other people report for my card.  Not bad for new code.

If you find this useful, feel free to throw some of your shiny, new crypto-currency at me!  Maybe then I’ll be able to get hardware I can actually play this strange lottery with!

BTC: 1QKPMpRNEbpwhzzP33HpiNSEfEgDdTYvd3

DOGE: D5A9ngH7mb3roJgpAGUjUPdAcbV3svvkvH