Skip to content

Instantly share code, notes, and snippets.

View marktabler's full-sized avatar

Mark Tabler marktabler

View GitHub Profile
@marktabler
marktabler / popsites.rb
Created October 31, 2010 18:30
Read a file containing 1 website address per line, and open each in the default browser.
#!/usr/bin/env ruby
require 'rubygems'
require 'launchy'
if File.exists?(ARGV[0])
sites = File.open(ARGV[0])
sites.each { |line| Launchy.open(line)}
else
abort "No link file found (#{ARGV[0]}), usage is 'popsites <linkfile>'"
@marktabler
marktabler / pa-cipher.rb
Created October 13, 2011 07:31
Penny-Arcade Cipher Decryptor
class WordIndexCipher
attr_accessor :source_text, :character_table
def initialize(text)
@source_text = text.upcase.split(' ')
make_character_table
end
def encode(text)
@cipher = ""
Somebody say something!
@marktabler
marktabler / pretty_hash.rb
Created May 22, 2012 22:43
A quick and dirty hash beautifier
def self.pretty_hash(hash)
results = []
hash.keys.each do |key|
results << key
if hash[key].respond_to?(:keys)
results << pretty_hash(hash[key]).split("\n").map do | line |
" -- " + line
end
end
end
Pigeons cannot lick their own necks.
This rarely appears to impede them.
@marktabler
marktabler / deploy.rb
Created June 11, 2012 20:41
Capistrano Config
# Configure these lines for your app prior to launch.
# Application Name is the folder it will deploy to.
# Script Name is the name of the logfile and the god script.
# Start Command is the command god will issue to start the process.
APPLICATION_NAME = "FayeServer"
SCRIPT_NAME = "faye"
REPOSITORY = "git://github.com/HungryAcademyTeam4/FayeServer.git"
START_COMMAND = 'rainbows /apps/FayeServer/current/faye.ru -c /apps/FayeServer/current/rainbows.conf -E production -p 9000'
@marktabler
marktabler / chutes.rb
Last active December 13, 2015 21:58 — forked from anonymous/gist:4980502
class Board
def initialize
@squares = {}
101.times do |n|
@squares[n] = n
end
@squares.delete(0)
set_active_squares
end
@marktabler
marktabler / hipster_attr.rb
Created March 1, 2013 18:17
Hipster Attr
class Class
def hipster_attr(*methods)
methods.each do |method|
define_method(method) do
instance_variable_get("@#{method}")
end
setter = method.to_s + "="
define_method(setter.to_sym) do |value|
instance_variable_set("@#{method}", value)
@marktabler
marktabler / Benchmark Notes
Last active December 29, 2015 09:19
Ruby API Framework Benchmarks
Sinatra 1.4.4
Rails 4.0.1
Rails-API 0.1.0
Rails-API disabled Mailer and Sockets
Each app connected to a MySQL database via ActiveRecord with an empty Accounts table; each app's root path responded with "#{Account.count} accounts detected."
Each app was configured to use Thin as its web server.
@marktabler
marktabler / content_proxy.rb
Last active March 1, 2016 23:10
Middleware Content Proxy
class ContentProxy
def initialize(app)
@app = app
end
def should_use_cms?
# Some logic goes here, examining the request path and making the determination
# about whether to render using the CMS engine or let the request bubble up
# to the Rails app. This example looks for URIs starting with "/blog"
env['REQUEST_URI'] =~ /^\/blog/