Skip to content

Instantly share code, notes, and snippets.

@lpar
lpar / example.rb
Created March 23, 2012 22:56
Brief demonstration of using character encodings in Ruby 1.9
#!/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 October 29, 2015 14:39
Set up Java on Linux
#!/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 December 1, 2015 23:08
Somebody set us up the BOM!
#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 March 14, 2013 20:35
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).
#!/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 June 7, 2013 19:04
Report the first 10 lines of all files on the command line, transparently decompressing .xz compressed files.
#!/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
-- 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
@lpar
lpar / pwgen.rb
Created June 17, 2011 18:10
Simple generation of readable random passwords using Ruby
#!/usr/bin/env ruby
# encoding: UTF-8
# Simple password generation in Ruby.
#
# Generate reasonably secure random passwords of any chosen length,
# designed to be somewhat easy for humans to read and remember.
# Each password has a capitalized letter and a digit.
#
# Example:
@lpar
lpar / ldapauth.rb
Created June 7, 2013 14:53
Example of LDAP authentication in Ruby. Written for IBM Intranet, but should easily be adaptable to other environments.
#!/usr/bin/ruby
# An example of BluePages / IBM Intranet Password authentication using Ruby.
# Uses the gem ruby-ldap, a Ruby wrapper for OpenLDAP. Works with Ruby 2.0.
#
# To get this code to work, you must
#
# 1. gem install ruby-ldap
# 2. add
#
@lpar
lpar / combos
Last active July 13, 2016 14:17
Go programming exercise: generating all combinations of an alphabet of symbols
See https://forum.golangbridge.org/t/generation-of-strings-generation/2968/2
@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: