Skip to content

Instantly share code, notes, and snippets.

View seanreads's full-sized avatar
🎸
Rock and Roll!

Sean seanreads

🎸
Rock and Roll!
View GitHub Profile
@seanreads
seanreads / deployed.sh
Last active November 10, 2017 17:41
See if HEAD revision of current branch is deployed to Heroku remote app
# zsh alias:
# return commit hash if your current branch's HEAD revision is the deployed revision, i.e., its deployed!
# if deployed, hash is returned
# if not deployed, no value is returned
alias deployed="echo $(heroku releases | head -2 | tail -n 1 | cut -d' ' -f4) | grep $(git rev-parse HEAD | cut -c 1-8)"
# troubleshooting
# be sure that your local branch is set to the branch corresponding to the remote Heroku deployment
# be sure that your heroku remote is pointed at the correct app, e.g. heroku git:remote -a <appname>
@seanreads
seanreads / deep_sort.rb
Last active September 26, 2017 13:43
deep sort javascript object by attribute
require 'deepsort'
require 'json'
# you've got a nested array of hashes of arrays of hashes ... of arrays of hashes
# and you want to sort hash entries by a specific attribute, like a label used for display.
json = '' # TODO: Add example
data = JSON.parse(json)
sorted_data = data.deep_sort_by{|obj| obj['label'] if (obj.is_a?(Hash) && obj.key?('label')) }
sorted_data.to_json
@seanreads
seanreads / controller.rb
Created December 16, 2015 15:24
Ruby on Rails action to updated a remote irrigation controller
def create_configs(identifier, cfg_xml)
device = Device.find_by_identifier_nwa(identifier)
@hostname = device.ip_address
@port = 18466
@timeout = 60
@username = params[:username]
@password = params[:password]
@remote_path = '/ugmo/augusta/config/rc'
@configs = %w{clock-config sensor-config zone-config}
@tempdir = nil
@seanreads
seanreads / ryb.java
Last active August 29, 2015 14:11
RYB
/*** RYB code excerpt ***/
abstract class Dot {
int c, t, x, y, w, h, d, r;
boolean v;
Dot(color c, int t, int x, int y, int w, int h, boolean v) {
this.c = c;
this.t = t;
this.x = x;
this.y = y;
@seanreads
seanreads / unvox.sh
Created December 23, 2013 22:08
# find iphone voicemails and save them locally
# unvox.sh
# find iphone voicemails and save them locally
#
# Sean O'Donnell
# Mon Dec 23 14:36:42 EST 2013
#
# requires ffmpeg, see http://www.ffmpeg.org/
BASE_DIR=$(dirname $(dirname $0))
INPUT_DIR="${HOME}/Library/Application Support/MobileSync/Backup"
@seanreads
seanreads / portfolio.js
Created October 23, 2013 15:52
Client-side component to Portfolio manager project
/* Portfolio - Create PDF reports of user progress
Author: Sean O'Donnell <sodonnell@acponline.org>
Revised: April 7, 2010
*/
//TODO: Put CSS selectors in PortfolioOptions
var PortfolioOptions = {
debug_mode: false,
create_document_url: '/residents/portfolio',
@seanreads
seanreads / S3UrlController.rb
Last active December 25, 2015 23:59
Use Rails
class S3UrlController < AuthenticatedController
# Retreive a list of S3 objects
# For a given object, get a temporary, secret URL
skip_filter(*_process_action_callbacks.map(&:filter)) # Turn off any before filter that...
before_filter :basic_authenticate # ... is not your HTTP Basic authentication
rescue_from Exception do |error|
logger.error(error)
@seanreads
seanreads / stamp.rb
Last active December 25, 2015 23:49
Utility class to convert datetime column values from one timezone to another (e.g., local to UTC).
#!/usr/bin/env ruby
# Stamp class
# Utility class to convert datetime column values from
# one timezone to another (e.g., local to UTC).
class Stamp
attr_accessor :query, :status
attr_reader :records, :duplicates
def initialize(columns, old_time_zone, new_time_zone, time_format = "%F %T")
@seanreads
seanreads / rspec.rake
Created December 19, 2012 00:32
Run `rake spec`, `rake spec:models`, `rake spec:controllers`, etc without running prerequisite tasks. Helpful for working with non-migration-aware (i.e., legacy databases).
# Run `rake spec`, `rake spec:models`, `rake spec:controllers`, etc
# without running prerequisite, database tasks. Helpful for working
# with non-migration-aware, legacy databases.
if defined?(RSpec)
tasks = %w{ spec models controllers helpers lib mailers
rcov requests routing views }
skip_db_task = Proc.new do |task|
path = task.eql?('spec') ? 'spec/**' : "spec/#{task}"
@seanreads
seanreads / get_and_set_hash_values_with_dot_syntax.rb
Last active October 12, 2015 17:08
Get and Set Hash Values with Dot syntax
class Hash
def method_missing(method, *args, &block)
key = method.to_s
key =~ /(.+)=$/ ? store($1, args[0]) : fetch(key)
end
end
h = Hash.new
h.foo = 'bar'
p h.foo