Skip to content

Instantly share code, notes, and snippets.

View electrum's full-sized avatar
🚀
Working on @trinodb

David Phillips electrum

🚀
Working on @trinodb
View GitHub Profile
@electrum
electrum / gist:4035227
Created November 7, 2012 23:09
GIT_SSH wrapper for Jenkins and GitHub
#!/usr/bin/env python
import re, os, os.path, sys
HOST = '[email protected]'
KEYS = '/data/users/jenkins/home/.ssh'
if len(sys.argv) != 3:
sys.stderr.write('usage: git-ssh host command\n')
sys.exit(100)
@electrum
electrum / gist:4004609
Created November 2, 2012 22:02
sshretry
#!/bin/sh -eu
while true
do
ssh -o ServerAliveInterval=10 "$@" && exit
sleep 5
done
@electrum
electrum / gist:3894720
Created October 15, 2012 19:33
Airlift DataSize approximateSize
public static DataSize approximateSize(long bytes)
{
DataSize size = new DataSize(bytes, DataSize.Unit.BYTE);
size = size.convertToMostSuccinctDataSize();
return new DataSize(size.roundTo(size.getUnit()), size.getUnit());
}
@electrum
electrum / gist:3868639
Created October 10, 2012 21:42
Run command under Java 6 on Mac OS X
#!/bin/sh -eu
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
export PATH=$JAVA_HOME/bin:$PATH
exec "$@"
@electrum
electrum / test1.txt
Created October 10, 2012 03:45
PHP destructors with cycles
PHP 5.3.15 (cli) (Aug 24 2012 17:40:23) [Darwin]
>>> class Foo { public $x; function __destruct() { echo "destroy\n"; var_dump($this); } }
>>> $a = new Foo(); $b = new Foo(); $a->x = $b; $b->x = $a; unset($a); unset($b);
>>> gc_collect_cycles()
destroy
object(Foo)#2 (1) {
["x"]=>
object(Foo)#1 (1) {
["x"]=>
*RECURSION*
package javatest;
import com.google.common.base.*;
import java.util.Arrays;
public enum RecursiveEnum
{
FOO(null),
BAR(FOO);
@electrum
electrum / gist:3456269
Created August 24, 2012 22:06
Guava Objects.toStringHelper template for IntelliJ IDEA
public String toString() {
#set ($autoImportPackages = "com.google.common.base.Objects")
return Objects.toStringHelper(this)
#foreach ($member in $members)
.add("$member.name", $member.accessor)
#end
.toString();
}
@electrum
electrum / javadoc.user.js
Created August 21, 2012 22:54
Latest Javadoc Redirect
// ==UserScript==
// @name Latest Javadoc Redirect
// @match http://docs.oracle.com/javase/*/api/*
// ==/UserScript==
(function() {
var oldVersions = ['1.3', '1.4.2', '1.5.0', '1,5.0', '6'];
var newVersion = '7';
var url = window.location.toString();
for (var i = 0; i < oldVersions.length; i++) {
@electrum
electrum / gist:3166968
Created July 23, 2012 23:46
Java Find Matching Files
private static List<Path> listMatchingFiles(Path start, String glob)
throws IOException
{
final ImmutableList.Builder<Path> list = ImmutableList.builder();
final PathMatcher matcher = start.getFileSystem().getPathMatcher("glob:" + glob);
Files.walkFileTree(start, new SimpleFileVisitor<Path>()
{
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException
@electrum
electrum / S3Location.java
Created June 29, 2012 01:33
AWS S3Location
import com.amazonaws.AmazonClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.google.common.collect.ImmutableList;
import com.google.common.io.InputSupplier;
import java.io.IOException;
import java.io.InputStream;