Quantum Mechanic

Content from 2014-12

Keeping the Fun Alive

posted on 2014-12-16 19:53:00

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

posted on 2014-12-05 17:57:00

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!


websockets.png


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

posted on 2014-12-01 20:30:00

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.