Skip to content

Instantly share code, notes, and snippets.

View stevenschobert's full-sized avatar

Steven Schobert stevenschobert

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / jira_header_color.js
Last active January 11, 2016 20:06
Tampermonkey (http://tampermonkey.net) script to change JIRA header color to black
// ==UserScript==
// @name JIRA Header color
// @namespace https://stevenschobert.com/
// @version 0.1
// @description Changes header color for JIRA.
// @author Steven Schobert
// @match https://ovenbits.atlassian.net/*
// @grant GM_addStyle
// ==/UserScript==
@stevenschobert
stevenschobert / api_client_standalone.rb
Last active February 2, 2017 19:17
Standalone Net::HTTP wrapper class for interfacing with JSON APIs. I typically use this when I have many classes that need to talk to different APIs in a project. Otherwise if I'm building a single API client gem, I sometimes use this instead: https://gist.github.com/stevenschobert/8df1dc08a96ba0ecc274
class ApiClient
attr_accessor :base_url
attr_accessor :default_headers
attr_accessor :default_params
attr_accessor :basic_auth
attr_reader :body
def initialize(base_url:, headers: {}, params: {})
@base_url = base_url
@stevenschobert
stevenschobert / footer_copyright.haml
Created February 6, 2016 06:14
Ruby/Haml snippet for an auto-updating copyright notice. Good for footers and such.