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
alias_method :old_data=, :data=
def data=(value)
old_data=(value)
self.file_updated=true
end
#!/usr/bin/env ruby
require 'optparse'
require 'time'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: git-timesheet [options]\nProduce a per-day activity report from the log of the current git repository.\n\n"
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
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 = {}
<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'>
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)
@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
get '/services/:id', :to => 'service_types#show', :as => :service_type, :constraints => SlugConstraint.new(ServiceType, :position => 2)
en:
success_messages:
update: Foo was updated
create: Foo was created
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