Skip to content

Instantly share code, notes, and snippets.

View shaliko's full-sized avatar

Shalva Usubov shaliko

View GitHub Profile
def defer(&block)
def block.each ; yield call ; end
block
end
app =
lambda do |env|
status = 200
headers = { 'Last-Modified' => exec_sql('SELECT MAX(updated_at) FROM foos').httpdate }
@wynst
wynst / README.MD
Created February 25, 2010 11:19
A Thor Task to unwatch *all* Github watched repositories (excluding owned) and optionally export to delicious.

A Thor Task to unwatch all Github watched repositories (excluding owned) and optionally export to delicious.

Sorry Github, for I have sinned. I use the Watch feature as a bookmarker.

Install required gems:

gem install thor rest-client

Use it as such:

class Video < ActiveRecord::Base
before_validation :set_attrs_via_embedly, :on => :create
def set_attrs_via_embedly
# example url: http://www.youtube.com/watch?v=oHg5SJYRHA0
attrs = Embedly.get_attrs url
errors[:base] << "is not a video" unless attrs['type'] == 'video'
self.attributes = attrs
end
require "time"
require "date"
class Date
def to_time
Time.local(year, month, day)
end
end
class Time
@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@josevalim
josevalim / client.js
Created January 4, 2011 08:29
Improve file uploads with Zombie
// Improvements to file uploads with Zombie.
//
// Just start the Sinatra server below and run this file with node.
// Depending on the server used with Sinatra, it will fail upfront or forward
// a bad request to the app. The source code in zombie is in the link below
// (you will need Zombie from git, you can check it out and use `npm link`):
//
// https://github.com/assaf/zombie/blob/master/src/zombie/history.coffee#L93
//
var zombie = require("zombie");
@banker
banker / basics.rb
Created January 26, 2011 19:42
Files used in a presentation on MongoDB and Ruby
require 'rubygems'
require 'mongo'
@con = Mongo::Connection.new
# Instance of Mongo::DB
@db = @con['webinar']
# Instance of Mongo::Collection
@col = @db['users']
@ryanb
ryanb / favorite_gems.md
Created March 4, 2011 17:31
A list of my favorite gems for various tasks.
@mikhailov
mikhailov / capistrano_log_recipes.rb
Created March 25, 2011 06:24
Capistrano extra recipes
namespace :log do
desc "A pinch of tail"
task :tailf, :roles => :app do
run "tail -n 10000 -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
puts "#{data}"
break if stream == :err
end
end
@sstephenson
sstephenson / gist:921992
Created April 15, 2011 16:33
REE vs 1.9.2 for a small Rails 3 app
ree-1.8.7-2010.02
-----------------
units: Finished in 0.930402 seconds.
functionals: Finished in 12.241386 seconds.
integration: Finished in 1.648589 seconds.
rake 20.19s user 4.96s system 98% cpu 25.588 total
ruby-1.9.2p180
--------------
units: Finished in 1.504977 seconds.