Skip to content

Instantly share code, notes, and snippets.

View pintowar's full-sized avatar

Thiago Oliveira Pinheiro pintowar

View GitHub Profile
@pintowar
pintowar / R.groovy
Last active February 28, 2018 18:11
Example of R + groovy integration via Rserve
@Grab(group='org.nuiton.thirdparty', module='REngine', version='1.7-3')
@Grab(group='org.nuiton.thirdparty', module='Rserve', version='1.7-3')
import org.rosuda.REngine.Rserve.RConnection;
/**
* Rserve (R 3.1 or higher) must be running, with command:
* R CMD Rserve
*/
def forecastInR(Closure cback){
def c = new RConnection();
@pintowar
pintowar / ftp.groovy
Created October 29, 2014 17:20
Setting a micro ftp server with groovy and apache ftpserver
@Grab('org.slf4j:slf4j-log4j12:1.7.7')
@Grab('org.apache.ftpserver:ftpserver-core:1.0.6')
import org.apache.ftpserver.FtpServerFactory
import org.apache.ftpserver.FtpServer
import org.apache.ftpserver.listener.ListenerFactory
import org.apache.ftpserver.ConnectionConfigFactory
import org.apache.ftpserver.usermanager.UserManagerFactory
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory
import org.apache.ftpserver.usermanager.impl.BaseUser
import org.apache.ftpserver.usermanager.impl.WritePermission
@Grab('org.apache.camel:camel-core:2.11.0')
@Grab('org.apache.camel:camel-ftp:2.11.0')
@Grab('org.apache.camel:camel-mail:2.11.0')
@Grab('org.apache.camel:camel-groovy:2.11.0')
@Grab('org.slf4j:slf4j-simple:1.6.6')
import org.apache.camel.*
import org.apache.camel.impl.*
import org.apache.camel.builder.*
import org.apache.camel.util.jndi.*
@pintowar
pintowar / jersey.groovy
Last active August 29, 2015 14:10
Groovy script for setting up a jersey REST service wish a WADL contract
@Grab(group='org.glassfish.jersey.containers', module='jersey-container-grizzly2-http', version='2.13')
@Grab(group='org.glassfish.jersey.media', module='jersey-media-json-processing', version='2.13')
@Grab(group='org.glassfish.jersey.media', module='jersey-media-json-jackson', version='2.13')
import javax.ws.rs.*
import javax.ws.rs.core.*
import javax.xml.bind.annotation.*
import com.sun.jersey.api.core.*
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory
import org.glassfish.jersey.server.ResourceConfig
@pintowar
pintowar / RXGlue.groovy
Created January 14, 2015 00:56
Creating a SSE streaming with Apache Camel and Ratpack, using Rx Groovy as a glue
@Grab('com.netflix.rxjava:rxjava-groovy:0.20.7')
@Grab('io.reactivex:rxjava-reactive-streams:0.3.0')
@Grab('org.apache.camel:camel-rx:2.14.1')
@Grab('io.ratpack:ratpack-groovy:0.9.11')
@Grab('org.slf4j:slf4j-simple:1.6.6')
import org.apache.camel.impl.*
import org.apache.camel.rx.*
import static rx.RxReactiveStreams.toPublisher
import static ratpack.groovy.Groovy.ratpack
import static ratpack.sse.ServerSentEvents.serverSentEvents;
@pintowar
pintowar / gradient.rb
Last active August 29, 2015 14:14
gradient class that prints a color between blue and red with a step size of "resolution" (arg)
require 'chunky_png'
class Gradient
attr_accessor :resolution, :R0, :G0, :B0, :R1, :G1, :B1
def initialize(start = 0x0000ff, stop = 0xff0000, resolution = 100)
@resolution = Float(resolution)
@R0 = (start & 0xff0000) >> 16;
@G0 = (start & 0x00ff00) >> 8;
@pintowar
pintowar / matrix-bench.groovy
Last active May 31, 2019 00:03
A nd4j benchmark
@Grab("org.nd4j:nd4j-jblas:0.4-rc3.6")
@Grab("org.nd4j:nd4j-java:0.4-rc3.6")
@Grab("org.ejml:simple:0.27")
@Grab("org.gperfutils:gbench:0.4.3-groovy-2.4")
import gbench.*
import org.ejml.simple.SimpleMatrix
import org.nd4j.linalg.jblas.NDArray
import org.nd4j.linalg.java.JavaNDArray
benchmark {
@pintowar
pintowar / unsubinput.groovy
Created March 1, 2016 15:28
Using RxJava to sequentially unsubscribe an Observable (counter) as a new instance is generated!
@Grab(group='io.reactivex', module='rxjava', version='1.1.1')
@Grab(group='com.hazelcast', module='hazelcast', version='3.6')
import rx.Observable
import rx.Observer
import rx.Subscription
import rx.schedulers.Schedulers
import rx.subscriptions.Subscriptions
import com.hazelcast.core.Hazelcast
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
@pintowar
pintowar / clojure-build.gradle
Last active April 22, 2016 14:47
Gradle script to run a clojure project
plugins {
id "de.kotka.clojuresque.nrepl" version "2.0.0"
}
apply plugin: 'application'
clojure {
warnOnReflection = true
aotCompile = true
}
@pintowar
pintowar / update_postgres_sequences.sql
Created October 18, 2016 12:04
Command to generate commands to update the sequence number of all tables of a postgres database
SELECT
'SELECT setval(''' || table_name|| '_id_seq'', COALESCE((SELECT MAX(id)+1 FROM ' || table_name || '), 1), false);' AS command
FROM
information_schema.tables
WHERE
table_type = 'BASE TABLE'
AND
table_schema = 'public';