Jonas Forsberg

I like to do high fives, take photographs and make cool things with Ruby.

Breakfast at Mynewsdesk

Every Monday morning at 8:00 breakfast is served for the Mynewsdesk employees at our headquarter in Stockholm. It became some sort of tradition for me to take a photograph of my breakfast every morning and here’s the result from 2012’s breakfasts.

Jekyll code highlighting on Heroku

The built in code highlighter in Jekyll doesn’t work on Heroku due to some issues with Python. I came up with a work around by using the Pygmentize gem instead.

Gemfile

Add the Pygmentize gem to your gemfile:

gem 'pygmentize'

And run bundle install

_plugins/highlight.rb

Create a new file in the _plugins directory with the name highlight.rb. Paste the following code to make the built in code highlighter use the new Pygmentize gem:

require 'pygmentize'
class Jekyll::HighlightBlock < Liquid::Block
  def render_pygments(context, code)
    @options[:encoding] = 'utf-8'
    output = add_code_tags(
      Pygmentize.process(code, @lang),
      @lang
    )

    output = context["pygments_prefix"] + output if context["pygments_prefix"]
    output = output + context["pygments_suffix"] if context["pygments_suffix"]
    output
  end
end

Use

Just use the standard highlight blocks as usual:

{% highlight ruby %}
gem 'pygmentize'
{% endhighlight %}

Create Jekyll posts from the command line

I got tired on creating new files manually for each new post a write so I put together this little command line task with Thor.

It creates a new file in the _posts directory with today’s date, parses the parameters to command as the post’s title and adds that as a slug to the new file. It then writes a default yaml template to the file (as specified in the script).

Running thor jekyll:new New and shiny post will for example create the file _posts/2012-12-28-new-and-shiny-post.md, populate it with an yaml template and finally open the file in my favorite editor.

How to

Add the following to your Gemfile:

gem 'thor'
gem 'stringex'

Run bundle install and create a jekyll.thor file with the following contents:

require "stringex"
class Jekyll < Thor
  desc "new", "create a new post"
  method_option :editor, :default => "subl"
  def new(*title)
    title = title.join(" ")
    date = Time.now.strftime('%Y-%m-%d')
    filename = "_posts/#{date}-#{title.to_url}.md"

    if File.exist?(filename)
      abort("#{filename} already exists!")
    end

    puts "Creating new post: #{filename}"
    open(filename, 'w') do |post|
      post.puts "---"
      post.puts "layout: post"
      post.puts "title: \"#{title.gsub(/&/,'&amp;')}\""
      post.puts "tags:"
      post.puts " -"
      post.puts "---"
    end

    system(options[:editor], filename)
  end
end

Use the new command:

$ thor jekyll:new The title of the new post

You can even specify which editor to open the new file with:

$ thor jekyll:new The title of the new post --editor=vim

The default editor is Sublime Text 2, just change on line 4 in jekyll.thor if an other editor is preferred.

Merry Christmas

A very cozy welcome to yesterday’s turkey dinner at my sister’s house.

Kläppen

Taken at Kläppen Ski Resort, January 2006.

Dublin

Thought I might be able to shoot a bit more again and get inspiration for some nice pictures when I was in Dublin for a couple of weekends ago. But i was a little bit disappointed when i transferred the photographs to my computer. Anyway, here is a photo of Eva on a shopping street in the middle of Dublin.

A sunday walk to Långsjöbadet

Took a walk with Eva this grey Sunday. Came to a lake with a empty beach and came home with wet shoes. Looking forward to visit that beach in the summer instead.

Mynewsdesk through Loopcam

Stekarveven :D Kickoff Kickoff RC-car Nordic Ruby

Having fun with Loopcam.

Real-time Instagram feed for SilarApp

Working on a real-time Instagram photo feed for a new SilarApp dashboard. Perfect for an event or a venue who wants to encourage the use of Instagram to increase their reach in social media.

And by the way, I love my kitchen table!

Forest

The last days of my summer vacation was spent at my fathers house, out in the countryside. Among other things we took a walk in the forrest to pick some chanterelles. Did not find that much mushrooms but it did not matter because I’m not so fond of it.