Skip to content

Instantly share code, notes, and snippets.

@szimek
szimek / create_locations.rb
Created June 20, 2010 18:58
How to setup PostGIS with Rails
class CreateLocations < ActiveRecord::Migration
def self.up
create_table :locations do |t|
t.datetime :time
t.point :geom, :null => false, :srid => 4326, :with_z => true
t.float :speed
end
end
def self.down
class ApplicationController < ActionController::Base
prepend_before_filter :blitzkrieg
def blitzkrieg
redirect_to "/berlin" and return if request.path == root_path
end
end
@szimek
szimek / paperclip_url_tempfile.rb
Created July 9, 2010 09:37
Paperclip extension for fetching images from URL
# Paperclip compliant class for uploading files through URL
# Simplified version of http://github.com/chris/paperclip_url_support
require "open-uri"
module Paperclip
class UrlTempfile < Tempfile
attr :content_type
def initialize(url)
@szimek
szimek / post-checkout
Created August 5, 2010 15:40
Git hook to switch Ruby versions when changing branches
#!/bin/bash
if [ -f .rvmrc ]; then
source .rvmrc
fi
From d75eb570e16f765b5c6acee8f1fc1c8013eeba4f Mon Sep 17 00:00:00 2001
From: Szymon Nowak <szimek@gmail.com>
Date: Mon, 11 Oct 2010 19:37:03 +0200
Subject: [PATCH] Return a valid empty JSON on successful PUT and DELETE requests.
---
.../lib/action_controller/metal/responder.rb | 20 ++++++++++++++++++++
actionpack/test/controller/mime_responds_test.rb | 19 +++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
@szimek
szimek / dont_handle_asynchronously.rb
Created October 13, 2010 13:05
Disable delayed_job in tests
class ActiveRecord::Base
# Allow to bypass Delayed Job asynchronous handling
def self.dont_handle_asynchronously(*methods)
method_aliases = {}
methods.each do |method|
# TODO move this part into Delayed::MessageSending::ClassMethods#handle_asynchronously
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}"
method_aliases[method] = {:with => with_method, :without => without_method}
@szimek
szimek / config.ru
Created December 19, 2010 17:22
Script for serving static pages in a directory
# Using Ruby with "rack" gem - run using "rackup"
use Rack::Static, :urls => [""]; run nil
@szimek
szimek / executer.js
Created February 20, 2011 20:21
capybara-zombie server segmentation fault
var net = require('net'),
util = require('util'),
zombie = require('zombie'),
browser = new zombie.Browser,
buffer = "";
net.createServer(function (socket) {
socket.setEncoding('utf8');
socket.on('data', function (data) {
@szimek
szimek / init.el
Created March 5, 2011 21:01 — forked from mig/init.el
;; emacs configuration
(push "/usr/local/bin" exec-path)
(add-to-list 'load-path "~/.emacs.d")
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq-default tab-width 2)
(setq-default indent-tabs-mode nil)
(setq inhibit-startup-message t)
@szimek
szimek / delayed_job_mailer.rb
Created March 23, 2011 09:01
Initial version - the idea is to make Mail::QueuedDelivery a proxy that takes original delivery_method as a parameter
# lib/mail/queued_delivery.rb
require 'mail'
module Delayed
class PerformableMail
attr_reader :mail
def initialize(mail)
@mail = mail
end