Skip to content

Instantly share code, notes, and snippets.

View geowarin's full-sized avatar

Geoffroy Warin geowarin

View GitHub Profile
@geowarin
geowarin / CompletableExecutors.java
Created June 12, 2015 18:34
ExecutorService that handles CompletableFutures
package completable.async;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;
import static java.util.concurrent.Executors.callable;
/**
@geowarin
geowarin / gh-create-repo.fish
Created May 9, 2015 00:12
Publish the current repository to github with fish shell and httpie
function gh-create-repo
if not is_installed http
echo "Please install httpie"
return 1
end
set -l username (git config --global user.name)
echo -n "Enter password for $username : "
stty -echo
@geowarin
geowarin / are_installed.fish
Created May 9, 2015 00:02
Utility functions to see if binaries are found in path with fish shell
function are_installed
for cmd in $argv;
is_installed $cmd
end
end
@geowarin
geowarin / gh-gist.fish
Last active August 29, 2015 14:20
Publish files as gists with fish shell
function gh-gist
if not are_installed http jq
echo "Please install httpie and jq"
return 1
end
set -l username (git config --global user.name)
echo -n "Enter password for $username : "
stty -echo
@geowarin
geowarin / ProxyUtils.java
Created May 7, 2015 17:49
Get the object behind a Spring proxy
package masterspringmvc4.utils;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
public class ProxyUtils {
public static <T> T getProxyTarget(Object proxy) {
if (!AopUtils.isAopProxy(proxy)) {
throw new IllegalStateException("Target must be a proxy");
@geowarin
geowarin / gsub.js
Last active March 2, 2017 19:04 — forked from varunkumar/JS gsub
Javascript implementation of ruby gsub
String.prototype.gsub = function (pattern, replacement) {
var match, result, source = this.toString();
if (pattern == null || replacement == null) {
return source;
}
result = '';
while (match = source.match(pattern)) {
result += source.slice(0, match.index);
result += typeof replacement === 'function' ? replacement(match[0]) : replacement;
source = source.slice(match.index + match[0].length);
@geowarin
geowarin / blanketHtmlReporter.js
Last active August 29, 2015 14:12
Blanket and mocha reporters to enable generation of a html report when doing in browser testing with phantomjs
/**
* Author: Geoffroy Warin (http://geowarin.github.io)
*
* Reporter for blanket. Outputs the coverage html to the console.
* This is basically a copy of https://github.com/alex-seville/blanket/blob/master/src/qunit/reporter.js
* with a few adaptations
*/
(function (){
var reporter = function(coverage){
var cssSytle = "#blanket-main {margin:2px;background:#EEE;color:#333;clear:both;font-family:'Helvetica Neue Light', 'HelveticaNeue-Light', 'Helvetica Neue', Calibri, Helvetica, Arial, sans-serif; font-size:17px;} #blanket-main a {color:#333;text-decoration:none;} #blanket-main a:hover {text-decoration:underline;} .blanket {margin:0;padding:5px;clear:both;border-bottom: 1px solid #FFFFFF;} .bl-error {color:red;}.bl-success {color:#5E7D00;} .bl-file{width:auto;} .bl-cl{float:left;} .blanket div.rs {margin-left:50px; width:150px; float:right} .bl-nb {padding-right:10px;} #blanket-main a.bl-logo {color: #EB1764;cursor: pointer;font-weight: bold;text-decoration: none} .bl-source{ overflow-x:scro
@Grapes(
@Grab(group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.7.1')
)
import groovyx.net.http.RESTClient
def etcd = new Etcd()
def onSet = { node, previous ->
println "set $node"
}
@geowarin
geowarin / groovy-logger.groovy
Created November 23, 2014 11:50
How to redirect command output to log4j in a groovy script
#!/usr/bin/env groovy
@Grapes(
@Grab('log4j:log4j:1.2.17')
)
import org.apache.log4j.Level
import org.apache.log4j.Logger
def redirectLog = { Level level ->
return { String s ->
if (s.trim())
@geowarin
geowarin / template.groovy
Last active August 29, 2015 14:10
Power Template® by geowarin. Use the power of groovy to templatize a file.
#!/usr/bin/env groovy
import groovy.json.JsonSlurper
import groovy.text.SimpleTemplateEngine
import org.apache.commons.cli.HelpFormatter
def template = new PowerTemplate()
template.parseOptions(args)
template.run()
class PowerTemplate {