Skip to content

Instantly share code, notes, and snippets.

View stevenschobert's full-sized avatar

Steven Schobert stevenschobert

View GitHub Profile
@stevenschobert
stevenschobert / api_client.rb
Last active March 22, 2016 04:01
Quick start file for an API client in Ruby
class ApiClient
attr_accessor :api_key
def initialize(api_key: nil)
@api_key = api_key
end
def some_method
path = "/some_path"
get_json!(path)
@stevenschobert
stevenschobert / rack_counter.ru
Last active November 10, 2015 22:46
Rack powered counter JSON API. For testing purposes.
require 'rack'
require 'json'
COUNTERS = {}
app = Proc.new do |env|
req = Rack::Request.new(env)
COUNTERS[req.path] ||= 0
@stevenschobert
stevenschobert / import.sh
Last active August 29, 2015 14:22
Importing data from Heroku PostgeSQL application
heroku pg:backups capture
# replace BACKUP_NUM with backup number from above
heroku pg:backups public-url BACKUP_NUM
# replace URL with step from above
curl -o latest.dump URL
# replace LOCAL_DB_NAME with local database table
# replace DB_USERNAME with db user
@stevenschobert
stevenschobert / get_dock_dimensions.scpt
Created January 18, 2015 04:43
Get the dimensions of the OS X dock using AppleScript
tell application "System Events" to tell process "Dock"
set dock_dimensions to size in list 1
set dock_width to item 1 of dock_dimensions
set dock_height to item 2 of dock_dimensions
end tell
@stevenschobert
stevenschobert / omnifocus-open-inbox.scpt
Last active August 29, 2015 14:13
Quickly open my "Inbox" and "Today" perspectives in OmniFocus
tell application "OmniFocus" to activate
tell application "System Events"
tell process "OmniFocus"
set perspectivesMenu to the first menu bar item of item 1 of menu bars whose name contains "Perspectives"
set inboxMenuItem to the first menu item of the first menu of perspectivesMenu whose name is "Inbox"
set viewMenu to the first menu bar item of item 1 of menu bars whose name contains "View"
click inboxMenuItem
@stevenschobert
stevenschobert / extend.js
Created December 30, 2014 15:12
Object extending - supports N... arguments
function extend() {
var args = [].slice.call(arguments);
args[0] = (typeof args[0] === 'object') ? args[0] : {};
for (var i=1; i<args.length; i++) {
if (typeof args[i] === 'object') {
for (var key in args[i]) {
if (args[i].hasOwnProperty(key)) {
args[0][key] = args[i][key];
}
}
@stevenschobert
stevenschobert / clone.js
Last active August 29, 2015 14:12
Object Cloning (with deep support) - modeled after Lodash's _.clone implementation. Supports strings, numbers, booleans, dates, regexps, objects, and arrays.
function clone(value, deep) {
var boo = '[object Boolean]';
var num = '[object Number]';
var str = '[object String]';
var obj = '[object Object]';
var arr = '[object Array]';
var date = '[object Date]';
var reg = '[object RegExp]';
var cloned;
var klass;
@stevenschobert
stevenschobert / instafeed_wrap_fourth.js
Created December 18, 2014 18:32
Instafeed.js - Wrap every 4th item with a tag
var count = 0;
var feed = new Instafeed({
filter: function(image) {
count += 1;
if (count % 4 === 0) {
image.customTagOpen = '<div>';
image.customTagClose = '</div>';
} else {
image.customTagOpen = '';
@stevenschobert
stevenschobert / camel_case.swift
Last active July 30, 2023 13:09
Camel-case a string in Swift
func camelCaseString(source: String) -> String {
if contains(source, " ") {
let first = source.substringToIndex(advance(source.startIndex, 1))
let cammel = NSString(format: "%@", (source as NSString).capitalizedString.stringByReplacingOccurrencesOfString(" ", withString: "", options: nil, range: nil)) as String
let rest = dropFirst(cammel)
return "\(first)\(rest)"
} else {
let first = (source as NSString).lowercaseString.substringToIndex(advance(source.startIndex, 1))
let rest = dropFirst(source)
return "\(first)\(rest)"
@stevenschobert
stevenschobert / request.js
Created December 2, 2014 20:02
Some bare-bones Request/Response prototypes for JavaScript. Wraps XMLHttpRequest.
/**
* Request class for making HTTP requests.
*
* new Request('http://api.com', {
* method: 'get',
* headers: {}
* }).send(function(res) {});
*/
function Request(url, opts) {
opts = opts || {};