Skip to content

Instantly share code, notes, and snippets.

View dgageot's full-sized avatar

David Gageot dgageot

View GitHub Profile
import static java.nio.charset.StandardCharsets.*;
import static javax.script.ScriptContext.*;
import java.io.*;
import net.codestory.http.io.*;
import javax.script.*;
public class CoffeeToJs {
@dgageot
dgageot / TestThreads.java
Created December 17, 2013 16:28
Thread hell
package net.gageot;
import java.util.*;
import java.util.concurrent.*;
public class TestThreads {
public static final int NB = 100000;
public static void main(String[] args) {
@dgageot
dgageot / Fluent.java
Created September 13, 2013 08:05
Iterables, Streams and Arrays, the new best friends
package net.gageot.listmaker;
import static java.util.Objects.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
import javax.annotation.*;
@dgageot
dgageot / convert.sh
Created July 9, 2013 13:55
Auto reload browser when a doc file is saved
#!/bin/sh
echo 'Convert .doc to .html'
# Convert
for file in *.doc ;do
asciidoc $file
done
# Add auto-reload js
for file in *.html ;do
@dgageot
dgageot / Types.java
Created June 22, 2013 08:57
Oops, a Lambda tends to forget what's its type.
public class Types {
interface SMI<T> {
T get(T value);
}
public static void main(String[] args) {
SMI<String> inner = new SMI<String>() {
@Override
public String get(String param) {
@dgageot
dgageot / FooFooLambdaWtf.java
Created June 20, 2013 10:27
A FooBar style WTF? using Java8 lambdas
import java.util.stream.*;
public class FooFooLambdaWtf {
public static void main(String[] args) {
// prints FooBar
String fooBar = IntStream.range(1, 10).mapToObj(FooFooLambdaWtf::foorBar).collect(Collectors.joining());
System.out.println(fooBar);
// prints FooFooFooFooFooFooFooFooFoo
String fooFooFoo = IntStream.range(1, 10).mapToObj(i -> (i == 3) ? "Foo" : (i == 5) ? "Bar" : "").collect(Collectors.joining());
@dgageot
dgageot / TestMockito.java
Last active March 3, 2017 11:08
Mockito and java8
import static org.mockito.Mockito.*;
import java.util.concurrent.*;
import org.junit.*;
import org.mockito.*;
import org.mockito.stubbing.*;
public class TestMockito {
@Test
def next_syracuse(n)
return n/2 if n.even?
3*n+1
end
def syracuse(n)
etapes = [n]
while etapes.last != 1
etapes << next_syracuse(etapes.last)
end
@dgageot
dgageot / SEOFilter.java
Created February 15, 2013 14:27
Jersey Filter *Prototype* that uses PhantomJS to retrieve pages asked by Googlebot. This way the javascript is interpreted by phantomjs and it provides a static webpage to Google.
package main;
import com.google.common.base.Strings;
import com.google.common.io.ByteStreams;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@dgageot
dgageot / PhantomJsDownloader.java
Last active May 28, 2019 17:40
PhantomJs / GhostDriver / FluentLenium with automatic install of PhantomJs
package com.fractales.synchro.helpers.phantomjs;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.io.OutputSupplier;
import com.google.common.io.Resources;
import java.io.File;
import java.io.FileOutputStream;