Skip to content

Instantly share code, notes, and snippets.

View mislav's full-sized avatar

Mislav Marohnić mislav

View GitHub Profile
@mislav
mislav / gist:91737
Created April 8, 2009 11:50
Croatian translation for Rails core
"hr":
date:
formats:
default: "%d. %m. %Y."
short: "%e %b"
long: "%B %e, %Y"
only_day: "%e"
day_names: [Nedjelja, Ponedjeljak, Utorak, Srijeda, Četvrtak, Petak, Subota]
abbr_day_names: [Ned, Pon, Uto, Sri, Čet, Pet, Sub]
@mislav
mislav / quiz.rb
Created May 15, 2009 18:18 — forked from ryanb/quiz.rb
Ryan Bates community challenge solution
# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? Only two rules:
#
# 1. You must test the order the gets/puts happen. The tests should not
# still pass if "gets" happens before "puts", etc.
#
# 2. No changing the Quiz class implementation/structure. But you can
# use whatever framework you want for the tests.
#
@mislav
mislav / update-ree-passenger.sh
Created May 26, 2009 17:08
Update Ruby Enterprise Edition and Passenger
set -e
# for a setup script see http://gist.github.com/32917
PASSENGER=2.2.3
REE="ruby-enterprise-1.8.6-20090610"
PREFIX=/opt/$REE
# git checkout of git://github.com/FooBarWidget/passenger.git
cd ~/passenger
git fetch origin
@mislav
mislav / twitter spammer.md
Created June 11, 2009 11:20 — forked from svenfuchs/What makes you a Twitter spammer?
What makes you a Twitter spammer?

Blocky (@blocky_bot) is a crowdsourcing solution for Twitter spam. Blocky does not define what a "spammer" is, so let's discuss.

What makes you a Twitter spammer?

  • You follow me just to make me follow you.

    It all comes down to this. Spammers can't spam if nobody follows them. Any relatively new account that already follows hundreds or thousands of people

@mislav
mislav / deploy.rb
Created June 12, 2009 13:04
Thor task for easier hotfixes with Capistrano & git (instructions below)
# copy to your Capistrano recipe file
namespace :deploy do
task :clear_cached_assets, :roles => :web do
dir = "#{current_release}/public"
run %(rm #{dir}/javascripts/all.js #{dir}/stylesheets/master.css)
end
end
@mislav
mislav / haml-html-skip-closing-tags.rb
Created June 27, 2009 13:57
monkeypatch for Haml to skip certain closing tags
require 'haml'
Haml::Engine.class_eval do
HTML_SKIP_CLOSING = %(body br col colgroup dd dt head hr html img input li link
meta option p param tbody td tfoot th thead tr)
def push_merged_text(text, tab_change = 0, indent = true)
if @options[:ugly] and html4? and text =~ %r{(.*)</([a-zA-Z])>(\s*)\Z}
content, tag, padding = $1, $2.downcase, $3
if HTML_SKIP_CLOSING.include?(tag)
@mislav
mislav / paginate_in_reverse.rb
Created July 15, 2009 21:03
Experiment in pagination that defaults to the last page
ActiveRecord::Base.class_eval do
def self.paginate_in_reverse(options = {})
unless options[:page]
# we only default to the last page if no explicit page has been given
total_entries = self.count(:conditions => options[:conditions])
# calculate the last page
total_pages = (total_entries / self.per_page.to_f).ceil
# update the options hash to hold this information
options = options.merge(:page => total_pages, :total_entries => total_entries)
end
@mislav
mislav / _notes.md
Created September 2, 2009 18:41
Installation script for ImageMagick on Snow Leopard

Outdated

This script is obsolete. Use Homebrew instead:

$ brew install imagemagick

@mislav
mislav / geolocation.js
Created September 18, 2009 08:51
Geolocate users with modern browsers (or with Google Gears)
var geo = navigator.geolocation || (window.google && google.gears && google.gears.factory.create('beta.geolocation'));
if (geo) geo.getCurrentPosition(displayLocation, handleError);
function displayLocation(position) {
position.coords.latitude;
position.coords.longitude;
position.coords.accuracy;
}
function handleError(error) {
@mislav
mislav / template-uri.rb
Created September 27, 2009 15:31
URI templates are, like, super-useful
# https://github.com/sporkmonger/addressable/
require 'addressable/template'
# http://dev.twitter.com/doc/get/statuses/followers
template = Addressable::Template.new 'http://{host=twitter.com}' +
'/statuses/followers{-prefix|/|id}.{format=json}' +
'?{-join|&|user_id,screen_name,cursor}'
template.expand(:id => 'mislav')
# => http://twitter.com/statuses/followers/mislav.json?