Skip to content

Instantly share code, notes, and snippets.

View renatoathaydes's full-sized avatar

Renato Athaydes renatoathaydes

View GitHub Profile
@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 / JavaFX in OSGi
Last active March 9, 2020 09:48
Packages needed by JavaFX 2.2 to work in OSGi
# Added the following extra packages to OSGI to enable JavaFX 2.2 (JRE 7 update 13)
# Extra packages appended after standard packages
org.osgi.framework.system.packages.extra=javafx.application;version=0.0.0, \
com.sun.browser.plugin; version=0.0.0, \
com.sun.deploy.uitoolkit.impl.fx; version=0.0.0, \
com.sun.deploy.uitoolkit.impl.fx.ui; version=0.0.0, \
com.sun.deploy.uitoolkit.impl.fx.ui.resources; version=0.0.0, \
com.sun.deploy.uitoolkit.impl.fx.ui.resources.image; version=0.0.0, \
@renatoathaydes
renatoathaydes / HaskellVSGroovy.groovy
Last active June 13, 2019 03:59
Haskell VS Groovy
// This is a comparison between Haskell and Groovy based on some simple problems found in the following
// Haskell Introduction:
// http://learnyouahaskell.com/starting-out#ready-set-go
// Ex 1. If we have two lists, [2,5,10] and [8,10,11] and we want to get the products of all the possible
// combinations between numbers in those lists, here's what we'd do.
/* HASKELL */
[ x*y | x <- [2,5,10], y <- [8,10,11]]
@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 / ThrownMatcher.java
Last active February 15, 2016 14:01
ThrownMatcher is a Hamcrest matcher that can be used to verify a Throwable of a certain type has been thrown.
package com.athaydes.automaton.internal;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.internal.matchers.TypeSafeMatcher;
/**
* User: Renato
*/
@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
@renatoathaydes
renatoathaydes / ceylon-generics.ceylon
Created November 28, 2013 21:55
Playing with Ceylon generics.
shared void run() {
object mouseDownBus extends EventBus<MouseDown>() {}
object mouseUpBus extends EventBus<MouseUp>() {}
mouseDownBus.listen(void (MouseDown event) => print("1 - " + event.string));
mouseDownBus.listen(void (MouseDown event) => print("2 - " + event.string));
mouseUpBus.listen(void (MouseUp event) => print("3 - " + event.string));
@renatoathaydes
renatoathaydes / Bindables.ceylon
Last active December 30, 2015 07:09
Example of binding properties for Ceylon.
"A read-only property."
shared interface Property<out Prop> {
"Gets the value of this property."
shared formal Prop get;
"On change of the value of this property, the given function will be invoked."
shared formal void onChange(Anything(Prop) runOnChange);
}
@renatoathaydes
renatoathaydes / ScalaVSCeylon.scala
Last active October 17, 2018 08:29
Scala VS Ceylon
// This is a comparison between Scala and Ceylon based on this previous comparison I made between Haskell and Groovy:
// https://gist.github.com/renatoathaydes/5078535
// Ex 1. If we have two lists, [2,5,10] and [8,10,11] and we want to get the products of all the possible
// combinations between numbers in those lists, here's what we'd do.
/* SCALA */
for { x <- List(2,5,10); y <- List(8,10,11) } yield x*y