Skip to content

Instantly share code, notes, and snippets.

@backus
backus / HackerSpace-Hackathon-p2.py
Created November 24, 2012 02:31
HackerSpace Hackathon Problem #2 - Retrieve Reddit’s top cat pictures from today, yesterday, the day before yesterday, and n days ago.
import urllib2
import json
import datetime
'''Constants'''
catSubreddits = ['cat','catpictures','cats','flyingcats','catgifs','lolcats']
''' Prompt for num days back '''
nDaysSet=False
while nDaysSet is not True:
@backus
backus / Function-Description-Comment-Block.sublime-snippet
Created February 6, 2013 09:31
Pre-Function Comment Block. Function, usage, dynamic underline, then description
<snippet>
<content><![CDATA[/**
* Function: ${1:Name}
* Usage: ${1:Name}(${2:params})
* -----------${1/./\-/g}${2/./\-/g}
* ${4:Description}
*/]]></content>
<tabTrigger>funcdesc</tabTrigger>
<description>Function name, usage, and description</description>
<scope>source.c, source.h, source.cpp</scope>
@backus
backus / pagination.jade
Last active August 14, 2018 08:30
Jade + Bootstrap Pagination Mixin
//- Pagination mixin
//- ----------------
//- start=# to start pagination at
//- numPages=# links to serve up
//- base=base url before num
//-
//- Example:
//- pagination(3,5,4,'/fda/')
//- Yields: | « | 3 | 4 | 5 | 6 | 7 | » |
//- « = /fda/2, 3 = /fda/3, 4 = #, .. 7 = /fda/7, » = /fda/8
tell application "Messages"
quit
end tell
tell application "HipChat"
quit
end tell
tell application "Cryptocat"
quit
@backus
backus / explain.sh
Created August 30, 2013 08:13
command line explain for http://explainshell.com
#!/bin/bash
cmd="$(cut -d ' ' -f 1 <<< "$@" )";
args="$(cut -d ' ' -f 2- <<< "$@" )";
url="http://explainshell.com/explain/$cmd?args=$args"
explanation="$(curl -s $url | grep '<pre' | sed -E 's/<\/?[a-z]+(\ [a-z]+=\"[a-z0-9]+\")*>//g' | sed -E 's/^\ +//g')"
echo "$explanation"
module EngineControllerPatch
def self.included(base)
@http_methods ||= [ :get, :post, :put, :patch, :delete ]
@http_methods.each { |http_method| patch_http_method http_method }
end
def self.patch_http_method(http_method)
define_method(http_method) do |action, parameters = nil, session = nil, flash = nil|
process_action(action, parameters, session, flash, http_method.to_s.upcase)
end
@backus
backus / 01_test.rb
Created May 17, 2015 02:56
Surprising return from `parent_name`
require 'active_support'
require 'active_support/core_ext'
require 'active_record'
require 'test/unit'
# Setup
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
require 'factory_girl'
require 'faker'
class JsonStrategy # From http://git.io/vT8kC
def initialize
@strategy = FactoryGirl.strategy_by_name(:create).new
end
delegate :association, to: :@strategy
@backus
backus / Gemfile
Created July 11, 2015 07:06
Guard critics
source 'https://rubygems.org'
ruby '2.2.2'
group :development do
# Handle file system changes and run things
gem 'guard', '~> 2.12.4'
# Intelligently Autorun Tests
gem 'guard-rspec', '~> 4.2.0'