Skip to content

Instantly share code, notes, and snippets.

@lpar
lpar / index.html
Created January 19, 2012 17:51
Simple JavaScript slideshow - no frameworks, no CSS3, no Flash
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Slideshow demo</title>
<script type="text/javascript" src="slideshow.js"></script>
<style type="text/css">
#current { position: absolute; left: 0px; top: 0px; z-index: 0; }
#next { position: absolute; left: 640px; top: 0px; z-index: 1; }
#slideshow { position: relative; border: solid #2b2b2b 3px; overflow: hidden; }
</style>
@lpar
lpar / atomizer.js
Created January 11, 2012 21:40
Atomizer: Small embeddable JavaScript web client for Atom feeds.
/*jslint browser: true, indent: 2 */
// Atomizer: Small embeddable JavaScript web client for Atom feeds (RFC 4287).
//
// Generates unordered lists or tables which can be inserted anywhere on
// the page using innerHTML.
//
// The Atom feed needs to be on the same hostname, port and protocol as the
// web page, because of browser security policies.
// See <http://en.wikipedia.org/wiki/Same_origin_policy>
@lpar
lpar / forkboy.rb
Created December 23, 2011 18:54
Locate files on Mac OS X which have resource forks
#!/usr/bin/env ruby
# encoding: UTF-8
# Utility for Mac OS X to locate files which have resource forks, and which
# therefore might be corrupted by being transferred via a non-Mac filesystem.
require 'find'
if ARGV.length != 1
puts "usage: forkboy <dir>"
@lpar
lpar / SubClass.java
Created November 15, 2011 21:58
Java field initialization weirdness with primitive values
public class SubClass extends SuperClass {
protected int myValue = 69;
public SubClass() {
// You might think that field initialization will have been performed before this constructor is executed.
super();
// However, Java doesn't actually perform all the field initialization for this object until this point in the code.
// Note also that there's nothing in the source code to say that initialization happens here.
System.out.println("Subclass constructor continuing");
@lpar
lpar / godel.rb
Created November 3, 2011 14:05
Simple Gödel encoding and decoding
#!/usr/bin/env ruby
# encoding: UTF-8
#
# Simple Gödel encoding
# Ruby 1.9.3
require 'prime'
# Allowed characters
CHARS = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@lpar
lpar / gist:1320801
Created October 27, 2011 20:42
Generic skeleton template for a command line utility written in Ruby
#!/usr/bin/env ruby
# encoding: UTF-8
'di '
'ig00 '
# This is both a Ruby script and a man page; you can symlink it into your
# man directory as commandname.1 or run man -l on this file.
# This is a generic skeleton for a Ruby command-line utility, showing how to
# make the same file work as both a Ruby script and a man page, for ease of
# distribution. This cool hack brought to you by mathew <meta@pobox.com>.
@lpar
lpar / Stopwatch.java
Created July 26, 2011 19:55
Stopwatch: Record real time taken for an operation, across multiple runs
import java.text.DecimalFormat;
/**
* The Stopwatch class provides a simple way to record the real-world time taken by an operation,
* averaged over multiple runs, and report the result easily in logs.
*
* An example use case would be timing JDBC calls to a relational database.
*
* This code does not measure CPU time or pay any attention to whether a thread or process is
* active or not. For that, you need to use a profiler.
@lpar
lpar / domino2syslog.rb
Last active August 29, 2016 16:14
Ruby code to pump IBM Lotus Domino server logs to regular Unix syslog
#!/usr/bin/env ruby
# encoding: UTF-8
# Script to take IBM Lotus Domino console input on stdin, and send it to
# syslog.
#
# Allows you to do all your logging via syslog, rather than having to
# keep weeks of data in log.nsf.
#
# In rsyslog, filter like this:
@lpar
lpar / jay
Created June 20, 2011 17:13
jay - a utility for removing excess kernel files from Ubuntu systems
#!/usr/bin/env ruby
# encoding: UTF-8
'di '
'ig00 '
# This is both a Ruby script and a man page; you can symlink it into your
# man directory as /usr/local/man/man8/jay.1 or run man -l on this file.
# The package which contains the kernel image itself
KERNEL_PACKAGE = 'linux-image'
@lpar
lpar / timeout.rb
Created June 17, 2011 20:41
Run a shell command in a separate thread, terminate it after a time limit, return its output
# Runs a specified shell command in a separate thread.
# If it exceeds the given timeout in seconds, kills it.
# Returns any output produced by the command (stdout or stderr) as a String.
# Uses Kernel.select to wait up to the tick length (in seconds) between
# checks on the command's status
#
# If you've got a cleaner way of doing this, I'd be interested to see it.
# If you think you can do it with Ruby's Timeout module, think again.
def run_with_timeout(command, timeout, tick)
output = ''