Skip to content

Instantly share code, notes, and snippets.

View leonid-shevtsov's full-sized avatar
🇺🇦
Help Ukraine Win

Leonid Shevtsov leonid-shevtsov

🇺🇦
Help Ukraine Win
View GitHub Profile
@leonid-shevtsov
leonid-shevtsov / application.rb
Created December 10, 2011 17:57
PRECOMPILE ALL THE ASSETS!
# 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/','')}
When 'I signup as "$nickname" with email "$email" and password "$password"' do |nickname, email, password|
find('.toggle-signup-block').click
find('#signup-regular').click
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
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
en:
success_messages:
update: Foo was updated
create: Foo was created
get '/services/:id', :to => 'service_types#show', :as => :service_type, :constraints => SlugConstraint.new(ServiceType, :position => 2)
@leonid-shevtsov
leonid-shevtsov / redirect.rb
Created October 24, 2011 18:42
Rails redirect using post emulation
# 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}">#{params.map{|k,v| %Q{<input type=
hidden" name="#{k}" value="#{v}" />}}.join('')}</form><script>document.forms[0].submit()</script>}
end
end
pg=# explain analyze SELECT * FROM "companies" WHERE ((lower(companies.title) LIKE 'c%') AND ("companies"."custom" = 'false')) ORDER BY title ASC LIMIT 100
;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
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)
<div class='paginator'>
{% if paginator.next_page %}
<div class='paginator-next'>
<a href='/page{{paginator.next_page}}'>
Earlier posts &rarr;
</a>
</div>
{% endif %}
{% if paginator.previous_page %}
<div class='paginator-prev'>
task :default_cities => :environment do
require 'fastercsv'
city_map = City.all.inject({}) do |cities, city|
cities[city.name] ||= []
cities[city.name] << city
cities
end
population = {}
found = %w(html body h1 h2 h3 h4 h5 h6 a ul ol li p div i b strong em)
not_found = []
File.read('app/stylesheets/common.sass').each do |line|
next if line =~ /^[\s|@|\/]/
elements = line.strip.split(/[^\w\-_]/).reject{|l| l==''}.reject{|l| found.include?(l) || not_found.include?(l)}
elements.each do |element|
result = `ack-grep #{element} --nocss`
if result.length>0
puts element