Skip to content

Instantly share code, notes, and snippets.

View renatoathaydes's full-sized avatar

Renato Athaydes renatoathaydes

View GitHub Profile
@renatoathaydes
renatoathaydes / keybase.md
Created September 27, 2017 16:38
Keybase - Renato Athaydes

Keybase proof

I hereby claim:

  • I am renatoathaydes on github.
  • I am renatoathaydes (https://keybase.io/renatoathaydes) on keybase.
  • I have a public key ASD6izZl-Pe5lHzlFdjcZS6HjOG_pPWAkvLfZvAEo2Q9xwo

To claim this, I am signing this object:

@renatoathaydes
renatoathaydes / client.groovy
Last active June 16, 2021 12:18
HTTP Server / Client in Groovy
/*
* This is a runnable groovy script.
* Run with "groovy client.groovy".
*
* Don't forget to start the server.groovy script first (shown in this gist).
*/
import groovy.transform.CompileStatic
import groovy.transform.Immutable
import groovy.transform.ToString
@renatoathaydes
renatoathaydes / fixIntellijProject.groovy
Created June 16, 2016 07:05
Adds src/test/groovy as test sources to all projects under the current directory
import groovy.io.FileType
import groovy.util.slurpersupport.GPathResult
import groovy.xml.XmlUtil
def intellijFileVisitor = { File intellijFile ->
def groovyDir = new File(intellijFile.parentFile, 'src/test/groovy')
if (groovyDir.isDirectory() && groovyDir.list()?.size() > 0) {
def module = new XmlSlurper().parse(intellijFile)
GPathResult sources = module.component.content.sourceFolder
def groovySources = sources.any { it.@url == 'file://$MODULE_DIR$/src/test/groovy' }
@renatoathaydes
renatoathaydes / nBody.ceylon
Last active August 29, 2015 14:19
Ceylon Solution for the n-body problem
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Renato Athaydes
*/
import ceylon.math.decimal {
decimalNumber,
@renatoathaydes
renatoathaydes / world.ceylon
Created April 1, 2015 22:46
The world modelled in Ceylon
abstract class Thing() {
string => className(this).split('.'.equals).last?.string else "";
}
abstract class World(shared Thing+ contents) {}
abstract class Ocean() extends Thing() {}
abstract class Land() of Continent|Island extends Thing() {}
@renatoathaydes
renatoathaydes / mortgage.groovy
Created February 16, 2015 20:07
Mortage calculator
totalValue = 4500000
pantbrev = 1534900
///////////////////////////////////
fromApt = 699500
lagFart = 0.015 * totalValue
toPay = 0.15 * totalValue + 0.02 * (Math.max(0, totalValue - pantbrev)) + lagFart
println "Total to pay $toPay"
@renatoathaydes
renatoathaydes / simpleMathsHelper.ceylon
Created August 25, 2014 20:36
Simple Maths helper program with between 1 and 3 inputs
String askUser(String question) {
process.write(question);
return process.readLine();
}
Float? askUserForNumber(String question) => parseFloat(askUser(question));
void printResult(Float(Float, Float=, Float=) operation, Float x, Float? y, Float? z) {
Float result;
if (exists y) {
@renatoathaydes
renatoathaydes / InstanceManager.java
Created May 25, 2014 08:50
Simple cloud instance manager based on jclouds
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.ec2.domain.InstanceType;
@renatoathaydes
renatoathaydes / simpleGroovlet.groovy
Created May 24, 2014 11:44
A groovlet that logs access and serves a simple HTML page
if (!session) {
session = request.getSession(true);
}
if (!session.counter) {
session.counter = 1
}
html.html {
head {
@renatoathaydes
renatoathaydes / webServer.groovy
Last active October 23, 2023 15:28
A simple web server written in Groovy that provides static and code-generated content
#!/usr/bin/env groovy
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import groovy.servlet.*
@Grab(group='org.eclipse.jetty.aggregate', module='jetty-all', version='7.6.15.v20140411')
def startJetty() {
def server = new Server(8080)