Skip to content

Instantly share code, notes, and snippets.

@tomdunning
tomdunning / match_data.rb
Last active August 10, 2020 23:24
Sample previous and current matches
previous_matches_collection = [{"start_time"=>1597093971.496, "item_id"=>1302, "start_time_range"=>1597093969.996..1597093972.996}, {"start_time"=>1597093971.576, "item_id"=>1302, "start_time_range"=>1597093970.076..1597093973.076}, {"start_time"=>1597093991.856, "item_id"=>1230, "start_time_range"=>1597093990.356..1597093993.356}, {"start_time"=>1597093971.336, "item_id"=>1086, "start_time_range"=>1597093969.836..1597093972.836}, {"start_time"=>1597093971.416, "item_id"=>1086, "start_time_range"=>1597093969.916..1597093972.916}, {"start_time"=>1597093987.616, "item_id"=>926, "start_time_range"=>1597093986.116..1597093989.116}, {"start_time"=>1597093988.096, "item_id"=>926, "start_time_range"=>1597093986.596..1597093989.596}, {"start_time"=>1597093988.576, "item_id"=>926, "start_time_range"=>1597093987.076..1597093990.076}, {"start_time"=>1597093974.016, "item_id"=>893, "start_time_range"=>1597093972.516..1597093975.516}, {"start_time"=>1597093971.256, "item_id"=>527, "start_time_range"=>1597093969.756..15970
@tomdunning
tomdunning / Sublime user settings
Last active April 8, 2019 09:49
Sublime text preferences
{
"ensure_newline_at_eof_on_save": true, # good for git
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",
".sass-cache",
"log",
@tomdunning
tomdunning / capybara cheat sheet
Created July 20, 2016 15:00 — forked from zhengjia/capybara cheat sheet
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')
@tomdunning
tomdunning / exception_list.rb
Created April 25, 2016 09:37
List all Exceptions currently in the project
exceptions = []
ObjectSpace.each_object(Class) {|k| exceptions << k if k.ancestors.include?(Exception) }
puts exceptions.sort { |a,b| a.to_s <=> b.to_s }.join("\n")
IOS_DEVICES = {
'iPhone1,1' => 'iPhone 1G',
'iPhone1,2' => 'iPhone 3G',
'iPhone2,1' => 'iPhone 3GS',
'iPhone3,1' => 'iPhone 4',
'iPhone3,3' => 'iPhone 4 (Verizon)',
'iPhone4,1' => 'iPhone 4S',
'iPhone5,1' => 'iPhone 5 (GSM)',
'iPhone5,2' => 'iPhone 5 (GSM+CDMA)',
'iPhone5,3' => 'iPhone 5C (GSM)',
@tomdunning
tomdunning / irb
Created February 26, 2015 13:30
merge with CouchDB
@db = CouchRest.database("http://127.0.0.1:5984/couchrest-test")
# setup an new record, missing the key
response = @db.save_doc({:key => 'value', 'another key' => 'another value'})
# and retrieve it
doc = @db.get(response['id'])
# merge new key!
doc.merge!({'new key' => 'foo'})
# => {"_id"=>"f5f855649ac666c35a8027f16c21330b", "_rev"=>"2-007fe4639675067edd9a590cf0a170d5", "key"=>"value", "another key"=>"another value", "new key"=>"foo"}
doc
@tomdunning
tomdunning / gist:e9460699f1de58b01360
Created August 27, 2014 11:11
Prototype to jQuery
Prototype jQuery/Javascript
in controller in JS/ERb view (xxxxxx.js.erb)
--------- -----------------
page.alert "message" alert('message');
page.hide "id" $('#id').hide();
page.insert_html \
:top, "id", "content" $('#id').prepend('content');
:bottom, "id", "content" $('#id').append('content');
:before, "id", "content" $('#id').before('content');
:after, "id", "content" $('#id').after('content');
@tomdunning
tomdunning / gist:8337414
Created January 9, 2014 16:42
ajax call
//<![CDATA[
new Ajax.Request('/m/finance/recurring_voucher_payments/user_voucher_info?user_data='+value.id, {
method:'get',
onComplete: function(transport){
var r = transport.responseText.evalJSON();
element.up().down('user_voucher_id').innerHTML = <%= options_for_select("r.user_vouchers") %>;
}
});
//]]>
@tomdunning
tomdunning / rename_rhtmls
Created September 17, 2013 13:36
rename rhtml files => html.erb
find ./ -name \*.rhtml -type f | sed 's/\(.*\).rhtml$/mv "&" "\1.html.erb"/' | sh
@tomdunning
tomdunning / user.rb
Created June 19, 2012 21:11
user resources / access control
def user_resources(compact = false)
x = []
x << Resource.all(:conditions => {:resource_for_type => "All"})
x << self.branch.resources
x << self.branch.area.resources
x << self.branch.zone.resources
#we then need the resources to which each of their roles has been assigned
for role_assignment in self.current_role_assignments