Skip to content

Instantly share code, notes, and snippets.

View pintowar's full-sized avatar

Thiago Oliveira Pinheiro pintowar

View GitHub Profile
@pintowar
pintowar / telegram.groovy
Created August 1, 2019 00:43
Minimalist telegram chat bot
@Grab('com.github.pengrad:java-telegram-bot-api:4.4.0')
import com.pengrad.telegrambot.TelegramBot
import com.pengrad.telegrambot.UpdatesListener
import com.pengrad.telegrambot.request.SendMessage
def bot = new TelegramBot("my:token") //token
def chats = [] as Set //chatIds as Long
bot.setUpdatesListener { updates ->
@pintowar
pintowar / javadoc-uml.build
Last active June 3, 2017 20:10
Show UML Class Diagrams on Javadoc
//
// Override the javadoc task to use umlgraph doclet. This depends on the presence
// of GraphViz on the path in your environment (http://www.graphviz.org)
//
allprojects {
configurations {
umljavadoc
}
dependencies {
apply plugin: 'scala'
repositories{
mavenCentral()
}
dependencies{
compile "org.scala-lang:scala-library:2.11.8"
compile "org.scala-lang:scala-compiler:2.11.8"
}
@pintowar
pintowar / line_plots.R
Created January 5, 2017 14:28
Series of line plots in R
data <- read.csv('data.csv', sep=',')
subplot <- function(data, set) {
subdata <- subset(data, column == set)
xrange <- strptime(subdata$period, format='%H:%M:%S')
yrange <- subdata$fitness
plot(xrange, yrange, type="l", col="blue", xlab="Period", ylab="Fitness", main="Evolution")
}
@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';
@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 / 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 / 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 / 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 / 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;