Skip to content

Instantly share code, notes, and snippets.

View zudochkin's full-sized avatar
😻

Dmitry Zudochkin zudochkin

😻
View GitHub Profile
@zudochkin
zudochkin / etc_init.d_unicorn_example.co.uk
Created August 18, 2012 20:40 — forked from rubysolo/etc_init.d_unicorn_example.co.uk
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
@zudochkin
zudochkin / default
Created August 24, 2012 15:43 — forked from mauricio/default
# as we’re going to use Unicorn as the application server
# we’re not going to use common sockets
# but Unix sockets for faster communication
upstream shop {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/shop.socket fail_timeout=0;
@zudochkin
zudochkin / gist:3706225
Created September 12, 2012 12:13 — forked from wheresalice/gist:949611
Sinatra Dropbox Oauth
require 'rubygems'
require 'erb'
require 'sinatra'
require 'dropbox'
configure do
enable :sessions
end
def authed?
@zudochkin
zudochkin / gist:3775889
Created September 24, 2012 13:13 — forked from olistik/gist:2627011
Ubuntu 12.04 setup (rbenv, janus, postgres)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
@zudochkin
zudochkin / Ubuntu rbenv
Created September 27, 2012 16:01 — forked from HatemMahmoud/Ubuntu rbenv
Installing Ruby 1.9.2 with OpenSSL on Ubuntu 11.04 using ruby-build and rbenv
# for more info: https://gist.github.com/1120938
@zudochkin
zudochkin / em-http-vcr.rb
Created September 28, 2012 15:27 — forked from igrigorik/em-http-vcr.rb
Mocking with WebMock and VCR
require 'rubygems'
require 'test/unit'
require 'em-http'
require 'vcr'
VCR.config do |c|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.http_stubbing_library = :webmock
end
# encoding: utf-8
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :application, "hirefireapp"
set :repository, "git@codeplane.com:meskyanichi/myapp.git"
set :branch, "develop"
set :rvm_ruby_string, "1.9.2"
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here: http://nokogiri.org/Nokogiri/XML/Reader.html
#
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
#
# A small example:
#
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans