Skip to content

Instantly share code, notes, and snippets.

public class DeadlockTest
{
public static void main(String[] args)
{
final Foo a = new Foo();
final Foo b = new Foo();
new Thread(new Runnable()
{
@eribeiro
eribeiro / gource-ffmpeg.sh
Last active February 11, 2022 16:23
Run Gource on a git repo, outputs as a movie (movie.mp4) and compresses it (output.mp4)
gource -s .06 -1280x720 --auto-skip-seconds .1 --multi-sampling --stop-at-end --key --highlight-users --hide mouse,progress,files,filenames,dirnames --file-idle-time 0 --max-files 0 --background-colour 000000 --font-size 22 --title "Lucene/Solr" --output-ppm-stream - --output-framerate 30 | avconv -y -r 30 -f image2pipe -vcodec ppm -i - -b 65536K movie.mp4
&& ffmpeg -i movie.mp4 -b:v 3048780 -vcodec libx264 -crf 24 output.mp4
@eribeiro
eribeiro / git-pull.sh
Created August 18, 2015 17:06
Does a git pull origin on each sub-directory of where the script is located.
#!/bin/bash
for i in `ls -d */`; do
echo "updating $i"
cd $i
if [ -d ".git" ]; then
git pull origin
fi
cd -
done
import com.datastax.driver.core.*;
import java.util.Arrays;
import java.util.UUID;
// create keyspace test with replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
// create table t2 (id uuid primary key, value list<text>);
public class CassandraTest {
public static void main(String[] args)
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
val top = new TopK()
for ( i <- 1 to 10 ) top.insert(i)
for (i <- 10 to 0 by -1) top.insert(i)
class TopK {
private val K = 10
private val values = new Array[Long](K)
private var size = 0
def insert(item: Long) = {
if (size < K) {
values(size) = item
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@eribeiro
eribeiro / weakref-snippet.java
Last active January 5, 2017 14:34
If you are using a *WeakHashMap* and your keys are boxed primitive types like, for example, an Integer with value 10, then you should *NOT* use "Integer.valueOf(10)" or even rely on autoboxing -- e.g., map.put(10, "blabla") -- to populate the keys of this map. REASON: both ".valueOf()" and autoboxing do a *caching* of primitive values (up to a t…
WeakHashMap<Integer, String> map = new WeakHashMap<Integer, String>();
map.put(new Integer(10), "aaa"); // remove entry
// map.put(10, "aaa"); // don't remove entry
// map.put(Integer.valueOf(10), "aaa"); // don't remove entry
for (int i = 0; i < Integer.MAX_VALUE; i++) {
if (map.size() != 0) {
System.out.println("At iteration " + i + " the map still holds the reference to object");
} else {
@eribeiro
eribeiro / quotes.txt
Created December 10, 2013 19:18
Programming Quotes
1. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”
- C.A.R. Hoare (British computer scientist, winner of the 1980 Turing Award)
2. “If debugging is the process of removing software bugs, then programming must be the process of putting them in.”
- Edsger Dijkstra (Dutch computer scientist, winner of the 1972 Turing Award)
3. “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”
- Bill Gates (co-founder of Microsoft)
4. “Nine people can’t make a baby in a month.” (regarding the addition of more programmers to get a project completed faster)