I had an issue where I was not sure the ActiveRecord::SessionStore was actually working (in hindsight: it worked). But to make sure, I needed to know what was stored in the session or retrieved.

Now all logging for the session-store is silenced, using Base.silence.

Now I was very interested in that logging, and did not find another to unsilence the logging but to add an initializer with the following code. So in file config/initializers/unsilence_logging.rb write:

class ActiveRecord::Base
  def self.silence
    yield self
  end
end

This will unsilence the SessionStore logging. Your logging will look like this:

^[[1m^[[36mAREL (0.0ms)^[[0m  ^[[1mUPDATE "sessions" SET "data" = 'BAh7DEkiFnF1aWN<<snipped to protect the inncocent>>iEi9mcC9kYXNoYm9hcmQ= ', "updated_at" = '2012-05-04 11:17:24.704491' WHERE "sessions"."id" = 33635^[[0m

This at least allows us to verify that the sessions are stored and retrieved correctly. But how can we see what is stored inside the session?
To be able to read or inspect what is actually stored in the session, you can use the following line:

session_data = 'BAh7DEkiFnF1aWN<<snipped to protect the inncocent>>iEi9mcC9kYXNoYm9hcmQ= '
Marshal.load(ActiveSupport::Base64.decode64(session_data))

And this will present your session data in a readable format.

This way I learned that a time-drift between our two servers caused a very obscure bug. I hope it can help you too.

Assume you have, like I did, a ruby gem that contains some javascript you want to test standalone.

First you need to install the jasmine-gem. You have two options:

  • either you use your gemspec to drive your bundler gemfile, so just add it to your developement dependencies
  • I am still using jeweler, so I use a normal Gemfile, which jeweler parses to populate my gemspec with. Personally I find this much easier, and my workflow is much closer to any ruby development for me, this way

If you have a rails-project, starting with jasmine is easy, and takes three easy steps:

# first add jasmine to Gemfile, and then
bundle install
rails g jasmine:install
rake jasmine 

Inside your gem or simple ruby-project it is equally simple, just type

jasmine init
rake jasmine

Now you can need to edit the jasmine.yml to make sure it is running your tests and your code, instead of the example code.
In my case I had to change only one line:

src_files:
  - app/assets/javascripts/**/*.js

Happy testing :)

Some interesting links to help you with jasmine:

I really like generative art, so I have been playing with processing for a while. Processing is an open source language (on top of java), that gives the possibilty to create images, animations, with added interactivity.

First I created a simulation of raindrops, and because I wanted it to be easily configurable I used processing.js: processing implemented on top of javascript. So that becomes native processing in the browser. Allowing to interact with HTML and javascript objects easily. Publishing the sketch is just: give people the link.

Next-up I wanted to create a music visualisation. Interact with the music. I had the perfect piece of music in my head: “Endless Season” by Ken Ishii.

Now processing.js does not interact with music. There is HTML5 audio, but it still is very experimental, and I did not find any API for processing music, reacting to and analysing music played. Processing (the java version) has an excellent library for this: Minim (actually more than one, but I ended up using that one).

When the sketch was finished, I wanted to share it, convert it to a video. What were the options.

Use Processing itself

There are two ways to convert a processing sketch to a movie, from within processing itself:

  • use MovieMaker: this requires quicktime and unfortunately does not work on Ubuntu
  • when each frame is drawn, do saveFrame and then convert all frames to a movie afterwards. While in theory this should work, saving the images slowed down my sketch, and ultimately screwed up the sync with the audio. My frame-rate was not consistent enough. For straightforward stuff this does not matter, but I needed it to sync with the audio.
  • There is a third option: GSVideo, but frankly, that seemed to damn hard for me, so I skipped that.
  • So I needed an alternative approach. If it runs correctly on my screen, couldn’t I just record it on my screen?

    Use some sort of screenrecording/screencast software

    To record my desktop, on ubuntu, including the sound from processing proved to have some issues:

    • processing (i.e. java/JDK 6) does not use ALSA to create the sound, but address the hardware devices directly
    • I do not want to record my entire desktop, but a specific part, of a specific size
    • I want to share my video on vimeo, so it has to follow certain guidelines

    The first proved to be the hardest.

    Recording the system audio out together with the video

    On ubuntu, I found one approach to work very well for me:

    • use gtk-recordmydesktop
    • use PulseAudio mixer, it will allow to take the sound output as input to record
    • and record away! :)
    • But, unfortunately, since java does not ALSA but uses the hardware devices directly, PulseAudio was unable to capture the sounds. However, by accident I found out that if you export your processing sketch to an applet, and run the applet in the browser, it does use ALSA and can be recorded perfectly. Awesome.

      Part one solved.

      Recording a specific part of the screen

      gtk-recordmydesktop allows to specify an area of the screen to record, but somewhat akwardly. Now, for exporting to vimeo, it had to follow certain fixed, optimal sizes. E.g. 640×480 for 4:3 SD video, 640×360 for 16:9 SD video, and 1280×720 or 1920×1080 for HD. And that is hard to do if you are trying to position the recording box manually.

      But, as I found out here, when using recordmydesktop from the commandline, you can send those options along:

      recordmydesktop -x=0 -y=0 --width=320 --height=240
      

      So, if you open the Advanced->Misc, and look for the Extra options field, there you can fill in the same options, and when you press record gtk-recordmydesktop will show the bounding box that is recorded.

      Preparing your video for uploading to vimeo

      To upload your video to vimeo, you have make sure two things are correct:

      • the screensize, which we discussed before
      • the video format

      gtk-recordmydesktop creates an Ogg Theora file, and unfortunately vimeo does not accept that format yet. Converting that to MP4 was hell, until I found Arista Transcoder.

      Using Arista to create an MP4 is easy (but you have to know it):

      • open Arista Transcode
      • create a new conversion
      • select your file, by default called out.ogv, as the source
      • select Sony Playstation - PSP as the device
      • press create!

      This will create a file called out.mp4 which is just perfect for vimeo, including the sound.

      The result

I was investigating ways to generate pdf’s in Ruby on Rails, but I had one enormous constraint: it had to deploy on heroku.

There are two very different ways to generate pdf’s in ruby:

  • use prawn: it is pure ruby, very powerful. It has it’s own DSL, that unleaches all the power of building a PDF, but at the same time: it seems to be very hard and tedious.
  • use some sort of HTML to PDF conversion. In ruby there exists two gems: wicked_pdf and PDFKit, both use wkhtmltopdf under the covers. I dreamed of having a view magically converted to PDF.

I went for the second option. Furthermore, I choose wicked_pdf over PDFKit, because I felt the rails integration was better. It allowed my to just render a view which would automatically be downloaded as a PDF.

Setting up wicked_pdf in Rails to run on heroku

Luckily, getting it running on heroku proved to be incredibly easy:just including the correct gem with the binaries that work on heroku.

In my Gemfile I added the following:

gem "wicked_pdf"
gem "wkhtmltopdf-heroku", :git => 'git://github.com/camdez/wkhtmltopdf-heroku.git'

And, then, inside a view you want to render as pdf, write something like

respond_to do |format|
       format.js
       format.pdf {
         render :pdf => "show", :header => { :font_size => '8', :right => '[page] of [toPage]' }, :footer => {:font_size => '8', :right => 'Generated by jottinx.com' }
      }
     end
   end

Then, you will still have to create the view, show.pdf.erb. Just make sure your view renders HTML and it will be converted to PDF correctly. That is just awesome.

Hope this helps.

The Problem

For jottinx I wrote a small piece of code that allowed to sort items using drag and drop. Of course, after writing it and making sure it works (manually), I want to make sure it keeps working. So I add a test, using cucumber.

My scenario actually looks pretty straightforward:

  @javascript
  Scenario: Dragging a book
    Given I authenticate as a "default user"
    And I add a new book with title "a-new-book"
    And I add a new book with title "another-book"
    And I add a new book with title "one-last-book"
    And I drag book "one-last-book" to the top
    Then book "one-last-book" is at the top of the list

The difficult bit was: how do I implement the dragging?.

Actually it seemed straightforward, because capybara has a method called drag_to. So I implemented the step like this:

When /^I drag book "([^"]*)" to the top$/ do |book_title|
  drop_place = page.find(:css, 'ul.sortable-books li:first')
  page.find(:xpath, "//a[@href='##{book_title.parameterize}']").drag_to(drop_place)
end

But, unfortunately, this did not work. I googled around a bit and found the following two similar questions:

The short conclusion: it does not work, and it is a combination of how jquery implemented the sortable element, and the fact that the selenium driver does not support it yet. So, refraining to using the selenium driver directly does not help either.

After some more googling, I found a similar question on stackoverflow, and there I found the solution.

The solution

Enter jquery.simulate.drag-sortable.js. It is a script that will allow you to simulate dragging in a sortable object by issuing a simple javascript command:

// drag item down one position in the list
$('#itemToDrag').simulateDragSortable({ move: 1 });

If move parameter is negative, it will move up. And down if positive. If you include the js inside your project, you can easily test that out inside your Chrome console. It just works. Awesome piece of work.

To use that in a step-definition, just write:

When /^I drag book "([^"]*)" to the top$/ do |book_title|
  page.execute_script %Q{
    $('.sortable-books li:last').simulateDragSortable({move: -4});
  }
end

Hope this helps :)

This release contains

  • paginate really large notebooks (unobtrusive, when reaching the end of the page, it will automatically fetch missing notes if available)
  • a user can new edit her own profile (email/password) and delete her account if she so desires
  • added more copy to the about/faq page

What was in the previous (undocumented) releases?

  • 0.0.24: entered links are clickable after saving (they were clickable in the preview only)
  • 0.0.23: redesigned landing page + fixed an error in the forgot password handling

This release contains:

  • tags are clickable and we also show a clickable tag-cloud
  • deleting of notebooks: after deleting now jumps to the first book
  • create a new book in a modal window
  • there were some problems with tags undefined popping up, I hope to have fixed that

If you have suggestions or encounter any problems, please let me know.

Released some small improvements:

  • somehow it was impossible to save tags: that is now fixed
  • links are now opened in a new tab/window

This new version contains a new layout setup. I see some room still for further improvement, but for now we get

  • better use of complete screen estate
  • faster loading of first page (as we start loading book after rendering the rest first)
  • books only get loaded when they are needed

Hope you like it.

What is next:

  • showing a clickable tag-cloud
  • making sure the sidebar and header is always visible

As always, I am happy to hear your suggestions and ideas.

Released 0.0.18 includes:

  • improved Markdown editor with immediate preview
  • some smaller improvements: you can now click on links immediately, flash-messages disappear, notes show the creation-date

Nextup I will most likely tackle the general layout. Replace the tabs by something smaller. Make more use of the screen in general.