Skip to content

Instantly share code, notes, and snippets.

import static java.util.Arrays.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class Pizza {
public static void main(String[] args) {
public class Casting {
public static void main(String[] args) {
// Those below are objects that get autoboxed automatically
Integer i = 0;
Long l = 0L;
Double d = 0D;
Float f;
Float f2 = 1f;
@eribeiro
eribeiro / scala-mutable-hashmap-retain
Created July 14, 2012 20:07
Filtering out elements of a mutable HashMap in Scala by means of retain()
val map = scala.collection.mutable.HashMap[String,Int]()
// populating the Map
Range(1,10).foreach(x => map.put(x.toString, x))
//removing all odd elements
map retain {(key,value) => value % 2 == 0}
@eribeiro
eribeiro / twitter-commons-zookeeper.sh
Created August 3, 2012 16:14
How to build twitter:commons zookeeper
testing:
$ ./pants src/java/com/twitter/common/zookeeper:client
$ ./pants src/java/com/twitter/common/zookeeper:node
$ ./pants src/java/com/twitter/common/zookeeper:map
$ ./pants src/java/com/twitter/common/zookeeper:group
$ ./pants src/java/com/twitter/common/zookeeper:partitioner
$ ./pants src/java/com/twitter/common/zookeeper:candidate
$ ./pants src/java/com/twitter/common/zookeeper:lock
$ ./pants src/java/com/twitter/common/zookeeper:server-set
$ ./pants src/java/com/twitter/common/zookeeper:singleton-service
@eribeiro
eribeiro / twitter-commons-zookeeper-libs.sh
Created August 3, 2012 16:17
twitter-commons-zookeeper-libs
$ for t in `pants list src/java/com/twitter/common/zookeeper`; do echo && pants depmap -im $t | grep zookeeper; done
com.twitter.common.zookeeper-client
com.twitter.common.zookeeper-node
com.twitter.common.zookeeper-client
com.twitter.common.zookeeper-map
@eribeiro
eribeiro / mp4png.sh
Created August 9, 2012 17:03
Extract PNG frames from mp4 video
#!/bin/bash
# A command to extract PNG files from a MP4 video
# Write out 200 png format frames from video starting at 4 minutes, 40 seconds.
mplayer -vo png -ss 04:40 -frames 200 dvvideo.mp4
@eribeiro
eribeiro / wma2mp3.py
Created August 9, 2012 17:04
Convert a WMA file into MP3
#!/usr/bin/python
# This script converts a WMA file into a MP3 file.
# Requisites: mplayer e lame
# Disclaimer: it worked last time I checked, but it was a long time ago,
# so I put it here just to reference. Use it at your own risk.
import os
list = os.listdir(".")
@eribeiro
eribeiro / color-git.sh
Created August 9, 2012 17:56
Color Git
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
PS1='\[\033[01;37m\]\w\[\033[00;35m\]$(parse_git_branch)\[\033[00m\] \$ '
@eribeiro
eribeiro / rm-svn.sh
Created August 17, 2012 03:22
Recursively remove .svn files from a directory tree
# Remove all the .svn directories below the current directory tree
# Credit: Zed Shaw, at the Mongrel mailing list.
#!/bin/bash
find . -name ".svn" -exec rm -rf {} \;
@eribeiro
eribeiro / mark-del.sh
Created August 17, 2012 03:24
Mark files that were manually deleted as deleted by SVN
# Register all files that were manually delete on SVN as deleted (sync)
#!/bin/bash
svn status | grep "^\!" | sed 's/^\! *//g' | xargs svn rm