Skip to content

Instantly share code, notes, and snippets.

View hwatkins's full-sized avatar

Hugh Watkins hwatkins

View GitHub Profile
#!/usr/bin/racc
# -*- encoding: utf-8 -*- Lapis Racc Parser Class
# Andy Brown <[email protected]> [April, 12, 2010]
/* This is a BNF style parser generator grammar for the
* Lapis Language to be used by racc. Racc is a tool
* much like Yacc or Bison implemented for Ruby.
*
* Racc will parse this file and create a lapis.tab.rb
* file that contains a Parser class with a do_parse
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Hugh Watkins">
<!-- Date: 2010-06-25 -->
<script type="text/javascript"
-module(stopwatch).
-behaviour(gen_server).
%% Server API
-export([start_link/0, stop/0]).
%% Client API
-export([start_timer/0, stop_timer/0, read_timer/0]).
%% gen_server callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% this module models a typical manager/worker pattern, where manager may spawn a large number of workers
%% required behaviour:
%%
%% 1) manager must log unexpected worker exits
%%
%% - manager must trap exits in init function -> 'process_flag(trap_exit, true)'
%% - workers must be spawned with spawn_link
%% - worker exit messages are handled by manager handle_info handler [where they can be logged etc]
@hwatkins
hwatkins / amqp_client
Created October 8, 2010 17:48
A rake file to pull the correct amqp_client libraries
SOURCE_DIRS=%w[deps/rabbitmq-server/src deps/rabbitmq-erlang-client/src]
INCLUDE_DIRS=%w[deps/rabbitmq-server/include deps/rabbitmq-erlang-client/include]
FILES=%w[rabbit_writer.erl
rabbit_reader.erl
rabbit_framing_amqp_0_8.erl
rabbit_framing_amqp_0_9_1.erl
rabbit_framing_channel.erl
rabbit_basic.erl
rabbit_binary_generator.erl
rabbit_binary_parser.erl
@hwatkins
hwatkins / pipetest.rb
Created December 8, 2010 18:31
Test case for Broken pipe in ruby libvirt
require "libvirt"
def nested
puts "nested"
h = Libvirt.connect
h.domains.each do |d|
puts "Domain: #{d.name}"
end
end
@hwatkins
hwatkins / application_helper.rb
Created December 18, 2010 14:40
Telephone number link
module ApplicationHelper
def phone_number_link(text)
sets_of_numbers = text.scan(/[0-9]+/)
number = "+1-#{sets_of_numbers.join('-')}"
link_to text, "tel:#{number}"
end
end
@hwatkins
hwatkins / ratings.rb
Created December 2, 2011 23:15
A script to use the Netflix paginated "What You've Rated" to pull what you have rated in Netflix. This call is not exposed in the Netflix API so it's hard to get any other way. This is quick and dirty so not the best Ruby constructs.
#!/usr/bin/env ruby
require 'iconv'
require 'nokogiri'
# This is a simple script to spider your Netflix paginated "What You've Rated" list.
# It requires an OS X based system with Ruby 1.9+, Safari, and AppleScript
#
# I could not find a way to back up my ratings (for all titles, not just my rental activity)
# without registering for a Netflix API key or handing my Netflix credentials over to someone
# who had an API key, so I decided to take a brute force approach and just parse the HTML for
@hwatkins
hwatkins / gist:3491399
Created August 27, 2012 19:10 — forked from seyhunak/gist:3479066
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@hwatkins
hwatkins / mongoid_3_multiple_database.txt
Created September 18, 2012 18:57
Mongoid 3.x multiple database
If you want to use multiple dbs at once there are several different ways...
1) If you want to do this on a per-model level, use .store_in (This is for all threads):
class Band
include Mongoid::Document
store_in database: "secondary" # This can be any name you want, no need to put it in the mongoid.yml.
end
class Artist