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 / 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}',"
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 }
# e.g. - "AC 10 01 3D" => "172.16.1.61"
def hex2ip(hex)
hex.split(" ").map { |i| i.to_i(16) }.join(".")
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)
class PagesController < ApplicationController
exposes :weather
def index
@weather = Rails.cache.fetch "weather", expires_in: 5.minutes do
Weather.lookup 68164
end
render
end
[ext2/1/ext 1 (0,20)] [straight_topics_core`, `infix_topics_core] apple @sphinx_internal_class_name (Topic)
@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
@jerodsanto
jerodsanto / httperf_big_cookies.rb
Created August 5, 2013 19:12
Httperf only allows cookies of 256 bytes or less. Rails sets cookies that are bigger than that. This will result in output such as `httperf.sess_cookie: truncating cookie to 245 bytes` and failed Rails sessions. This brew adds the `--big-cookies` option to the `httperf` formula so you can use it with Rails.
require 'formula'
class Httperf < Formula
homepage 'http://code.google.com/p/httperf/'
url 'http://httperf.googlecode.com/files/httperf-0.9.0.tar.gz'
sha1 '2aa885c0c143d809c0e50a6eca5063090bddee35'
option 'enable-debug', 'Build with debugging support'
option 'big-cookies', 'Allow cookies larger than 256 bytes'
@jerodsanto
jerodsanto / bb.rb
Last active August 29, 2015 14:07
Quick & dirty script to open the current directory's git repo on BitBucket. Surely there's a better way
#!/usr/bin/env ruby
if remote = `git remote -v`.lines.find { |l| l.match /bitbucket/ }
remote.match /(bitbucket\.org\/.*?)\.git/
system "open https://#{$1}"
else
puts "No BitBucket remote :("
end
@jerodsanto
jerodsanto / Rakefile
Created January 10, 2015 16:51
A code dump showing how we generate "The Changelog Weekly" using the Trello API
require "rubygems"
require "bundler"
require_relative "lib/importer"
Bundler.setup
desc "Import from Trello board"
task :import do
Importer.new(File.dirname(__FILE__)).import ENV["ISSUE"]
end