Skip to content

Instantly share code, notes, and snippets.

View markoa's full-sized avatar

Marko Anastasov markoa

View GitHub Profile
@markoa
markoa / rails3-installation-fail-on-rdoc
Created September 5, 2010 11:35
Rails 3 installation fails on Linux with "File not found: lib" before making rdocs
marko@harman:~$ sudo gem install rails
[sudo] password for marko:
Successfully installed activesupport-3.0.0
Successfully installed i18n-0.4.1
Successfully installed activemodel-3.0.0
Successfully installed rack-1.2.1
Successfully installed rack-mount-0.6.13
Successfully installed tzinfo-0.3.23
Successfully installed erubis-2.6.6
Successfully installed actionpack-3.0.0
@markoa
markoa / configuration-middleware.rb
Created October 19, 2010 16:45
Monkey patch for OmniAuth::Strategy to make it Rack::Config configurable. Here we also include sample middleware that sets different configuration within an app serving many domains.
module App
module Middleware
class OmniAuthConfigurator
def initialize(app)
@app = app
end
def call(env)
current_domain = env["SERVER_NAME"] || env["HTTP_X_FORWARDED_FOR"]
website = Website.find_by_domain(current_domain)
@markoa
markoa / login_backdoor.feature
Created December 9, 2010 15:32
Mislav's method to log in without messing with the form in Cucumber
# Eg Given I am logged in as @mislav
#
Given /^I am logged in as @(\w+)$/ do |username|
visit "/login/#{username}"
@current_user = User.find_by_login(username)
end
@markoa
markoa / kata-two-binary-seach-spec.rb
Created January 19, 2011 08:37
Specification for a binary search method.
# Source: http://codekata.pragprog.com/2007/01/kata_two_karate.html
#
# Method takes an integer search target and a sorted array of integers.
# It should return the integer index of the target in the array, or -1
# if the target is not in the array.
#
# Test data:
def test_chop
assert_equal(-1, chop(3, []))
@markoa
markoa / bates.css
Created February 2, 2011 09:53
CSS file as seen on Railscasts
body {
background-color: #4B7399;
font-family: Verdana, Helvetica, Arial;
font-size: 14px;
}
a img {
border: none;
}
@markoa
markoa / npm-install-error-log.txt
Created February 9, 2011 10:29
Installing from git after install node 0.4.0-pre
$ sudo make install
node cli.js install npm
npm info it worked if it ends with ok
npm info using npm@0.3.0
npm info using node@v0.4.0-pre
npm info fetch http://registry.npmjs.org/npm/-/npm-0.2.17.tgz
npm info calculating sha1 /tmp/npm-1297247221156/1297247221156-0.8592270885128528/tmp.tgz
npm info shasum da3ef5c631a377a6df266a933c2e92d361bcd3a6
npm info calculating sha1 /usr/local/lib/node/.npm/.cache/npm/0.2.17/package.tgz
npm info shasum 7aa61f06f35622cfc329b13dccaf3cae498c344c
# Sad shvatam šta si mislio sa lokalnom promenljivom,
# ja sam doduše u vidu imao samo objekat. Konceptualno,
# moja ideja bi mogla da si implementira kao:
class Transformable
def transform(sym)
self = self.send(sym) # => SyntaxError: compile error - Can't change the value of self
end
end
@markoa
markoa / capistrano-with-bundler-deploy.rb
Created March 15, 2011 11:18
The snippet for config/deploy.rb to use Bundler.
# use this in a after "deploy:update_code" block
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
@markoa
markoa / iptables.up.rules
Created May 13, 2011 10:28
Slicehost recommended iptables setup
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
@markoa
markoa / omniauth_callbacks_controller.rb
Created August 17, 2011 14:45
Saving LinkedIn OAuth data in a callback action (Rails controller, Devise, Omniauth).
# in your routes.rb:
# devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
#
# and view:
# link_to("Connect to LinkedIn", user_omniauth_authorize_path(:linked_in))
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
omniauth_hash = env["omniauth.auth"]