Skip to content

Instantly share code, notes, and snippets.

View jerodsanto's full-sized avatar
:shipit:
Always be shipping

Jerod Santo jerodsanto

:shipit:
Always be shipping
View GitHub Profile
@jerodsanto
jerodsanto / firehol.conf
Last active December 19, 2015 18:39
various Debian-related scripts & configs
version 5
FIREHOL_LOG_PREFIX="firehol: "
interface any world
policy drop
server "ssh icmp http https" accept
client all accept
[ext2/1/ext 1 (0,20)] [straight_topics_core`, `infix_topics_core] apple @sphinx_internal_class_name (Topic)
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 December 31, 2012 13:57
fetches the top content on Hacker News
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)
# e.g. - "AC 10 01 3D" => "172.16.1.61"
def hex2ip(hex)
hex.split(" ").map { |i| i.to_i(16) }.join(".")
end
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 April 25, 2012 19:12
Run this on a WordPress SQL dump before importing it into your dev env
#!/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 December 13, 2011 16:00
Printing the $PATH with each entry on a separate line
# 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'
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 October 12, 2011 13:50
Siri, tell me when iOS 5 is available. Nothing? Fine. Bash, you do it.
#!/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