Skip to content

Instantly share code, notes, and snippets.

@lpar
lpar / inimerge.rb
Created Sep 9, 2011
Merge NOTES.INI files
View inimerge.rb
#!/usr/bin/ruby
# encoding: UTF-8
# Merge NOTES.INI files.
# Should also work on other INI files which only have a single [section]
# First argument is the current NOTES.INI file.
# Second argument is the file containing directives to merge in.
# Output to stdout is the new NOTES.INI file.
# A new directive which assigns no value deletes matching directives;
@lpar
lpar / gist:1320801
Created Oct 27, 2011
Generic skeleton template for a command line utility written in Ruby
View gist:1320801
#!/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 / SubClass.java
Created Nov 15, 2011
Java field initialization weirdness with primitive values
View SubClass.java
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 / index.html
Created Jan 19, 2012
Simple JavaScript slideshow - no frameworks, no CSS3, no Flash
View index.html
<!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 / example.rb
Created Mar 23, 2012
Brief demonstration of using character encodings in Ruby 1.9
View example.rb
#!/usr/bin/env ruby
# encoding: UTF-8
# Notice I set UTF-8 as the default above. As far as I'm concerned there
# are two choices of encoding: UTF-8, and legacy crap. If I need to deal
# with anything else I'll handle it explicitly, as in this example.
# Open an ISO-8859-1 file.
infile = File.open("iso88591.txt", "r:iso-8859-1")
@lpar
lpar / java-install
Last active Oct 29, 2015
Set up Java on Linux
View java-install
#!/usr/bin/env ruby
# encoding: UTF-8
# Programs to install from the Java runtimes
PROGS = ['java', 'javac', 'javaws', 'jar', 'keytool']
# Plugins for browsers, original lib name then the name to use in the
# alternatives system
PLUGINS = {
'libnpjp2.so' => 'libjavaplugin.so'
@lpar
lpar / bom.c
Created Dec 1, 2015
Somebody set us up the BOM!
View bom.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *ifp, *ofp;
ofp = fopen("test.txt", "wb");
@lpar
lpar / reader2evernote.rb
Created Mar 14, 2013
Google Reader to Evernote. Quick hack together of a Ruby script which will pull all your Google Reader starred items into an Evernote notebook in ENML (Evernote export format).
View reader2evernote.rb
#!/usr/bin/env ruby
# encoding: UTF-8
# Google Reader to Evernote
# Quick hack together of a Ruby script which will pull all your Google Reader
# starred items into an Evernote notebook in ENML (Evernote export format).
# Requires Ruby 2.0, no other special dependencies. Should work on 1.9 but I
# haven't tested it.
#
@lpar
lpar / logreport.rb
Created Jun 7, 2013
Report the first 10 lines of all files on the command line, transparently decompressing .xz compressed files.
View logreport.rb
#!/usr/bin/ruby
# encoding: UTF-8
# The audit team wanted to know that we were doing logging as required. As
# evidence, they asked for a regular report consisting of the first 10 lines
# of each daily log file. I wrote this script to automate the process.
# If you want the last 10 lines instead, I suggest the Ruby Gem called Elif,
# which wraps any IO object to read line by line backwards.
LINES_OF_LOG = 10
View Clean up download files.applescript
-- This is the script piece of an Automator workflow, it won't work without the rest of the workflow.
on run {input, parameters}
set maxDaysOld to 14 -- This is the number of days of stuff to keep
set oldFiles to {}
set oldFilesRef to a reference to oldFiles
repeat with n from 1 to length of input
set thing to item n of input
set dateAddedString to (do shell script "mdls -name kMDItemDateAdded -raw " & quoted form of POSIX path of thing)
set dateadded to the (date dateAddedString)
set daysold to ((current date) - dateadded) / 86400