Skip to content

Instantly share code, notes, and snippets.

View renatoathaydes's full-sized avatar

Renato Athaydes renatoathaydes

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / util.js
Created November 3, 2012 20:31
Util JavaScript functions
(function() {
var chars = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY0123456789~`!@#$%^&*()-_=+{[}]|\\;:'\"<,>.?/";
/**
* Get a random char according to the optionsl options given.
* @param options can be one of:
* <ul>
* <li><b>'alpha'</b>: only returns alphabetic chars</li>
* <li><b>'lowercase'</b>: only returns alphabetic chars</li>
@renatoathaydes
renatoathaydes / createOsgiBluePrintProject.groovy
Created February 3, 2013 19:09
Creates a simple Osgi Blueprint Project using a Maven Archetype.
// Creates an empty OSGi Blueprint project using the Maven archetype
// http://karaf.apache.org/manual/2.2.6/developers-guide/archetypes.html
def MAVEN_HOME = 'C:/Program Files/Maven/apache-maven-3.0.3/bin'
def cli = new CliBuilder()
cli.with {
g args: 1, 'GroupId of the artifact being created'
a args: 1, 'ID of the artifact being created'
@renatoathaydes
renatoathaydes / RomanNumeral.java
Created April 17, 2013 07:22
Converter of Arabic numbers to Roman numbers
import java.util.HashMap;
import java.util.Map;
public class RomanNumeral
{
private static final Map<Integer, String[]> romanCharsByDecimalPlace = new HashMap<Integer, String[]>()
{
{
put( 0, new String[]
@renatoathaydes
renatoathaydes / CheckGraphicsDeviceBounds.groovy
Last active December 26, 2015 01:28
Groovy script that prints information about the graphics devices currently in use.
import java.awt.*
def virtualBounds = new Rectangle()
GraphicsEnvironment ge = GraphicsEnvironment.localGraphicsEnvironment
GraphicsDevice[] gs = ge.screenDevices
println Arrays.toString(gs)
gs.each { GraphicsDevice gd ->
GraphicsConfiguration[] gc = gd.configurations