Skip to content

Instantly share code, notes, and snippets.

View wojtha's full-sized avatar

Vojtěch Kusý wojtha

View GitHub Profile
class CorsSupport
def initialize(app)
@app = app
end
def call(env)
if preflight?(env)
env['HTTP_ORIGIN'] = 'file://' if env['HTTP_ORIGIN'] == 'null'
env['HTTP_ORIGIN'] ||= env['HTTP_X_ORIGIN']

Using better_errors on Ubuntu with SublimeText 2

After I installed the fantastic better_errors gem, I was disappointed to notice that linking to your text editor doesn't work correctly on Ubuntu (at least, it didn't for me). Here's how I fixed it.

First, create a new desktop entry:

# /usr/share/applications/subl-urlhandler.desktop
@wojtha
wojtha / gist:4506860
Created January 11, 2013 00:02 — forked from dhh/gist:1014971
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@wojtha
wojtha / gist:4503703
Created January 10, 2013 16:52 — forked from dhh/gist:1975644
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@wojtha
wojtha / Chef Bootstrap Ruby 1.9.3-p194
Created December 9, 2012 17:35 — forked from tjsingleton/Chef Solo Bootstrap with Ruby 2.2.2
Chef Solo Bootstrap with Ruby 1.9.3-p327
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install autoconf curl git-core bzip2
apt-get -y autoremove
apt-get -y clean
cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xvzf ruby-1.9.3-p327.tar.gz
@wojtha
wojtha / README.md
Created December 5, 2012 18:39 — forked from coreyward/README.md
@wojtha
wojtha / macros_base.rb
Created November 26, 2012 17:04 — forked from feroult/macros_base.rb
RSpec Macros Recorder
module MacrosBase
def self.included(base)
base.extend(GroupMethods)
end
module GroupMethods
def mock(model_name)
class_eval <<-EOFMOCK
def mock_#{model_name}(stubs={})
(@mock_#{model_name} ||= mock_model(#{model_name.to_s.classify}).as_null_object).tap do |#{model_name}|
require 'spec_helper'
describe LineItemsController do
mock :order
mock :customer
# GET /orders/11/line_items
get :index, :order_id => 11 do
default :stub => :off
@wojtha
wojtha / controller_macros.rb
Created November 26, 2012 17:04 — forked from feroult/controller_macros.rb
Rails Controller Macros (with scaffold default)
module ControllerMacros
def self.included(base)
base.extend(GroupMethods)
end
def mock_access(user = mock_model(User))
controller.stub('require_user').and_return(true)
controller.stub('current_user').and_return(user)
end
@wojtha
wojtha / profile.ps1
Created June 19, 2011 10:18 — forked from markembling/profile.ps1
My preferred prompt for Powershell - includes git info.
# My preferred prompt for Powershell.
# Displays git branch and stats when inside a git repository.
# See http://gist.github.com/180853 for gitutils.ps1.
. (Resolve-Path ~/Documents/WindowsPowershell/gitutils.ps1)
function prompt {
$path = ""
$pathbits = ([string]$pwd).split("\", [System.StringSplitOptions]::RemoveEmptyEntries)
if($pathbits.length -eq 1) {