Skip to content

Instantly share code, notes, and snippets.

View stevegraham's full-sized avatar
🛠️
Building @tellerhq

Stevie Graham stevegraham

🛠️
Building @tellerhq
View GitHub Profile
@stevegraham
stevegraham / deal_with_it.rb
Created December 18, 2014 17:02
#20YearsOfCharacters #DealWithIt
require 'net/http'
require 'logger'
require 'mechanize'
logger = Logger.new(STDOUT)
req = Net::HTTP::Get.new '/'
drop_time = Time.local 2014, 12, 19, 12
req['User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10"
@stevegraham
stevegraham / active_jerbz.rake
Created December 4, 2014 15:47
Run ActiveJobs with Sneakers
require 'sneakers/runner'
task :environment
namespace :sneakers do
desc "Start processing jobs with all workers"
task :work => :environment do
silence_warnings do
Rails.application.eager_load! unless Rails.application.config.eager_load
end
module PaymentGatewayCheck
@available = nil
MUTEX = Mutex.new
TASK = PeriodicTask.new(every: 5.seconds, run_immediately: !Rails.env.test?) do
begin
result = HTTParty.get ENV['PAYMENT_GATEWAY_PING_ENDPOINT']
MUTEX.synchronize { @available = result.success? }
rescue SystemCallError
MUTEX.synchronize { @available = false }
# Returns methods in the order of definition
FooClass.instance_methods(false)
=> [:methods, :excluding, :from, :superclass, :returned, :in, :the, :order, :they, :were, :defined]
# Returns a sorted list
FooClass.instance_methods - FooClass.superclass.instance_methods
=> [:defined, :excluding, :from, :in, :methods, :order, :returned, :superclass, :the, :they, :were]
# WAT
@stevegraham
stevegraham / gist:833736560d72e15576bd
Last active August 29, 2015 14:04
Grab Instagram cookies
sudo tcpdump -U -In -i en0 -s 2048 -A dst i.instagram.com | ack -o "(?<=Cookie: ).+" --flush > ~/Desktop/cookies

Keybase proof

I hereby claim:

  • I am stevegraham on github.
  • I am sg (https://keybase.io/sg) on keybase.
  • I have a public key whose fingerprint is DB6D 0AB8 BEA8 3D90 E1FC B5A8 9E83 7DE0 28E3 4D82

To claim this, I am signing this object:

@stevegraham
stevegraham / description.js
Last active December 30, 2015 10:28
Restafarian "code-on-demand" example used to inform client what a valid resource is, including non-authorative property validations.
Function.prototype.curry = function() {
var fn = this;
var slice = Array.prototype.slice;
var args = slice.call(arguments);
return function() {
return fn.apply(this, args.concat(slice.call(arguments)));
}
}
// Cannot init an NSManagedObject. Have to insert into an NSManagedObjectContext instance.
NSManagedObjectSubclass * scratchObj = [NSEntityDescription insertNewObjectForEntityForName:@"Foo"
inManagedObjectContext:AppDelegate.managedObjectContext];
// Set the properties on our object, e.g. via UITextField IBOutlets
scratchObj.foo = @"foo";
// Post the object. Assume use of an RKMapping here.
[[RKObjectManager sharedManager] postObject:scratchObj path:nil parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
//
// NSString+Inflections.m
// Zap
//
// Created by Stevie Graham on 28/10/2013.
//
#import "NSString+Inflections.h"
@implementation NSString (Inflections)
@stevegraham
stevegraham / example.m
Last active December 20, 2015 03:59
parseport - leave parse whenever you want
NSString * const kAPIEndpoint = @"http://127.0.0.1:3000/";
void SwizzleInstanceMethod(Class class, SEL dstSel, SEL srcSel) {
Method dstMethod = class_getInstanceMethod(class, dstSel);
Method srcMethod = class_getInstanceMethod(class, srcSel);
if (class_addMethod(class, dstSel, method_getImplementation(srcMethod), method_getTypeEncoding(srcMethod))) {
class_replaceMethod(class, dstSel, method_getImplementation(dstMethod), method_getTypeEncoding(dstMethod));
} else {
method_exchangeImplementations(dstMethod, srcMethod);