Skip to content

Instantly share code, notes, and snippets.

View jonatasemidio's full-sized avatar

Jonatas Emidio jonatasemidio

View GitHub Profile
@jonatasemidio
jonatasemidio / cadp.txt
Last active August 29, 2015 14:16
De X Para de Duas estruturas diferentes de municípios, removendo as repetições.
93#GO#ABADIA DE GOIAS #52137
50#MG#ABADIA DOS DOURADOS #24622
93#GO#ABADIANIA #24615
50#MG#ABAETE #28989
17#PA#ABAETETUBA #5603
32#CE#ABAIARA #5586
39#BA#ABAIRA #2448
39#BA#ABARE #33682
73#PR#ABATIA #15758
75#SC#ABDON BATISTA #44918
l = [
"MUNICIPIO.put(\"50830\",\"1\"); ",
"MUNICIPIO.put(\"9465\" ,\"2\"); ",
"MUNICIPIO.put(\"35697\",\"3\"); ",
"MUNICIPIO.put(\"50919\",\"4\"); ",
"MUNICIPIO.put(\"50971\",\"5\"); ",
"MUNICIPIO.put(\"35680\",\"6\"); ",
"MUNICIPIO.put(\"50964\",\"7\"); ",
"MUNICIPIO.put(\"15978\",\"8\"); ",
"MUNICIPIO.put(\"50957\",\"9\"); ",
@jonatasemidio
jonatasemidio / JokenpoSheldon.groovy
Last active August 29, 2015 14:17
Groovy version do JokenpoSheldon
/*
VERSÃO PARA SERES HUMANOS
No dia 18/03/2015 a Galera do DojoRio resolveuresolver o problema o jokenpo elevado a sheldon cooper. O resultado ofi um dojo com várias risadas e um resultado bem antes das 211:00 da noite.
*/
plays = ['scissor', 'paper', 'rock', 'lizard', 'spock']
def play(play1, play2){
warning = {i, n -> (i + n) % 5}
position = plays.indexOf(play1)
play1 == play2 ? 'draw' : play2 in [plays[warning(position, 1)] , plays[warning(position, 3)]] ? 'play1' : 'play2'
@jonatasemidio
jonatasemidio / Person.java
Last active August 29, 2015 14:17
Mapeamento para Extreme
@Entity
@IdClass(PersonKey.class)
public class Person{
@Id
int taxid;
@Id
String countryCd;
@Transient
PersonKey key
@jonatasemidio
jonatasemidio / SpeakingTongues.groovy
Created April 22, 2015 20:17
Problem A. Speaking in Tongues
d=[:];n='';r=''
g = 'ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc\nypc rtcsra dkh wyfrepkym veddknkmkrkcd\nde kr kd eoya kw aej tysr re ujdr lkgc jvqz'
e = 'our language is impossible to understand there\nare twenty six factorial possibilities\nso it is okay if you want to just give upzq'
g.eachWithIndex{s,i->d+=["${s}":e[i]]}
def tc(def s){d.find{it.key==s}.value}
def tl(def l){l.each{n += tc(it)};return n}
g.split('\\n').eachWithIndex{s,i->r+="Case #${i+1}: ${tl(s)}\n"}
r
@jonatasemidio
jonatasemidio / Euclides.groovy
Created May 4, 2015 19:08
Exemplo Algoritimo de Euclides
def mdc(a, b) { return (b == 0) ? a : mdc (b, a%b) }
mdc 252, 105
@jonatasemidio
jonatasemidio / EuclidesEstendido.groovy
Created May 4, 2015 19:29
Algoritimo de Euclides Estendido
//def mdc(a, b) { return (b == 0) ? a : mdc (b, a%b) }
//mdc 252, 105
def mdcx(a, b){
def r=a; r1=b; u=1; v=0; u1=0; v1=1;
def rs, us, vs, q;
while ( r1 != 0 ) {
q = r/r1 as int
@jonatasemidio
jonatasemidio / switch.groovy
Created May 21, 2015 11:59
O poder do Switch do Groovy
def testSwitch(val) {
def result
switch (val) {
case ~/^Switch.*Groovy$/:
result = 'Pattern match'
break
case BigInteger:
result = 'Class isInstance'
break
case 60..90:
@jonatasemidio
jonatasemidio / grep.groovy
Last active August 29, 2015 14:21
Grep Method
//post sobre o código - http://mrhaki.blogspot.com.br/2009/08/groovy-goodness-grep-method.html
assert [true] == ['test', 12, 20, true].grep(Boolean), 'Class isInstance'
assert ['Groovy'] == ['test', 'Groovy', 'Java'].grep(~/^G.*/), 'Pattern match'
assert ['b', 'c'] == ['a', 'b', 'c', 'd'].grep(['b', 'c']), 'List contains'
assert [15, 16, 12] == [1, 15, 16, 30, 12].grep(12..18), 'Range contains'
assert [42.031] == [12.300, 109.20, 42.031, 42.032].grep(42.031), 'Object equals'
assert [100, 200] == [10, 20, 30, 50, 100, 200].grep({ it > 50 }), 'Closure boolean'
@jonatasemidio
jonatasemidio / BenchmarkTest.groovy
Created May 29, 2015 11:55
What is my mistake?
@Grab( 'com.googlecode.gbench:gbench:0.3.0-groovy-2.0' )
import gbench.*
def i = 0
new BenchmarkBuilder().run( measureCpuTime:true ) {
'TEST:' {
1000000.times{i?.toLong() ? i?.toLong() : null}
}
'TEST:' {