Skip to content

Instantly share code, notes, and snippets.

View ianterrell's full-sized avatar

Ian Terrell ianterrell

  • University of Virginia
  • Charlottesville, VA
View GitHub Profile
@ianterrell
ianterrell / gitdb
Created March 3, 2011 15:09
Small script to
#!/usr/bin/env ruby
# Usage:
# gitdb copy
# Copies the current development database into db/branchname-development.sqlite3
# gitdb
# Copies the db/branchname-development.sqlite3 into the default db/development.sqlite3
branch = `git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'`.gsub('* ','').strip
@ianterrell
ianterrell / bulk_domain_generator.rb
Created April 16, 2011 16:40
Generate .coms for a bulk search
# Usage:
# ruby bulk_domain_generator.rb word [word...]
suffixes = ['able','ac','acity','ade','age','aholic','al','algia','an','ance','ant','ar','ard','arian','arium','ary','ate','ation','ative','cide','cracy','crat','cule','cy','cycle','dom','dox','ectomy','ed','ee','eer','emia','en','ence','ency','ent','er','ern','escence','ese','esque','ess','est','etic','ette','ful','fy','hood','ial','ian','iasis','iatric','ible','ile','ily','ine','ing','ion','ious','ish','ism','ist','ite','itis','ity','ive','ization','ize','less','let','like','ling','log','ly','ment','ness','oid','ology','oma','onym','opia','opsy','or','ory','osis','ous','path','pathy','phile','phobia','phone','phyte','plegia','plegic','pnea','sect','ship','sion','some','th','tion','trophy','tude','ty','ular','uous','ure','ward','ware','wise','y']
i = 0
ARGV.each do |a|
suffixes.each do |b|
i += 1
puts "#{a}#{b}.com"
@ianterrell
ianterrell / referral_codes.rb
Created April 18, 2011 14:35
Quickly generate pretty referral codes through Base-N encoding
# Want to give your users nice referral URLs, like http://www.service.com/?r=2ab3 ?
#
# A fast and easy 1-1 method is to use base-n encoded numbers.
#
# For instance, encode the user's id in base 36. In Ruby, this is easy:
# > 272927.to_s(36)
# => "5ulb"
#
# To get the base 10 id back again is just as easy:
# > "5ulb".to_i(36)
module Foo
def self.included(base)
class << base
attr_accessor :bar
end
end
def set
self.class.bar = "hello there"
end
@ianterrell
ianterrell / gist:1102751
Created July 24, 2011 15:49 — forked from deathbob/gist:1102683
Meta module madness
module Foo
def bar
@bar ||= self.snakes
end
end
class Baz
def self.snakes
[:cobra]
class NSString < Mobi::Cocoa::Object
end
class UIAlertView < Mobi::Cocoa::Object
def self.alert(title, message, options={})
alert = UIAlertView._alloc \
._initWithTitle _S(title),
:message, _S(message),
:delegate, nil,
:cancelButtonTitle, options[:cancel_title] ? _S(options[:cancel_title]) || nil,
#define p1prime(p1,p2,p3,p4) (u0*u0*u0*p1 + (t0*u0*u0 + u0*t0*u0 + u0*u0*t0)*p2 + (t0*t0*u0 + u0*t0*t0 + t0*u0*t0)*p3 + t0*t0*t0*p4)
#define p2prime(p1,p2,p3,p4) (u0*u0*u1*p1 + (t0*u0*u1 + u0*t0*u1 + u0*u0*t1)*p2 + (t0*t0*u1 + u0*t0*t1 + t0*u0*t1)*p3 + t0*t0*t1*p4)
#define p3prime(p1,p2,p3,p4) (u0*u1*u1*p1 + (t0*u1*u1 + u0*t1*u1 + u0*u1*t1)*p2 + (t0*t1*u1 + u0*t1*t1 + t0*u1*t1)*p3 + t0*t1*t1*p4)
#define p4prime(p1,p2,p3,p4) (u1*u1*u1*p1 + (t1*u1*u1 + u1*t1*u1 + u1*u1*t1)*p2 + (t1*t1*u1 + u1*t1*t1 + t1*u1*t1)*p3 + t1*t1*t1*p4)
@ianterrell
ianterrell / BDD.swift
Last active August 29, 2015 14:02
Rspec style matchers for Swift
import XCTest
protocol Matchable : Equatable, Comparable { }
class Matcher<T : Matchable> {
let subjectWrapper: T[]
var subject: T {
get {
return subjectWrapper[0]
function execute_loop() {
var vmfunc, pathtab, path;
var pathstart, pathend;
if (resumefuncop) {
//qlog("### at resume time, storing value " + resumevalue + " at funcop " + resumefuncop.key);
store_operand_by_funcop(resumefuncop, resumevalue);
resumefuncop = null;
resumevalue = 0;
}
// This handles most storyboard style injection needs
extension UIViewController {
func injectable<T>() -> T? {
var controller: UIViewController? = self
if let nav = self as? UINavigationController {
controller = nav.viewControllers.first
}
return controller as? T
}