Skip to content

Instantly share code, notes, and snippets.

@lpar
lpar / md5daemon
Created June 17, 2011 20:23
Automatic MD5 checksum generating daemon for use with vsftpd
#!/usr/bin/env ruby
# encoding: UTF-8
'di '
'ig00 '
# VSFTPD auto-MD5 program
#
# Run man -l <this file> for documentation
require 'rb-inotify'
@lpar
lpar / jdbcexample.java
Created June 17, 2011 18:38
An example of performing a JDBC query from Java and handling exceptions correctly
/**
* A correct example of performing a SQL query using JDBC.
*
* See http://lpar.ath0.com/2008/09/05/java-jdbc-and-memory-leaks/ for
* discussion; correct examples of Java JDBC code are surprisingly rare.
*/
public static void doSomething() {
try {
Connection connection = DriverManager.getConnection(JDBC_URL);
try {
@lpar
lpar / weeknum.ls
Created June 17, 2011 18:28
ISO 8601 week number calculation in LotusScript
Function WeekNumber(t As NotesDateTime) As String
' Wrapper to work out week numbers of NotesDateTime objects in the
' current time zone
Dim lst As Variant
lst = t.LSLocalTime
WeekNumber = LSWeekNumber(lst)
End Function
Function LSWeekNumber(t As Variant) As String
' Returns the week number of a NotesDateTime object
@lpar
lpar / utf8truncate.java
Created June 17, 2011 18:21
Truncate a Java string so that its UTF-8 representation will not exceed the specified number of bytes
/**
* Truncate a Java string so that its UTF-8 representation will not
* exceed the specified number of bytes.
*
* For discussion of why you might want to do this, see
* http://lpar.ath0.com/2011/06/07/unicode-alchemy-with-db2/
*/
public static String utf8truncate(String input, int length) {
StringBuffer result = new StringBuffer(length);
int resultlen = 0;
@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: