Skip to content

Instantly share code, notes, and snippets.

View jumski's full-sized avatar
🐴
For the lack of a nail, throw new HorseshoeNailNotFoundException("no nails!");

Wojtek Majewski jumski

🐴
For the lack of a nail, throw new HorseshoeNailNotFoundException("no nails!");
  • Independent hacker
View GitHub Profile
@jumski
jumski / backbone_sync_hack.coffee
Created August 5, 2011 17:10
BackboneJS sync hack to namespace params when saving/updating model
###
Usage:
* add model.name property that will be used as a namespace in the json request
* put this code before your Backbone app code
* use toJSON() as usual (so there is no namespacing in your templates)
* your model's data will be sent under model.name key when calling save()
###
# save reference to Backbone.sync
Backbone.oldSync = Backbone.sync
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="urn:AllegroWebApi" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="urn:AllegroWebApi"><env:Body><doCheckNewAuctionExt><fields><fid>1</fid><fvalue-string>Pan Tadeusz</fvalue-string><fvalue-int>0</fvalue-int><fvalue-float>0</fvalue-float><fvalue-image> </fvalue-image><fvalue-datetime>0</fvalue-datetime><fvalue-boolean>false</fvalue-boolean></fields><fields><fid>2</fid><fvalue-string>1829</fvalue-string><fvalue-int>0</fvalue-int><fvalue-float>0</fvalue-float><fvalue-image> </fvalue-image><fvalue-datetime>0</fvalue-datetime><fvalue-boolean>false</fvalue-boolean></fields><fields><fid>3</fid><fvalue-string></fvalue-string><fvalue-int>0</fvalue-int><fvalue-float>0</fvalue-float><fvalue-image> </fvalue-image><fvalue-datetime>2011-11-07T21:53:05+01:00</fvalue-datetime><fvalue-boolean>false</fvalue-boolean></fields><fields><fid>4</fid><fvalu
@jumski
jumski / rbenv-install-system-wide.sh
Created December 23, 2011 17:29
rbenv install and system wide install on Ubuntu 10.04 LTS.
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@jumski
jumski / etc_init.d_unicorn_example.co.uk
Created December 23, 2011 17:33
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
@jumski
jumski / 0-readme.md
Created February 4, 2012 15:23 — forked from burke/0-readme.md
ruby-1.9.3-p0 cumulative performance patch.

Patched ruby 1.9.3-p0 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@jumski
jumski / deploy.rb
Created February 28, 2012 15:51 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
def display_booking_prices(booking)
prices.inject('') do |content, row|
content << content_tag :dl, row.inject('') do |row_content, cell|
row_content << case row.index(cell)
when 2
content_tag(:dd, display_money(cell, booking.place.currency, :no_html => true), :class => "price")
when 1
content_tag(:dd, cell, :class => "guests")
when 0
content_tag(:dd, cell, :class => "nights")
@jumski
jumski / Gemfile
Created March 23, 2012 20:40
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@jumski
jumski / gist:2299910
Created April 4, 2012 09:24 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@jumski
jumski / enumerize_matcher.rb
Created April 6, 2012 10:58
Rspec matcher for enumerize gem
# RSpec matcher to spec enumerize settings
# usage:
#
# it { should enumerize(:sex).in(:male, :female).with_default(:male) }
RSpec::Matchers.define :enumerize do |attribute|
match do |model|
@attribute = attribute
@klass = model.class