Skip to content

Instantly share code, notes, and snippets.

View workmad3's full-sized avatar

David Workman workmad3

View GitHub Profile
@workmad3
workmad3 / do.rb
Last active August 29, 2015 14:02
class TrueClass
def do(_if: ->{}, _else: ->{})
_if.call
self
end
end
class FalseClass
def do(_if: ->{}, _else: ->{})
_else.call
class Foobar < ActiveRecord::Base
attr_accessor :foobar
def as_json(options = {})
options[:methods] ||= []
options[:methods] << :foobar
super(options)
end
end
hasQueryVariable = (variable)->
query = window.location.search.substring(1)
queryVars = query.split("&")
for queryVar in queryVars
queryKv = queryVar.split("=")
if queryKv[0] == variable
#Return true as soon as we find the variable nam
return true
Foo.transaction do
Foo.connection.execute("CREATE TEMPORARY TABLE temp_foos ON COMMIT DROP AS (SELECT *, RANDOM() AS rank FROM foos)")
Foo.select("temp_foos.*").from("temp_foos").order("rank").find_each do |foo|
#whatever
end
end
# Load *.bash files in the .bashrc.d directory. Put bash config files there.
export $BASH_D=$HOME/.bashrc.d
if [ -d $BASH_D ]; then
for conf in $BASH_D/*.bash; do
. $conf
done
fi
setup: &SETUP
adapter: postgresql
encoding: utf8
reconnect: true
pool: 5
timeout: 5000
production:
<<: *SETUP
database: <project_name>_production
describe TTT::ConsolePrinter
subject{TTT::ConsolePrinter.new(output)}
let(:output) {StringIO.new("")}
let(:board) {...}
it "should be awesome" do
subject.print(board)
expect(output.read).to eq("An awesome TTT board")
end
end
class LinkedList
def initialize(items)
items = Array(items)
if items.size == 1
@value = items[0]
else
@value, @next = items[0], LinkedList.new(items[1..-1])
end
end
<tr>
<td><%= hours[:paylocity_id] %></td>
<td>E</td>
<td>REG</td>
<td><%= hours[:regular_hours] %></td>
</tr>
<tr>
<td><%= hours[:paylocity_id] %></td>
<td>E</td>
<td>OT</td>
" Reset to preferred behaviour {{{
set norelativenumber
set number
" }}}
" Extra setup {{{
" General {{{
set softtabstop=2
set shiftwidth=2