Skip to content

Instantly share code, notes, and snippets.

View matthutchinson's full-sized avatar
🧐
`¯\_(ツ)_/¯`

Matthew Hutchinson matthutchinson

🧐
`¯\_(ツ)_/¯`
View GitHub Profile
# subdomains.rake in /lib/tasks
namespace :subdomains do
desc "adds the necessary hosts to your /etc/hosts file from current subdomains in your application"
task :setup => :environment do
# NOTE: default_hosts is used as a locator for the line to update in /etc/hosts
tmp_file, changed = '/tmp/etc_hosts_copy', false
default_hosts, hosts = %w(blog.local emptyblog.blog.local), []
# find all the subdomains used in your app (push to hosts array) - modify this to suit your app
@matthutchinson
matthutchinson / fakeout.rake
Created February 10, 2010 16:49
fakeout.rake - a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker or ffaker gem
# sudo gem install faker - http://faker.rubyforge.org
# OR
# sudo gem install ffaker - http://github.com/EmmanuelOga/ffaker
require 'faker'
class Fakeout
@matthutchinson
matthutchinson / gist:320476
Created March 3, 2010 09:29
simple TwitStream using EventMachine
#!/usr/bin/env ruby
# usage;
# script/twitstream start
# script/twitstream stop
# script/twitstream restart
# pid and log at RAILS_ROOT/tmp/pids
# where config/twitstream.yml looks like this;
@matthutchinson
matthutchinson / fnotify.pl
Created August 21, 2010 10:47
Irssi fnotify
# todo: grap topic changes
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
authors => 'Thorsten Leemhuis',
contact => 'fedora@leemhuis.info',
@matthutchinson
matthutchinson / .bash_aliases
Created September 20, 2010 15:12
.bash_aliases
# launching console/server
sc () {
if [ -f ./script/rails ]; then
rails c $@
else
./script/console $@
fi
}
sg () {
@matthutchinson
matthutchinson / google_translate.rb
Created January 11, 2012 16:03
Ruby Google Translate v2 API wrapper and example usage
#!/usr/bin/env ruby
require 'net/http'
require 'net/https'
require 'uri'
require 'rubygems'
require 'json'
# consider these for better newline preservation?
#CGI.escape(content)
@matthutchinson
matthutchinson / rack_image_interceptor.rb
Created January 13, 2012 15:59
Broken or missing image interceptor
# lib/rack_image_interceptor.rb
module Rack
class ImageInterceptor
def initialize(app)
@app = app
end
def respond_with_placeholder_image(path)
file = ::File.open(path)
@matthutchinson
matthutchinson / google_geocoder.rb
Created January 17, 2012 17:35
Simple Google v3 API Geocoder in Ruby
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
class GoogleGeocoder
@matthutchinson
matthutchinson / distance_away_report.rb
Created January 20, 2012 11:18
Ruby script for the find distance between two points using haversine formula
MAX_DISTANCE_AWAY_IN_KM = 100.0
RAD_PER_DEG = 0.017453293
Rmiles = 3956 # radius of the great circle in miles
Rkm = 6371 # radius in kilometers, some algorithms use 6367
Rfeet = Rmiles * 5282 # radius in feet
Rmeters = Rkm * 1000 # radius in meters
def haversine_distance( lat1, lon1, lat2, lon2 )
dlon = lon2 - lon1
@matthutchinson
matthutchinson / std.js
Created January 20, 2012 17:37
Standard Deviation in Javascript
// http://jsfiddle.net/hiddenloop/TPeJt/
var array = [2, 3, 4, 6, 2, 5, 7, 2, 4, 5, 99];
var within_std_of = 3;
outputResult = function(str) {
var content = $('#results').html();
$('#results').html(content + str);
}