Skip to content

Instantly share code, notes, and snippets.

View heycarsten's full-sized avatar

Carsten Nielsen heycarsten

View GitHub Profile
@heycarsten
heycarsten / gist:3239720
Last active October 7, 2015 23:08
Dumb-Dumb's Guide To Manually Provisioning A Linode For A Ruby App

Manually Provisioning A Linode For A Ruby App

Alright, let's get started. Create a new Ubuntu 12.04 LTS instance, boot it up, and SSH into the fresh Linode as root. Now update/upgrade your sources and install Git and curl:

apt-get update
apt-get upgrade
@heycarsten
heycarsten / musical-keys.txt
Created February 15, 2012 07:36
List of musical keys from Wikipedia.
A major: A
A minor: a
A-flat major: A♭
A-flat minor: a♭
A-sharp minor: a♯
B major: B
B minor: b
B-flat major: B♭
B-flat minor: b♭
C major: C
@heycarsten
heycarsten / gist:1219443
Created September 15, 2011 14:49
Yes, this happened.
heycarsten:~ carsten$ gem install rakins
Successfully installed rakins-0.0.1
1 gem installed
heycarsten:~ carsten$ rakins install rakins
,,,,
.' `/\_/\
' <@V@> /===========================
<(((((((((( ) ( \./ <== INSTALLIN' rakins, YO. =
\(''''''\(\( \===========================
`-"`-" " "
@heycarsten
heycarsten / time_ranges.rb
Created August 19, 2011 18:53
Benchmarking creating arrays of time ranges, using Range and a while loop.
require 'benchmark'
require 'time'
SECS_IN_HOUR = 3600
def while_loop
now = Time.now
ago = now - (SECS_IN_HOUR * 23)
max, count, times = now.to_i, ago.to_i, []
begin
@heycarsten
heycarsten / quick_token.rb
Created August 19, 2011 00:02
Benchmarking generating fairly unique tokens quickly without external dependencies
require 'benchmark'
Benchmark.bmbm do |x|
x.report('printf') do
for i in 1..1_000_000
3.times.map { '%06x' % rand(0x100000) }.join
end
end
x.report('to_s') do
@heycarsten
heycarsten / queue_classic.rb
Created August 9, 2011 22:36
A moderately hacky way of generating a PG connection string from AR::Base.configurations to use with QueueClassic
ENV['DATABASE_URL'] ||= lambda {
def config
ActiveRecord::Base.configurations[Rails.env.to_s]
end
def credentials
if (creds = [config['user'], config['password']]).any?
creds.join(':')
else
nil
@heycarsten
heycarsten / lcbo-api-example.html
Created February 3, 2011 21:00
A demonstration of using LCBO API directly from a web-browser using jQuery and JSON-P
<!DOCTYPE html>
<html>
<head>
<title>Using LCBO API via jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
<script type="text/javascript">
// Let's make an object in the global namespace that will serve as an API
// wrapper for LCBO API.
var LCBO = new function() {
# I had no idea that you could do this:
def attribute(name, type = Ohm::Types::String, klass = Ohm::Types[type])
# If no 3rd argument is provided then it uses the second argument to key
# the default value. Not super obvious, but now that I know about it, I
# think it's kinda cool :-)
# I wanted a simple object factory for use with Ohm, I'm used to factory_girl
# and fabrication. After a few minutes of messing around and trying to get them
# to work with Ohm, I decided to try giving it a whirl myself...
class Factory
def self.factories
@factories ||= {}
end
heycarsten:lcbo carsten$ gem list nokogiri
*** LOCAL GEMS ***
nokogiri (1.4.3)
heycarsten:lcbo carsten$ irb
ruby-1.9.2-preview3 > require 'nokogiri'
LoadError: no such file to load -- nokogiri/version_warning
from /Users/carsten/.rvm/gems/ruby-1.9.2-preview3/gems/nokogiri-1.4.3/lib/nokogiri.rb:34:in `require'
from /Users/carsten/.rvm/gems/ruby-1.9.2-preview3/gems/nokogiri-1.4.3/lib/nokogiri.rb:34:in `<top (required)>'