Skip to content

Instantly share code, notes, and snippets.

View ahoward's full-sized avatar
💭
probably outside if i'm not hacking.

ara.t.howard ahoward

💭
probably outside if i'm not hacking.
View GitHub Profile
# config/initializers/trailing_slash.rb
Rails.configuration.before_initialize do
ActionController::Base.module_eval do
before_filter :enforce_trailing_slash
protected
def enforce_trailing_slash
@ahoward
ahoward / a.rb
Created May 30, 2014 17:04
this bitchin script can boil virtually any rails project in a pure static ball of goodness suitable for deployment to s3, bitballoon, etc.
#! /usr/bin/env ruby
# this script can create a static build from virtually any rails' project. it
# has two simple requirements.
#
# 1) you have
#
# gem 'passenger'
#
# in your Gemfile
@ahoward
ahoward / a.rb
Created June 4, 2014 17:24
~/dot/ify (should be in Dropbox for sanity)
#! /usr/bin/env ruby
# usage
#
usage = <<-__
dot/ify
keep *all* your dot files in one directory. link them back into your home
dir. for example
curl \
-i \
-u "$account:$token" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X PUT \
-d@- \
"$api/v1/credit_cards/:id" <<-__
{"credit_card":{"month":7}}
class BatonPass
Fattr(:window){ Rails.env.production? ? 24.hours : 10.seconds }
def BatonPass.rollup!
#
counts = Map.new
window = BatonPass.window
#
to_rollup = BatonPass.where(:auto => true)
@ahoward
ahoward / a.rb
Created August 5, 2014 15:59
make sure a ruby program can run only one copy of itself
#! /usr/bin/env ruby
# it's trivial ot make a ruby program run once.
#
status = DATA.flock(File::LOCK_EX|File::LOCK_NB)
unless status == 0
puts "another process has the lock"
exit(42)
#alias rb='rbenv'
# path setup
#
# paths=`cat ~/.paths.sh`
# PATH=`ruby -e' PATH=ENV["PATH"].split(/:/); \
# ARGV.reverse.each{|path| PATH.delete(path); PATH.unshift(path)};\
# PATH.map!{|path| File.expand_path(path)};\
# PATH.uniq!; print(PATH.join(":")) ' '~/bin' "$paths" "$PATH" 2>/dev/null`
@ahoward
ahoward / favicon.sh
Created August 21, 2014 16:44
generating correct favicons is trivial with image magick
#! /bin/sh
# file : ~/bin/favicon
#
# usage: favicon foo.png
convert "$@" -resize 16x16 favicon-16.png
convert "$@" -resize 32x32 favicon-32.png
convert "$@" -resize 64x64 favicon-64.png
convert "$@" -resize 128x128 favicon-128.png
//
s3Uploader.content_type_for = function(file_input, file_name, content_type){
content_type = content_type || 'application/octet-stream';
try{
content_type = jQuery(file_input).prop('files')[0]['type']
} catch(e) {};
if(!content_type){
var parts = file_name.split('.');
@ahoward
ahoward / a.rb
Last active August 29, 2015 14:07
# this code _must_ return a hash since the result hash is used to log information about the job run.
#
# by using catch/throw via 'return_result' it's easy to control the return value while still decorating
# it with key info, such as 'elapsed' time.
#
def run