Skip to content

Instantly share code, notes, and snippets.

Avatar

Guillaume Laforge glaforge

View GitHub Profile
View piapprox.groovy
import groovy.transform.*
import groovyx.gpars.actor.*
import groovyx.gpars.group.*
@Immutable class Calculate {}
@Immutable class Work { int start, nrOfElements }
@Immutable class Result { double value }
@Immutable class PiApproximation { double pi ; long duration }
double calculatePiFor( int start, int nrOfElements ) {
@glaforge
glaforge / LongAdderTest.groovy
Last active Aug 29, 2015 — forked from timyates/LongAdderTest.java
Tim's long adder test with streams but groovier :-)
View LongAdderTest.groovy
import java.util.Random
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.LongAdder
import java.util.stream.IntStream
def frequencyMap = new ConcurrentHashMap<>()
def rnd = new Random()
IntStream.range( 0, 10000 )
.parallel()
@glaforge
glaforge / gist:e1d88601c053611678ae
Created Jul 1, 2014
List of some of the Netflix Groovy-related jobs
View gist:e1d88601c053611678ae
http://jobs.netflix.com/jobs.php?id=NFX01044
http://jobs.netflix.com/jobs.php?id=NFX00979
http://jobs.netflix.com/jobs.php?id=NFX01209
http://jobs.netflix.com/jobs.php?id=NFX01033
http://jobs.netflix.com/jobs.php?id=NFX01176
http://jobs.netflix.com/jobs.php?id=NFX01123
http://jobs.netflix.com/jobs.php?id=NFX01428
http://jobs.netflix.com/jobs.php?id=NFX00586
http://jobs.netflix.com/jobs.php?id=NFX01393
View gist:d0c13fd995abaf4f7a4b
### Keybase proof
I hereby claim:
* I am glaforge on github.
* I am glaforge (https://keybase.io/glaforge) on keybase.
* I have a public key whose fingerprint is C85A BAF0 7611 7C9D ACAD 94D1 5534 CABE 8D9C 5BD2
To claim this, I am signing this object:
@glaforge
glaforge / groovyCoffee.groovy
Created Oct 15, 2014
Calling @netopyr's CoffeeScript javax.script engine from Groovy with @grab
View groovyCoffee.groovy
@Grab('com.netopyr.coffee4java:coffee4java:1.0.0')
import javax.script.ScriptEngineManager
def coffeescript = new ScriptEngineManager().getEngineByName('coffeescript').factory.scriptEngine
assert coffeescript.eval('''\
square = (x) -> x * x
return square 3''') == 9
@glaforge
glaforge / gist:1f481e0f0d043260aa9a
Created Dec 2, 2014
List and Map constructor coercion in Groovy
View gist:1f481e0f0d043260aa9a
import groovy.transform.Immutable
@Immutable
class Point {
double x, y
}
Point p1 = [1.23, 5.67]
assert p1.x == 1.23 && p1.y == 5.67
@glaforge
glaforge / Result from the Github API
Created Mar 30, 2015
Get star creation timestamps for a given repository
View Result from the Github API
[
{
"login": "rsutphin",
"id": 2503,
"avatar_url": "https://avatars.githubusercontent.com/u/2503?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/rsutphin",
"html_url": "https://github.com/rsutphin",
"followers_url": "https://api.github.com/users/rsutphin/followers",
"following_url": "https://api.github.com/users/rsutphin/following{/other_user}",
View Api_Bunny_Maze.groovy
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.0')
import wslite.rest.*
import wslite.http.auth.*
import groovy.json.*
def j = new JsonSlurper()
def base = 'http://apibunny.com'
def client = new RESTClient(base)
View github1.groovy
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.0')
import wslite.rest.*
import wslite.http.auth.*
def client = new RESTClient("https://api.github.com")
def response = client.get(
path: '/repos/restlet/restlet-framework-java/events',
query: [page: 11]) // <== page 11 and beyond yield 422
@glaforge
glaforge / fluentHttp.groovy
Last active Aug 29, 2015 — forked from dgageot/fluentHttp.groovy
Fluent HTTP further groovyfied!
View fluentHttp.groovy
@Grab('net.code-story:http:2.98')
import net.codestory.http.WebServer
new WebServer()
.configure { routes -> routes.anyGet { ctx -> "Hello"} }
.start()