Skip to content

Instantly share code, notes, and snippets.

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@t2
t2 / application.rb
Created December 12, 2011 02:13
Formatting Rails form elements for Twitter Bootstrap error validation
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
# add nokogiri gem to Gemfile
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
elements.each do |e|
if e.node_name.eql? 'label'
html = %(<div class="clearfix error">#{e}</div>).html_safe
elsif e.node_name.eql? 'input'
if instance.error_message.kind_of?(Array)
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
@broccolini
broccolini / frontage.css
Created May 31, 2012 18:23 — forked from nrrrdcore/frontage.css
Outlined Type Effect with CSS Text-Shadowing
body {
background-color: #7A060C;
}
#wrapper {
width: 90%;
margin: 200px auto;
}
h1 {
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@kmandreza
kmandreza / Calculating the array mode
Created January 2, 2013 03:30
Write a method mode which takes an Array of numbers as its input and returns an Array of the most frequent values. If there's only one most-frequent value, it returns a single-element Array. For example, mode([1,2,3,3]) # => [3] mode([4.5, 0, 0]) # => [0] mode([1.5, -1, 1, 1.5]) # => [1.5] mode([1,1,2,2]) # => [1,2] mode([1,2,3]) # => [1,2,3], b…
def mode(array)
count = Hash.new(0)
array.each { |element| count[element] += 1 } #count how many times an element[s] appears the most
# element of the array => number of times element occured in an array
# ex. {5 => 2, 6 =>2, 7 =>1}
max = count.values.max
count.keep_if { |key, val| val == max}
# count is {5 => 2, 6 =>2}
count.keys #return an array of those elements
end
@eric1234
eric1234 / README.md
Last active December 11, 2015 22:08
S3 - Set permissions public on all files in a bucket using IronWorker.

Purpose

Workers to ensure all objects in a S3 bucket have the 'public-read' canned ACL permission. Designed to work with iron.io's IronWorker product to use it's scalable workers to set the permissions quickly and afforably.

Setup

@YayC
YayC / My_Shortcuts.md
Last active December 13, 2015 22:18
Some ST2 and OSX time savers that I use (as of the first night of Dev Bootcamp). Boosting the productivity of a total novice, give 'em a spin.

J's Essential Keyboard Shortcuts


ST2, Terminal, and OSX

If you haven't seen one of these, try it out! Well documented but these are the ones I use consistently.

⇧ = shift, ⌃ = ctrl, ⌥ = option, ⌘ = command (aka master)

Sublime Text 2

What an awesome tool.

@dbc-challenges
dbc-challenges / fgist.rb
Last active December 16, 2015 02:09
save this toyour ~/bin directory as "fgist" then run "chmod +x ~/bin/fgist" then make sure ~/bin is on your $PATH This will download all the contents of a gist to your current directory, given a gist url. run as: fgist https://gist.github.com/dbc-challenges/5360499
#!/usr/bin/env ruby
require 'net/https'
require 'json'
# a simple wrapper to do an HTTP GET
def fetch_uri(uri)
uri = URI(uri)
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@onewheelskyward
onewheelskyward / generate-hombrew-install-commands.rb
Last active February 16, 2024 08:57
brew reinstall commands
brews = []
out = IO.popen("brew list", "r") do |io|
brews = io.read.split "\n"
end
def parse(brew, brew_info)
in_options = false
print "brew reinstall -v #{brew} "
brew_info.split("\n").each do |m|
#puts m.inspect