Skip to content

Instantly share code, notes, and snippets.

View mislav's full-sized avatar

Mislav Marohnić mislav

View GitHub Profile
@mislav
mislav / index.html.erb
Created August 4, 2008 15:03
Group paginated messages by day
<h1>Last activity</h1>
<% for day, messages in @messages_by_day -%>
<h2><%= day %></h2>
<ol>
<%- for message in messages -%>
<li><%= link_to message.title, message %></li>
<%- end -%>
</ol>
<% end -%>
@mislav
mislav / gist:8920
Created September 5, 2008 04:08
a utility to execute commands entered in the console in several git repositories at once
#!/usr/bin/env ruby
# for each git repo in a subdirectory ...
dirs = Dir['**/.git'].map { |gd| File.dirname(gd) }
def prompt
print ">> "
gets
end
# ... execute a command given on STDIN
@mislav
mislav / git-scoreboard.rb
Created September 11, 2008 20:16
Generates an adds/removes-based scoreboard for a git project
## Usage:
$ ruby git-scoreboard.rb
You can also specify a range of commits:
$ ruby git-scoreboard.rb v1.2..HEAD
## Outputs:
@mislav
mislav / _note.md
Created September 17, 2008 17:49
"Branch" your database together with git

This code is obsolete

For a much more elegant way, visit my blog.

@mislav
mislav / twitter.rb
Created September 21, 2008 20:28
Ruby script to fetch user's latest update from Twitter (for Adium integration)
## gets the latest Twitter update from a user
require 'rubygems'
require 'json'
require 'yaml'
require 'open-uri'
CONFIG_FILE = ENV["HOME"] + "/.twitter"
CACHE_FILE = "/tmp/.#{ENV["LOGNAME"]}_TwitterAdium.txt"
DEFAULTS = { 'interval' => 300, 'limit' => 3 }
@mislav
mislav / gist:13809
Created September 30, 2008 13:05
Steps to setup a reasonably sane development environment on OS X
Xcode
http://developer.apple.com/technology/xcode.html
[OR]
Mac OS X install disc 2
GNU wget
http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz
Git
http://code.google.com/p/git-osx-installer/
# nginx: redirect secondary domain names to primary
server {
listen 80;
server_name mislav.caboo.se mislavmarohnic.com mislavmarohnic.name mislav.name mislav.info mislav.biz;
# ...
if ($host != "mislav.caboo.se") {
rewrite .* http://mislav.caboo.se$uri permanent;
}
@mislav
mislav / gist:17371
Created October 17, 2008 07:42
haml2erb
class ErbEngine < Haml::Engine
def push_script(text, preserve_script, in_tag = false, preserve_tag = false,
escape_html = false, nuke_inner_whitespace = false)
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
end
@mislav
mislav / gist:17821
Created October 19, 2008 12:55
implicit tags for Haml
require 'haml'
module ImplicitTags
ALLOWED_NESTING = {
'tr' => %w(table thead tbody tfoot),
'td' => 'tr',
'li' => %w(ul ol),
'col' => 'colgroup',
'dd' => 'dl',
'option' => %w(select optgroup),
@mislav
mislav / youtube_paginate.rb
Created November 23, 2008 21:23
add pagination to YouTube Model
YouTubeModel::SingletonMethods.class_eval do
include WillPaginate::Finders::Base
protected
def wp_query(options, pager, args)
# dup options and set limit
args << options.merge(:max_results => pager.per_page)
# carefully add start_index (YouTube goes nuts if it's zero)
args.last[:start_index] = pager.offset if pager.offset > 0