Skip to content

Instantly share code, notes, and snippets.

@esamson
esamson / utf8ify.py
Created July 12, 2012 09:23
Use chardet to guess a file's encoding and then iconv to convert the file to UTF-8
#!/usr/bin/env python
import sys
import urllib
import chardet
import os
orig = sys.argv[1]
rawdata = urllib.urlopen(orig).read()
enc = chardet.detect(rawdata)['encoding']
@esamson
esamson / MapVsMap.java
Created July 26, 2012 03:24
Microbenchmark of `put()` and `get()` operations of Java Map implementations.
import java.util.*;
import java.math.*;
public class MapVsMap {
static final int MAP_SIZE = 100000;
static final int STR_LEN = 10;
static final int ROUNDS = 10;
static final char[] chars = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
@esamson
esamson / ttu.py
Created September 13, 2012 08:55
time-to-uwian
#!/usr/bin/env python
#
# Tools for the Extra Bored
# brought to you by Edward Samson
#
# time-to-uwian
#
# If you turn on your computer as soon as you get to work, this script will
# show how much longer you have to wait before you can leave.
#
@esamson
esamson / mysql_table_sizes.sql
Created December 6, 2012 01:48
MySQL table size, number of rows, and size of indexes
SELECT concat(table_schema,'.',table_name),
concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024*1024),2),'G') DATA,
concat(round(index_length/(1024*1024*1024),2),'G') idx,
concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(index_length/data_length,2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length+index_length DESC LIMIT 20;
@esamson
esamson / slf4j.tmpl
Created January 20, 2013 14:23
Improved NetBeans code template for generating an SLF4J Logger declaration. See http://wiki.netbeans.org/SLF4JCodeTemplate for instructions on how to use.
private static final ${LOG_TYPE type="org.slf4j.Logger" default="Logger" editable=false} log =
${LOG_FACT type="org.slf4j.LoggerFactory" default="LoggerFactory" editable=false}.getLogger(${classVar editable="false" currClassName default="getClass()"}.class);
@esamson
esamson / logback.xml
Created February 14, 2013 03:30
Logback configuration to keep unit tests quiet.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%r [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<root>
<level value="error" />
<appender-ref ref="STDOUT" />
@esamson
esamson / default-license.ftl
Created February 27, 2013 02:25
My NetBeans default license template. Copyright year is automatically determined from the current date.
<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix}Copyright ${date?date?string("yyyy")} Edward Samson
<#if licenseLast??>
${licenseLast}
</#if>
@esamson
esamson / Stinger-2.2-2.2.2.diff
Created November 12, 2013 01:35
Source file changes between Stinger-2.2 and Stinger-2.2.2
diff -ur Stinger-2.2/src/org/owasp/stinger/Stinger.java Stinger-2.2.2/src/org/owasp/stinger/Stinger.java
--- Stinger-2.2/src/org/owasp/stinger/Stinger.java 2006-11-21 21:11:16.000000000 +0800
+++ Stinger-2.2.2/src/org/owasp/stinger/Stinger.java 2007-12-20 11:04:30.000000000 +0800
@@ -44,12 +44,15 @@
private static RuleSet set = null;
+ private static boolean debug = false;
+
private Stinger() {
@esamson
esamson / makeapp.sh
Last active August 29, 2015 13:57 — forked from demonbane/makeapp.sh
#!/bin/sh
echo "What should the Application be called (no spaces allowed e.g. GCal)?"
read inputline
name="$inputline"
echo "What is the url (e.g. https://www.google.com/calendar/render)?"
read inputline
url="$inputline"
@esamson
esamson / InYourProcessor.java
Last active May 2, 2022 12:12
Maven and javax.annotation.processing.Messager NOTE messages.
import javax.annotation.processing.SupportedOptions;
@SupportedOptions("debug") // declare the `debug` option
public final class InYourProcessor extends AbstractProcessor {
/**
* This is now your logging routine.
*/
private void log(String msg) {
if (processingEnv.getOptions().containsKey("debug")) {