Skip to content

Instantly share code, notes, and snippets.

@philz
philz / gist:6444491
Created September 5, 2013 00:18
Inefficient mechanism to find slow Surefire-executed tests. keywords: maven surefire test duration time
$paste <(xpath -q -e '//testcase/@name' $(find . -name 'TEST-*.xml') ) <(xpath -q -e '//testcase/@classname' $(find . -name 'TEST-*.xml') ) <(xpath -q -e '//testcase/@time' $(find . -name 'TEST-*.xml') ) | tr '=' ' ' | tr -d '"' | awk '{ print $6, $4, $2 }' | sort -n > testtimes
@philz
philz / gist:6405044
Created September 1, 2013 15:13
Expand RPM packages
for x in *.rpm; do mkdir ${x%%.rpm}; cd ${x%%.rpm}; rpm2cpio ../$x | cpio -idmv; cd ..; done
@philz
philz / gist:6393825
Created August 30, 2013 20:11
git-above
# License: Public Domain
#
# Usage: git-above [ref]
#
# ref defaults to "origin/master" if not specified.
#
# Returns the commit directly after that commit. Useful for pushing
# the "bottom" of your stack of changes above master.
#
# Is there a better way?
@philz
philz / TernaryBoxing.java
Created August 13, 2013 22:24
Ternary Boxing -- Java Puzzler -- What does this print?
// License: Public Domain
//
// Java Puzzler: what does this print?
public class TernaryBoxing {
public static void main(String[] args) {
Long nullLong = null;
try {
takesLong(true ? nullLong : 1);
} catch (NullPointerException e) {
System.out.println("1");
@philz
philz / gist:6159293
Created August 5, 2013 20:25
Close your open review board requests
for x in $(curl 'http://reviewboard/api/review-requests/?status=pending&from-user=philip&last-updated-to=2013-06-01' | jsonpipe | grep links/self/href | awk '{ print $2 }' | grep -v pending | tr -d \"); do
curl -u "philip:$(cat /tmp/pass)" -v -XPUT $x -Fstatus=submitted;
done
# License: Public Domain
$crontab -l
#6 * * * * /home/philip/bin/reservation.sh
###########################################################################
$cat bin/reservation.sh
#!/bin/sh
if curl -s http://rez.urbanspoon.com/reservation/start/2086 | grep -q 'Unfortunately'; then
exit
@philz
philz / gist:5631456
Last active December 17, 2015 15:28
Using sqlite3 to analyze two jmap heap histograms. Using SQL is a powerful way to query and compare two data sets, like the output of jmap.
jmap -histo:live $pid > old.jmap
sleep $((60*60))
jmap -histo:live $pid > new.jmap
cat old.jmap | awk 'BEGIN { OFS="|" } /:/ { print $2, $3, $4 }' > old.txt
cat new.jmap | awk 'BEGIN { OFS="|" } /:/ { print $2, $3, $4 }' > new.txt
sqlite3
sqlite> create table new(count, bytes, class);
sqlite> create table old(count, bytes, class);
sqlite> .import new.txt "new";
sqlite> .import old.txt "old";
@philz
philz / gist:5605978
Created May 18, 2013 22:33
Processes with the largest ratio of virtual memory size to resident size.
ps hax -o rss,vsz,command | awk '{ if ($1 > 0) { print $2/$1, $3 } }' | sort -n | tail
@philz
philz / gist:5355729
Created April 10, 2013 15:39
Query impala directly from Python. Note that doesn't do things like query cancellation that impala-shell actually does.
#!/usr/bin/python
# Apache License
#
# $python impala.py 'select "hello", "there"'
# ['hello\tthere']
import sys
import os
@philz
philz / gist:5305400
Created April 3, 2013 21:17
Executing a shell script via MR.
hadoop jar /usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.3.0-SNAPSHOT.jar -input /user/philip/single_line -output $(mktemp) -mapper 'touch /tmp/philip_was_here' -jobconf mapred.reduce.tasks=0 -jobconf mapred.map.tasks=0