Skip to content

Instantly share code, notes, and snippets.

Michael Kirk michaelkirk

Block or report user

Report or block michaelkirk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:948835
params = {"longitude":194.5432,"latitude":194.5432}
ct = CountThreshold.create!(params)
#was longitude assigned?
puts ct.longitude
# re populate ct from the DB based on it's ID to make sure the fields were persisted.
ct.reload
#was longitude persisted?
@michaelkirk
michaelkirk / gist:948842
Created Apr 29, 2011
ruby, dumb but true
View gist:948842
#this is dumb but true
irb(main):001:0> a = {:a => 1}
=> {:a=>1}
irb(main):002:0> a['a']
=> nil
irb(main):003:0> a[:a]
=> 1
View terrain.py
@before.harvest
def setup_test_database(variables):
# Setup the testing database
world.test_runner = django_nose.NoseTestSuiteRunner()
# Setup environment.
world.test_runner.setup_test_environment()
# Create Base DB
world.test_db = world.test_runner.setup_databases()
@before.harvest
@michaelkirk
michaelkirk / terrain.py
Created Mar 6, 2012
terrain.py for lettuce, using south
View terrain.py
from lettuce import after, before, world
from selenium import webdriver
from django.core.management import call_command
from django.test.simple import DjangoTestSuiteRunner
import lettuce_webdriver.webdriver
@before.harvest
def setup_test_database_and_env(variables):
# FIXME when path_for_test_db_setup is outside of this method,
# running ./manage.py test explodes
@michaelkirk
michaelkirk / unoptimize_to_xs_hack.rb
Created Apr 26, 2012
work around for rails 3 to_xs
View unoptimize_to_xs_hack.rb
# work around for https://github.com/rails/rails/pull/2076
class String
alias_method :to_xs, :original_xs
end
View show-remote-branch-info.sh
#!/bin/sh
#
# Too many crusty old git branches? Run this to find likely candidates for deletion
# It lists all the remote branches and sorts them by age.
#
# Folks at pivotal shared this with me
#
#$ . show-remote-branch-info.sh
# 2012-05-04 09:42:29 -0700 4 minutes ago Ted & Bill \torigin/hey_Bill
@michaelkirk
michaelkirk / .ackrc
Created Jun 5, 2012
get ack to search cucumbers
View .ackrc
--type-set=cucumber=.feature
--cucumber
View application_helper.rb
module ApplicationHelper
def usable_time_ago(time)
time_string = if (Time.now - time) < 10.days
time_ago_in_words(time) + " ago"
else
time.to_s(:long)
end
"<abbr class='datetime' title='#{time}'>#{time_string}</abbr>".html_safe
end
@michaelkirk
michaelkirk / download_dom_node.js
Created Aug 28, 2012
client side file generation and download
View download_dom_node.js
// Download a piece of the DOM in a file
// Based on http://stackoverflow.com/questions/4498122/how-to-save-dynamicly-changed-byjquery-html-dom
var $node = $("svg")[0];
var text = new XMLSerializer().serializeToString($node);
// large data URI support is dubious but works on most "modern" browsers.
var data_uri = "data:application/octet-stream," + encodeURIComponent(text);
$("body").append("<a href='" + data_uri + "'>Save</a>");
View overlapping_prefixes.rb
# given a list of numbers, print any prefixes that overlap.
#
# e.g. [1, 2, 34, 35] has no overlaps
# e.g. [1, 2, 34, 3, 5] overlaps (3 is more general than 34)
#
# This is useful in the TZip gem, since if our prefixes
# overlap, the more specific mapping will never be used - probably
# not the intended behavior of anyone inputting a mapping.
#
# Note: this doesn't detect duplicate prefixes, since they've already
You can’t perform that action at this time.