Skip to content

Instantly share code, notes, and snippets.

View bmc's full-sized avatar

Brian Clapper bmc

View GitHub Profile
import scala.util.continuations._
import java.io.File
object Test2
{
sealed trait Iteration[+T]
case class Yield[+T](result: T, next: () => Iteration[T])
extends Iteration[T]
@bmc
bmc / delicious2diigo.py
Created December 18, 2010 03:46
Quick hack to load Delicious bookmarks into Diigo
#!/usr/bin/python
# Based on diigo.py, which is copyright (c) 2008 Kliakhandler Kosta
# <Kliakhandler@Kosta.tk> and released under the GNU Public License.
#
# This hacked version is also released under the GNU Public License.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@bmc
bmc / asuser.rb
Created December 28, 2010 18:36
Run block as another user, in subprocess
require 'etc'
def as_user(user, &block)
# Find the user in the password database.
u = (user.is_a? Integer) ? Etc.getpwuid(user) : Etc.getpwnam(user)
# Fork the child process. Process.fork will run a given block of code
# in the child process.
Process.fork do
# We're in the child. Set the process's user ID.
@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
@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 / 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 = 'foobar@example.com'
$smtp_password = 'secret'
@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 / 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 / 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 / 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'