Skip to content

Instantly share code, notes, and snippets.

View ggtools's full-sized avatar

Christophe Labouisse ggtools

View GitHub Profile
#!/usr/bin/perl
use strict;
use Data::Dumper;
my $initialNumber = 0;
$initialNumber += $_ for map { ord($_) } split //, shift || die "No word supplied";
my ( $tempVol, $volEnAltitude, $altitudeMax, $descendu );
my $number = $initialNumber;
my @sequence;
@ggtools
ggtools / ScalaskelResolver.java
Last active December 12, 2015 01:18
CodeStory 2013 : l'échoppe de monade sur Scalaskel en Java
private static void addToChange(COIN currentCoin, int value, Map<COIN, Integer> changeMap) {
if (value != 0) {
changeMap.put(currentCoin, value);
}
}
// Méthode principale on l'appelle avec computeChange(COIN.baz, value) afin en commençant donc par la plus grosse
// pièce.
public List<Map<COIN, Integer>> computeChange(COIN currentCoin, int value) {
if (currentCoin.getValue() == 1) {
@ggtools
ggtools / CalculatorResolver.java
Created February 1, 2013 07:13
CodeStory 2013: Calculateur
public String solve(HttpServletRequest request) throws ResolverException {
String q = request.getParameter("q");
if (q == null) return null;
String expr = q.replace(',', '.').replaceAll(" ", "+");
try {
GroovyShell shell = new GroovyShell();
Object evalResult = shell.evaluate(expr);
Object result;
@ggtools
ggtools / LoopWTF.java
Created February 22, 2012 13:39
WTF: "Improved" enhanced for loop
for(Entity entity: entityList) {
entityList.get(entityList.indexOf(entity)).performOp();
}
@ggtools
ggtools / readIniSection.sh
Created January 29, 2012 00:06
Parse .ini file
# Reads a section of the ini file and put the results in variables prefixed by the supplied prefix.
readIniSection() {
local PREFIX="$1"
local SECTION="${2-main}"
# Neat way to parse the ini section from CONFIG_FILE
# shamelessly taken from http://www.tuxz.net/blog/
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/;.*$//' \
-e 's/[[:space:]]*$//' \

Keybase proof

I hereby claim:

  • I am ggtools on github.
  • I am clabouisse (https://keybase.io/clabouisse) on keybase.
  • I have a public key whose fingerprint is AF03 78CE 6C5A F3C4 6C51 E7CE FB49 83B4 1AD2 5EC7

To claim this, I am signing this object:

@ggtools
ggtools / TestMongoConfig.java
Created October 7, 2014 06:51
A Spring configuration to use an embedded MongoDB during tests
@Configuration
public class TestMongoConfig {
private static final MongodStarter starter = MongodStarter.getDefaultInstance();
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
private MongoProperties properties;
@Autowired(required = false)
private MongoClientOptions options;
@ggtools
ggtools / end-of-build
Created June 18, 2014 07:11
Differences between ls -al at the end of the build and when running the image in a container
tep 17 : RUN whoami
---> Running in 3240a56670c9
restx
---> f80416f3ec29
Error removing intermediate container 7ec7bc8a9760: The given container is <nil>
Removing intermediate container 3240a56670c9
Step 18 : RUN ls -al ${HOME}
---> Running in efd468ae1f51
total 12
drwxr-xr-x 1 restx restx 76 Jun 18 06:56 .
@ggtools
ggtools / VideoHttpMessageConverter.java
Created June 5, 2014 11:14
HttpMessageConverter handling video streams
public class VideoHttpMessageConverter extends AbstractHttpMessageConverter {
public VideoHttpMessageConverter() {
super(new MediaType("video", "mp4"));
}
@Override
protected boolean supports(Class clazz) {
return InputStream.class.isAssignableFrom(clazz) || File.class.isAssignableFrom(clazz);
}
@ggtools
ggtools / GetVideoRoute.java
Created June 4, 2014 21:55
Restx Router to handle GET on a video stream
public class GetVideoRoute extends StdEntityRoute<Void, InputStream> {
private final VideoResource videoResource;
public GetVideoRoute(EntityRequestBodyReaderRegistry readerRegistry, VideoResource videoResource) {
super("Get Video Route",
readerRegistry.<Void>build(Void.class, Optional.<String>absent()),
new AbstractEntityResponseWriter<InputStream>(OutputStream.class, "video/mp4") {
@Override
protected void write(InputStream value, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException {
try {