Skip to content

Instantly share code, notes, and snippets.

View dgageot's full-sized avatar

David Gageot dgageot

View GitHub Profile
@dgageot
dgageot / FindParametersTypes.java
Created August 19, 2014 10:05
Find Lambda parameter types with serialization. Works only on serializable lambda
package avaj.lang.invoke;
import java.io.*;
import java.lang.invoke.SerializedLambda;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
public class FindParametersTypes {
public static void main(String[] args) throws Exception {
System.out.println(getMethodSignature((String s) -> s));
@dgageot
dgageot / fluentHttp.groovy
Created June 9, 2015 16:40
fluent-http Groovy Style
import net.codestory.http.WebServer
@Grab(group='net.code-story', module='http', version='2.98')
def startWebServer() {
new WebServer()
.configure {routes -> routes.anyGet {ctx -> "Hello"}}
.start()
}
startWebServer()
#!/bin/sh
# Pre-commit hook that crushes PNG files in order to reduce their size.
if ! which -s pngcrush
then
echo "Please install pngcrush to reduce png images size before commit"
exit 1;
fi
for file in `git diff --cached --name-only | grep ".png\$"`
#!/bin/sh
PWD=`pwd`
CURRENT=`grep "<version>" -i pom.xml --max-count 1 | sed -e "s/.*<version>\(.*\)<\/version>/\1/" | sed -e "s/-SNAPSHOT//"`
MAJOR_VERSION=`echo $CURRENT | sed -e "s/\([0-9]*\.[0-9]*\.\)\([0-9]*\)/\1/"`
MINOR_VERSION=`echo $CURRENT | sed -e "s/\([0-9]*\.[0-9]*\.\)\([0-9]*\)/\2/"`
NEXT=$MAJOR_VERSION`expr $MINOR_VERSION + 1`-SNAPSHOT
TAG=VERSION$CURRENT
echo "=== RELEASING $CURRENT ==="
#!/bin/bash
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
if [ 0 -eq `git remote -v | grep -c push` ]; then
REMOTE_REPO=`git remote -v | sed 's/origin//'`
else
REMOTE_REPO=`git remote -v | grep "(push)" | sed 's/origin//' | sed 's/(push)//'`
git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --name-only | awk -F ';' '{printf "%s %-28s %30-s %s\\n",$1,$2,$3,$4}'
git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub("SHA1: ", ""); print}'
package com.algodeal.test.rules;
import static com.algodeal.test.rules.ConsoleRecorder.ConsoleType.*;
import java.io.*;
import org.junit.rules.ExternalResource;
/**
* JUnit Rule to record System.out or System.err output.
*/
public class ConsoleRecorder extends ExternalResource {
#!/bin/bash
LAST=$(date -j "+%Y-%m-%d")
FIRST=$(date -j -f "%Y-%m-%d" 2008-10-01 "+%Y-%m-%d")
CURRENT=${LAST}
git reset -q --hard origin/master; git clean -q -xdf
echo "Date;Lines of code;Lines of test"
foldingFunction=method(sum, x,
case(x,
"+", [sum pop! + sum pop!],
"*", [sum pop! * sum pop!],
"-", [sum pop! - sum pop!],
"/", [sum pop! / sum pop!],
[x toRational]
) + sum
)
"8 1 2 + 5 * +" split fold([], sum, x, foldingFunction(sum, x)) println