This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
'di ' | |
'ig00 ' | |
# VSFTPD auto-MD5 program | |
# | |
# Run man -l <this file> for documentation | |
require 'rb-inotify' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]>. |
OlderNewer