Skip to content

Instantly share code, notes, and snippets.

@shenie
shenie / getStackTraceAsString.java
Created August 14, 2008 13:57 — forked from fuzzylizard/getStackTraceAsString.java
Return stack trace as string
public static String getStackTraceAsString(Exception e) {
StringWriter stackTrace = new StringWriter();
e.printStackTrace(new PrintWriter(stackTrace));
return stackTrace.toString();
}
@shenie
shenie / YamlDumper.java
Created August 15, 2008 13:23
yaml dumper using jyaml lib
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.log4j.Logger;
import org.ho.yaml.Yaml;
public class YamlDumper {
private static final Logger LOG = Logger.getLogger(YamlDumper.class);
private final Object object;
public YamlDumper(Object object) {
import org.junit.Assert;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class MapReduce<V, T> {
private Collection<V> collection;
@shenie
shenie / download_sources.sh
Created November 26, 2009 05:40
Download sources from maven
#!/bin/bash
prefix="http://mirrors.ibiblio.org/pub/mirrors/maven2"
header="/tmp/$0.header.$$"
find . -name "*.jar" -and ! -name "*sources.jar" | grep -v "siteminder" | \
while read j
do
source_jar=$(echo $j | sed -e's/.jar/-sources.jar/')
@shenie
shenie / Readme.md
Created January 27, 2010 06:01
tab-fu

This script will open a new Terminal tab at the current directory or another directory relative to the current directory. Assuming tab.sh is somewhere in your PATH. For example I saved it in my ~/bin then you can just do:

tab.sh

tab.sh ../another_project

public List<String> glom(String...a) {
Stack<String> stack = new Stack<String>();
stack.push("");
for (String s : a) {
if (s != "") {
stack.push(stack.pop() + s);
} else {
if (stack.peek() != "") {
stack.push("");
@shenie
shenie / glom.java
Created January 29, 2010 20:08
dhanji take 2
public void _glom(Stack<String> stack, String...a) {
if (a.length == 0) {
if (stack.peek() == "") {
stack.pop();
}
return;
}
String s = a[0];
if (s != "") {
@shenie
shenie / itunes.markdown
Created January 31, 2010 07:38
iTunes applescript
osascript -e 'tell app "iTunes" to set sound volume to sound volume +20'
osascript -e 'tell app "iTunes" to next track'
osascript -e 'tell app "iTunes" to previous track'
osascript -e 'tell app "iTunes" to playpause'
osascript -e 'tell app "iTunes" to play'
osascript -e 'tell app "iTunes" to pause'
osascript -e 'tell application "iTunes" to return name of current track'
osascript -e 'tell application "iTunes" to set song repeat of current playlist to one'
osascript -e 'tell application "iTunes" to set shuffle of current playlist to not shuffle of current playlist'
public String convertToString(GPathResult doc) {
def defaultNamespace = doc.lookupNamespace('')
if (defaultNamespace) {
def docWithNamespace = {
mkp.declareNamespace("": defaultNamespace)
out << doc
}
return new StreamingMarkupBuilder().bind(docWithNamespace)
} else {
// Written for Advanced Scraping (http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga)
// by David Trejo
//
// Install node.js and npm:
// http://joyeur.com/2010/12/10/installing-node-and-npm/
// Then run
// npm install jsdom jquery http-agent
// node numresults.js
//
var util = require('util')