Skip to content

Instantly share code, notes, and snippets.

View dahernan's full-sized avatar

David Hernandez dahernan

View GitHub Profile
package main
import (
"encoding/json"
"github.com/bmizerany/pat"
"log"
"net/http"
)
type httpHandlerFunc func(w http.ResponseWriter, req *http.Request)
package main
import (
"github.com/bmizerany/assert"
"net/http"
"net/http/httptest"
"testing"
)
func TestJsonServerReturnsJsonDocumentWithRightHeaders(t *testing.T) {
@dahernan
dahernan / gist:2820065
Created May 28, 2012 16:51
Filter a list
// old filter
List<WhiteListKeyword> filtered = new ArrayList<WhiteListKeyword>();
for (WhiteListKeyword whiteListKeyword : whiteListKeywords) {
if(keyword.equals()){
filtered.add(whiteListKeyword.getKeyword());
}
}
@dahernan
dahernan / gist:2820052
Created May 28, 2012 16:43
Local Cache
// Simple cache
private ConcurrentHashMap<String, String> cache;
String resource = cache.get(url.toString());
...
// Guava
@dahernan
dahernan / increase_pom.groovy
Created April 24, 2012 09:19
Groovy XML pom manipulation
/*
Script to increase the version number of the project and remove snapshots
Using Gmaven: http://docs.codehaus.org/display/GMAVEN/Executing+Groovy+Code
Execute standalone
$ mvn groovy:execute
<plugin>
<groupId>org.codehaus.gmaven</groupId>
@dahernan
dahernan / CharMatcher.java
Created August 15, 2011 11:51
CharMatcher example
package testting.testinggggg;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
@dahernan
dahernan / certificateKeytool.txt
Created August 10, 2011 09:11
generate self signed certificate with keytool
To generate a self-signed SSL certificate using the keytool command on Windows, Mac, or Linux:
1 Open a command prompt or terminal.
2 Run this command:
keytool -genkey -keyalg RSA -alias tomcat -keystore selfsigned.jks -validity <days> -keysize 2048
Where <days> indicate the number of days for which the certificate will be valid.
3 Enter a password for the keystore. Note this password as you require this for configuring the server.
Bash funtions
function psgrep() { ps aux | grep -v grep | grep "$@" -i --color=auto; }
function fname() { find . -iname "*$@*"; }
Who is using the port 25
$ lsof -i :25
Ports that process is using
$ lsof -p 52808|grep TCP
@dahernan
dahernan / sshExec
Created March 28, 2011 16:02
Exec ssh command passing the password as a parameter
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 2]
set arg1 [lrange $argv 3 c3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh root@$ipaddr $scriptname $arg1
match_max 100000
expect -timeout 4 "yes/no" {send "yes\r"}
@dahernan
dahernan / rabbitmqinject.groovy
Created March 9, 2011 14:59
rabbitmqinject.groovy
import com.rabbitmq.client.*
import java.util.Random
@Grab(group='com.rabbitmq', module='amqp-client', version='1.7.2')
params = new ConnectionParameters(
username: 'guest',
password: 'guest',
virtualHost: '/',
requestedHeartbeat: 0
)