Skip to content

Instantly share code, notes, and snippets.

@wulftone
wulftone / functions.php
Created April 9, 2010 19:35
An API extension for FX.php, the PHP interface to FileMaker Pro
<?php
/**
* This file is an extension for FX.php, the PHP interface to FileMaker Pro.
* It will make your life much easier for petty FileMaker tasks!
*
* It also includes a "deluxe nav bar" function which is just a glorified
* version of the normal page navigation bar for sets of records.
*
* Go to the Psych Department Wiki for the latest version of this class--
@wulftone
wulftone / bitmask_helpers.rb
Created October 5, 2011 22:22
Extending String and Array with bitmask helpers
# Convert a number in a string to a different base (stolen from stackoverflow.com)
class String
def convert_base(from, to)
self.to_i(from).to_s(to)
end
end
# Convert an array to it's maximum value if it were representing binary and filled with 1's
class Array
def max_bitmask
@wulftone
wulftone / random_string.rb
Created October 5, 2011 23:59
Generate a random string (extracted from WEBrick)
# extracted from the WEBrick::Utils module
RAND_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
def random_string(len)
rand_max = RAND_CHARS.bytesize
ret = ""
len.times{ ret << RAND_CHARS[rand(rand_max)] }
ret
end
@wulftone
wulftone / template_block_example.rb
Created October 27, 2011 21:30
Make your own template block evaluator thing
# In a helper
def box(&block)
("<div class='box'>" + capture(&block) + "</div>").html_safe
end
# In your view template
#<%= box do %>
# <p>Hello World!</p>
#<% end %>
@wulftone
wulftone / db_reload.rake
Created November 2, 2011 01:21
Rake task for Rails: Completely reload test and dev databases
namespace :db do
desc 'Drop, create, migrate, and seed a database'
task :reload => :environment do
puts "Environment Check: Rails Environment = #{Rails.env}"
Rake::Task['db:drop'].reenable
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].reenable
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].reenable if Rails.env.development?
Rake::Task['db:migrate'].invoke if Rails.env.development?
@wulftone
wulftone / update-css-rule.coffee
Created December 20, 2011 19:46
Update a CSS Rule--(A Rule, as opposed to a CSS property of a rendered element)
# http://blog.hashtagify.me/2011/12/08/update-css-rules-with-5-lines-of-coffeescript/
# http://jsfiddle.net/danmaz74/C7dv4/1/
@updateCSS = (selector, styles) ->
for sheet in document.styleSheets
for rule in sheet.cssRules || sheet.rules || []
if rule.selectorText == selector
for style, value of styles
rule.style[style] = value
@wulftone
wulftone / view-manager-example.js.coffee
Created December 24, 2011 01:36
Creating a Backbone.js View Manager
((Account) ->
Account.Route.Registration = Backbone.Router.extend(
routes:
"": "index"
"!/choose": "choose"
initialize: (args) ->
if args.view_managers
_.each args.view_managers, ((view_manager, name) ->
this[name] = view_manager
@wulftone
wulftone / backbone_base_view.js.coffee
Created December 24, 2011 01:46
Handy base class extensions for Backbone.View
# Credit goes to JonnyO from stackoverflow: http://stackoverflow.com/questions/7567404/backbone-js-repopulate-or-recreate-the-view/7607853
@BaseView = (options) ->
@bindings = []
Backbone.View.apply this, [ options ]
_.extend BaseView::, Backbone.View::,
# binds and keeps track of objects (models and collections) we want this view to respond to
bindTo: (model, event, callback) ->
model.bind event, callback, this
@wulftone
wulftone / description
Created January 4, 2012 02:05 — forked from irrationalidiot/description
Cucumber, rspec and spork setup using watchr for rails
Gems:
gem 'cucumber'
gem 'cucumber-rails'
gem 'rspec'
gem 'rspec-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'spork'
gem 'watchr'
@wulftone
wulftone / gist:1573449
Created January 7, 2012 01:49 — forked from mikegehard/gist:954537
Waiting until all jquery ajax calls are done
//Useful if you have a slow CI server...
When /^I wait until all Ajax requests are complete$/ do
wait_until do
page.evaluate_script('$.active') == 0
end
end