Steve Jackson

Ruby, Rails, Vim, and various other musings
10 Oct 2011

Srahhh.com Portfolio Site

I recently developed a portfolio site for my friend Sarah: check it out. She designed, I built. It’s a custom theme built for WordPress, so it was primarily a PHP, jQuery, and CSS endeavor.

11 Sep 2011

HTML5 Canvas Mazery

I’ve been wanting a reason to fool around with CoffeeScript and the HTML5 Canvas element for quite awhile, so I finally did so yesterday and created mazery. It’s a maze generation visualizer. It’s purposely built with an inefficient algorithm (Hunt and Kill) simply so that I can show the cool traversal process visually.

I’m majorly impressed by CoffeeScript. You can check out my code on github. Feel free to provide feedback on anything I’m not doing the CoffeeScript way.

I’ll hopefully get around to adding some stuff to mazery as time goes by, such as a solver. We’ll see!

31 Aug 2011

Facebook photo downloading script

I wrote a quick script using the Facebook Graph API to download photos tagged of myself. It’s pretty easily modifiable to grab any other objects from your graph, too.

Go to the Graph API explorer and generate an access token with the permissions you need. In this instance: user_photos, user_photo_video_tags. Just use that token when you run this ruby script and you’re golden:

require 'json'
require 'net/http'

def fetch(output_dir, username, photo_limit, access_token)
  url = "https://graph.facebook.com/#{username}/photos?limit=#{photo_limit}&access_token=#{access_token}"
  uri = URI.parse(URI.encode(url))
  
  http_session = Net::HTTP.new(uri.host, uri.port)
  http_session.use_ssl = true
  
  response = http_session.request(Net::HTTP::Get.new(uri.request_uri))

  jsonresult = JSON.parse(response.body)
  result_data = jsonresult["data"]

  if result_data.nil?
    puts "No data to parse. Maybe you've got an invalid access token or uri?"
    return
  end

  for entry in result_data
    system "wget --directory-prefix='#{output_dir}' #{entry['source']}"
  end
end

fetch('my-photos', 'YOUR_FACEBOOK_IDENTIFIER', 2000, 'YOUR_ACCESS_TOKEN')
30 Aug 2011

RSpec-Fuuu

So you’re running your suite of RSpec unit tests, and have some breakage. You get a giant stream of F’s. I wrote a gem to correct that to what you’re really thinking: FUUUUUUUUUUU

I know what you’re thinking, “Wow, Steve, that’s the coolest and most useful gem ever.” I know. Go ahead and grab it:

gem install rspec-fuuu

And use it once or set it to your default RSpec formatter:

rspec spec -f RspecFuuu

echo '-f RspecFuuu' > ~/.rspec

Check out the code over here on github.

22 Aug 2011

A few quick Vim tips

Here’s a few quick vim-isms to throw in your vim settings, if you’re so inclined.

Reindent File

I grew annoyed at hitting gg=G (indent from beginning to end of file) and having my cursor end up at the end of the file. This method saves your cursor position, executes a gg=G, and returns your cursor to its previous position. Easily modifiable for any other similar action.

" re-indent file function
nnoremap <silent> <F4> :call <SID>ReindentFile()<CR>
function! <SID>ReindentFile()
  " Save cursor position
  let l = line(".")
  let c = col(".")

  " Reindent File
  let cmd = "normal!" . "gg=G"
  execute cmd

  " Move cursor back to saved position
  call cursor(l, c)
endfunction

Get Some Ipsum

Find yourself repeatedly going to a lorem ipsum generator while prototyping? Leverage the simple power of abbreviations by shortcutting the first couple paragraphs of lipsum. Why not use Hipster Ipsum?

iab lipsum1 filler text of choice here.

Fix SCSS formatting

If you find yourself editing SCSS, which you increasingly might with it being bundled by default in the upcoming Rails 3.1, Vim doesn’t properly indent the nested brackets. I found a fix released by Tim Pope (clone this file into ~/.vim/indent/). Voila!