This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class='paginator'> | |
{% if paginator.next_page %} | |
<div class='paginator-next'> | |
<a href='/page{{paginator.next_page}}'> | |
Earlier posts → | |
</a> | |
</div> | |
{% endif %} | |
{% if paginator.previous_page %} | |
<div class='paginator-prev'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/services/:id', :to => 'service_types#show', :as => :service_type, :constraints => SlugConstraint.new(ServiceType, :position => 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
en: | |
success_messages: | |
update: Foo was updated | |
create: Foo was created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |