Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / Secret.java
Created May 23, 2015 09:57
Clearing a Java String
import java.lang.reflect.Field;
import java.io.Console;
public class Secret {
public static void main(String[] args) throws Exception {
Console console = System.console();
String secret = console.readLine("secret: ");
System.out.println("Capture secret in heap");
@esamson
esamson / Dockerfile
Created March 6, 2015 07:27
Dockerfile for a Vagrant ready image. Kinda works but getting permission denied errors in the synced folder (e.g., `/vagrant`).
FROM centos:7
RUN yum install -y openssh-server openssh-clients sudo
RUN yum clean all
RUN sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -i "s/Defaults requiretty.*/#Defaults requiretty/g" /etc/sudoers
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
RUN useradd vagrant
@esamson
esamson / purge.sh
Last active August 29, 2015 14:16 — forked from adrienbrault/purge.sh
#!/bin/sh
# Credits to:
# - http://vstone.eu/reducing-vagrant-box-size/
# - https://github.com/mitchellh/vagrant/issues/343
aptitude -y purge ri
aptitude -y purge installation-report landscape-common wireless-tools wpasupplicant ubuntu-serverguide
aptitude -y purge python-dbus libnl1 python-smartpm python-twisted-core libiw30
aptitude -y purge python-twisted-bin libdbus-glib-1-2 python-pexpect python-pycurl python-serial python-gobject python-pam python-openssl libffi5
@esamson
esamson / current-workspace-only.sh
Created February 20, 2015 03:08
Set Gnome 3 app switcher to only consider the current workspace
gsettings set org.gnome.shell.app-switcher current-workspace-only true
@esamson
esamson / opendj
Created February 19, 2015 09:33
OpenDJ subcommands -- instead of adding everything to your PATH
#!/bin/bash
OPENDJ_HOME=~/.local/opt/opendj
if [ -z "$1" ] ; then
echo "Usage: $0 <command>"
echo
echo "Where <command> is one of:"
echo
ls -1 $OPENDJ_HOME/bin