Skip to content

Instantly share code, notes, and snippets.

View bmc's full-sized avatar

Brian Clapper bmc

  • Suburban Philadelphia, PA, US
View GitHub Profile
@bmc
bmc / testwrapmany.rb
Created August 2, 2011 15:11
Wrapping multiple objects in Ruby
class Foo
attr_reader :a, :b
def initialize
@a = 'a-Foo'
@b = 'b-Foo'
end
end
class Bar
attr_reader :a, :c
@bmc
bmc / doofus.rb
Created June 30, 2011 20:27
Sample, simple Sinatra + JSON thingie
require 'rubygems'
require 'sinatra'
require 'json'
get '/', :provides => 'json' do
data = {"key1" => ["a", "b"],
"key2" => 10}
JSON::dump(data)
end
@bmc
bmc / scalatest-sbt-fragment.scala
Created May 17, 2011 13:41
Supporting ScalaTest with Scala 2.8 and 2.9 in SBT
val (scalatestArtifact, scalatestVersion) = buildScalaVersion match
{
case "2.7.7" => ("scalatest", "1.2")
case "2.8.0" => ("scalatest", "1.3")
case "2.8.1" => ("scalatest", "1.3")
case "2.9.0" => ("scalatest_2.9.0", "1.4.1")
case n => error("Unsupported Scala version " + n)
}
val scalatest = "org.scalatest" % scalatestArtifact % scalatestVersion % "test"
@bmc
bmc / googl.rb
Created April 1, 2011 21:21
Access goo.gl from Ruby
# Test of Goo.gl Ruby gem. Install via:
#
# $ gem install googl
#
# See
# http://code.google.com/apis/urlshortener/v1/getting_started.html#shorten
# for Goo.gl API info.
require 'rubygems'
require 'googl'
@bmc
bmc / shorten.py
Created April 1, 2011 21:08
Access goo.gl from Python
# Test of Goo.gl Python front-end available at
# http://code.google.com/p/python-googl/source/checkout
#
# Some kind of JSON parser must be installed. 'simplejson' works fine.
#
# See
# http://code.google.com/apis/urlshortener/v1/getting_started.html#shorten
# for Goo.gl API info.
import googl
@bmc
bmc / fixepub.rb
Created March 7, 2011 19:57
Hack a Pandoc-generated EPUB to have a cover image.
#!/usr/bin/env ruby
#
# Fix an EPUB document generated by Pandoc to have a title page.
#
# Usage: fixepub epub_in epub_out cover_png
#
# Only supports PNG at the moment, but easily hacked to support JPEG.
#
# Requires these gems:
#
@bmc
bmc / blog-108-bmc-dev.rb
Created February 14, 2011 18:48
ActionMailer: Overrides
# Override the SMTP settings, for local testing.
$smtp_address = 'mail.inside.ardentex.com'
$smtp_domain = 'inside.ardentex.com'
$smtp_auth_type = nil
$smtp_user = nil
$smtp_password = nil
$smtp_port = 25
@bmc
bmc / blog-108-environment.rb
Created February 14, 2011 18:39
ActionMailer: environment.rb
Rails::Initializer.run do |config|
# The following globals define the default SMTP configuration. To
# change the configuration in your environment, simply set these globals
# in your environment configuration (config/*.rb) file.
$smtp_address = 'smtpserver.example.com'
$smtp_domain = 'example.com'
$smtp_auth_type = :plain
$smtp_user = '[email protected]'
$smtp_password = 'secret'
@bmc
bmc / CallableHash.rb
Created February 7, 2011 03:36
Screwing around with a CallableHash class in Ruby
class CallableHash < Hash
def initialize(h)
h.each do |k, v|
self[k] = v
end
@@methods = {}
end
def respond_to?(sym)
true
@bmc
bmc / asusertest.rb
Created January 1, 2011 15:59
Testing asuser.rb gist
puts("Caller PID = #{Process.pid}")
puts("Caller UID = #{Process.uid}")
as_user "bmc" do |user|
puts("In child process. User=#{user}, PID=#{Process.pid}, UID=#{Process.uid}")
end