Skip to content

Instantly share code, notes, and snippets.

# Nginx+Unicorn best-practices congifuration guide. Now with SPDY!
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
@kapkaev
kapkaev / faraday_digest_auth.rb
Created March 5, 2013 08:13
Faraday::Request::DigestAuth
require 'faraday'
require 'net/http/digest_auth'
module Faraday
# Public: A Faraday middleware to use digest authentication. Since order of
# middlewares do care, it should be the first one of the Request middlewares
# in order to work properly (due to how digest authentication works).
#
# If some requests using the connection don't need to use digest auth you
@kapkaev
kapkaev / gzip.rb
Last active September 13, 2018 17:10
Faraday::Response::Gzip middleware
require 'faraday'
require 'zlib'
module Faraday
class Response::Gzip < Response::Middleware
def on_complete(env)
encoding = env[:response_headers]['content-encoding'].to_s.downcase
case encoding
when 'gzip'
env[:body] = Zlib::GzipReader.new(StringIO.new(env[:body]), encoding: 'ASCII-8BIT').read
@kapkaev
kapkaev / qwerty.rb
Last active December 14, 2015 07:08
simple qwerty
#encoding: utf-8
module Utils
module Qwerty
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
EN = %W(q w e r t y u i o p [ ] a s d f g h j k l ; ' \\ z x c v b n m , . ')
RU = %w(й ц у к е н г ш щ з х ъ ф ы в а п р о л д ж э ё я ч с м и т ь б ю)
@kapkaev
kapkaev / quick_find.rb
Created February 17, 2013 16:00
QuickFind. The Algoritms introduced in Coursera courses Algorithms, Part I
class QuickFind
def initialize(n)
@ids = []
0.upto(n-1) {|i| @ids[i] = i}
end
def connected?(id1,id2)
@ids[id1] == @ids[id2]
end
@kapkaev
kapkaev / oj_vs_activemodel_serializer.rb
Created February 13, 2013 08:38
oj vs activemodel_serializer
require 'benchmark'
require 'oj'
class WrapperSerializer < ActiveModel::Serializer
attributes :seq
end
class Wrapper
include ActiveModel::SerializerSupport
@kapkaev
kapkaev / Gemfile
Created February 3, 2013 08:19 — forked from pirj/Gemfile
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib', require: 'sinatra/streaming'
group :development do
gem 'thin'
gem 'pry-rails'
end
@kapkaev
kapkaev / gist:4619127
Created January 24, 2013 09:30
MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. Resque
$ redis-cli
> config set stop-writes-on-bgsave-error no
# Search by polygons
t = Tire.search('places', load:false) do
query { all }
sw = [55.524508, 36.414773] #lat, lng
ne = [55.974333, 38.886697]
nw = [55.974333, 36.414773]
se = [55.524508, 38.886697]
filter :geo_polygon, lat_lng: {points: [sw, ne, nw, se, sw]}
end.results
@kapkaev
kapkaev / using-ruby-1.9.3-p327.md
Created December 3, 2012 21:49 — forked from juno/using-ruby-1.9.3-p327.md
Using ruby-1.9.3-p327 with ruby-env and ruby-build

Using ruby-1.9.3-p327 with ruby-env and ruby-build

Prerequisite

  • Mac OS X Mountain Lion (10.8.2)
  • Homebrew
  • readline
  • rbenv

Install or update ruby-build