Skip to content

Instantly share code, notes, and snippets.

Leonid Shevtsov leonid-shevtsov

Block or report user

Report or block leonid-shevtsov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
# Connect Opscode repository
echo "deb `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list
mkdir -p /etc/apt/trusted.gpg.d
gpg --keyserver --recv-keys 83EF826A
gpg --export | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null
# Install chef
apt-get update -qq
echo "chef chef/chef_server_url string none" | debconf-set-selections && apt-get install chef -y -q
# Stop and disable the chef-client service since we're only using chef-solo
/etc/init.d/chef-client stop
leonid-shevtsov / proposal.markdown
Created May 10, 2012
DOU Hackathon Dnepr-May-2012 project proposal
View proposal.markdown

Архиватор Твиттера


  • Старые данные Твиттера невозможно или сложно найти: старые ретвиты, упоминания пользователя / хештега / произвольной фразы и т.п.
  • Твиты хранятся только в твиттере, а, следовательно, рискуют быть утерянными в случае сбоя/удаления старых данных/удаления пользователя
  • Многие люди пользуются твиттером как блогом, публикуя полезную информацию только в твиттер, несмотря на то, что просмотр старых твитов очень неудобен (нет поиска, архива-календаря и т.п.)


leonid-shevtsov / gist:2550423
Created Apr 29, 2012
Like find(:first), but asserts that query returns exactly one element. Works with scopes.
View gist:2550423
class MyModel < ActiveRecord::Base
results = find(:all, find_hash)
if results.size != 1
raise "Expected one record, found #{results.size}"
return results[0]
leonid-shevtsov / application.rb
Created Dec 10, 2011
View application.rb
# This snippet adds any and all CSS and JS files in asset directories to list of precompiled assets.
# Avoid the dreaded 'whatever.js isn't precompiled' error
config.assets.precompile += Dir['app/assets/stylesheets/**/*.css'].map{|f| f.gsub('app/assets/stylesheets/','')}
config.assets.precompile += Dir['app/assets/javascripts/**/*.js'].map{|f| f.gsub('app/assets/javascripts/','')}
View signup_steps.rb
When 'I signup as "$nickname" with email "$email" and password "$password"' do |nickname, email, password|
find('.cp_signup_nickname input.r').set nickname
find('.cp_signup_email input.r').set email
find('.cp_signup_password input.tip').click
find('.cp_signup_password input.password').set password
find('.cp_day .opener').click
find('.cp_day li[text()="1"]').click
find('.cp_month .opener').click
View escape_pres.rb
require 'cgi'
require 'nokogiri'
def escape_pres(text)
doc = Nokogiri::HTML(text)
pres = doc.css('pre').select do |pre|
# Select only PREs that don't have PREs as parents
# Slow but works
tag = pre.parent
View config_locales_en.yml
update: Foo was updated
create: Foo was created
View config_routes.rb
get '/services/:id', :to => 'service_types#show', :as => :service_type, :constraints =>, :position => 2)
leonid-shevtsov / redirect.rb
Created Oct 24, 2011
Rails redirect using post emulation
View redirect.rb
# This code isn't safe; at least add escaping to the url and the params.
class ActionController::Base
def redirect_using_post(url, params)
render :text => %Q{<form action="#{url}">#{{|k,v| %Q{<input type=
hidden" name="#{k}" value="#{v}" />}}.join('')}</form><script>document.forms[0].submit()</script>}
View gist:1158352
pg=# explain analyze SELECT * FROM "companies" WHERE ((lower(companies.title) LIKE 'c%') AND ("companies"."custom" = 'false')) ORDER BY title ASC LIMIT 100
Limit (cost=50411.91..50412.16 rows=100 width=817) (actual time=16646.708..16646.900 rows=100 loops=1)
-> Sort (cost=50411.91..50413.52 rows=647 width=817) (actual time=16646.701..16646.773 rows=100 loops=1)
Sort Key: title
Sort Method: top-N heapsort Memory: 66kB
-> Bitmap Heap Scan on companies (cost=7678.75..50387.18 rows=647 width=817) (actual time=1084.527..16643.838 rows=795 loops=1)
Filter: ((NOT custom) AND (lower((title)::text)
You can’t perform that action at this time.