Skip to content

Instantly share code, notes, and snippets.

:shipit:
Always be shipping

Jerod Santo jerodsanto

:shipit:
Always be shipping
Block or report user

Report or block jerodsanto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pages_controller.rb
class PagesController < ApplicationController
exposes :weather
def index
@weather = Rails.cache.fetch "weather", expires_in: 5.minutes do
Weather.lookup 68164
end
render
end
@jerodsanto
jerodsanto / top_hn.rb
Created Dec 31, 2012
fetches the top content on Hacker News
View top_hn.rb
require "open-uri"
require "cgi"
require "json"
SEARCH_API = URI "http://api.thriftdb.com/api.hnsearch.com/items/_search"
START_DATE = "2012-01-01"
END_DATE = "2012-12-31"
TOP_LIMIT = 10
def get(type, sortby)
View hex2ip.rb
# e.g. - "AC 10 01 3D" => "172.16.1.61"
def hex2ip(hex)
hex.split(" ").map { |i| i.to_i(16) }.join(".")
end
View star_ect_with_object.rb
require "minitest/autorun"
module Enumerable
def collect(&block)
each_with_object([]) { |i, obj| obj << block.call(i) }
end
def detect(&block)
# each_with_object(nil) { |i, obj| obj ||= block.call(i) ? i : nil }
inject(nil) { |obj, i| obj ||= block.call(i) ? i : nil; obj }
@jerodsanto
jerodsanto / wp_prepare.rb
Created Apr 25, 2012
Run this on a WordPress SQL dump before importing it into your dev env
View wp_prepare.rb
#!/usr/bin/env ruby
unless filename = ARGV.first
abort "usage: #{__FILE__} file [http://host] [theme]"
end
host = ARGV[1] || "http://wp33.dev"
theme = ARGV[2] || "twentyten"
text = File.read(filename)
text.gsub! /'siteurl','.*',/, "'siteurl','#{host}',"
@jerodsanto
jerodsanto / gist:1472671
Created Dec 13, 2011
Printing the $PATH with each entry on a separate line
View gist:1472671
# using ruby:
$ echo $PATH | ruby -e 'STDIN.read.split(":").each { |l| puts l }'
$ echo $PATH | ruby -e 'print STDIN.read.gsub(":", "\n")'
# Using sed: I would expect this to work, but it does not
$ echo $PATH | sed 's/:/\n/g'
View unique_id.rb
module UniqueId
def self.included(base)
raise StandardError, "model must have 'uuid'" unless base.columns.any? { |c| c.name == 'uuid' }
base.before_create do
self.uuid = UUID.generate unless uuid.present?
end
end
end
@jerodsanto
jerodsanto / ios5_notify.sh
Created Oct 12, 2011
Siri, tell me when iOS 5 is available. Nothing? Fine. Bash, you do it.
View ios5_notify.sh
#!/bin/bash
while :
do
echo "Checking for iOS 5: `date`"
result=`curl -s -L http://phobos.apple.com/version | grep Restore | grep iPhone | grep 5.0`
if [ -z "$result" ]; then
echo "Nothing yet..."
else
say "I O S 5 IS NOW AVAILABLE. GO GET YOUR DOWNLOAD ON, KID"
fi
@jerodsanto
jerodsanto / set_wallpaper.rb
Created Sep 20, 2011
MacRuby script to set wallpaper on all connected monitors
View set_wallpaper.rb
#!/usr/bin/env macruby
abort "Usage: #{__FILE__} [image]" if ARGV.empty?
framework "Cocoa"
wallpaper_path = File.expand_path(ARGV.first)
wallpaper_url = NSURL.fileURLWithPath(wallpaper_path, isDirectory: false)
workspace = NSWorkspace.sharedWorkspace
@jerodsanto
jerodsanto / gist:1137337
Created Aug 10, 2011
Bookmarklet to uncripple Kindle Cloud Reader
View gist:1137337
(function() {
function uncrippleFrame() {
var body = this.contentWindow.document.getElementsByTagName('body')[0];
this.contentWindow.onclick = null;
body._frame = this;
body.onmousemove = function() {
this._frame.contentWindow.onclick = null;
this.setAttribute('style', '-webkit-user-select: auto;');
You can’t perform that action at this time.