This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definição do problema: https://gist.github.com/jonatasemidio/8b95d2c666004065c53f | |
String.metaClass.getFirstIsVowel{-> return delegate[0] ==~ /[aeiou]/} | |
'plutãones'.replace(' ','&').collect{ if(it.firstIsVowel){return it+"#"}else{return it}}.join().split('#').collect{it+'pl'+it[-1]}.join().replace('&', ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plutãones | |
Um grupo de pesquisadores descobriram que foi realizada uma missão secreta para plutão em busca de vida e que os astronautas enviaram uma mensagem codificada para a nasa em uma lingua que foi denominada plutãones. | |
Após algumas análises, foi identificado que esta codificação segue os seguintes padrões: | |
1 - Cada palavra é separada por "syllabe textus" ou "ST" (silaba textual - ou seja, a separação não é pelo som e sim pelas vogais, desconsiderando as acentuadas); | |
2 - após cada ST é adicionado o sufixo pl somado com a última letra do ST em questão; | |
3 - No caso da palavra terminar com uma consoante ela não sofre alteração. | |
4 - Em contradição com a regra 3, toda consoante de final de palavra é considerada uma ST se for a ultima da frase. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
public class Losartana{ | |
public String getNome(Integer numero){ | |
return "${numero}º losartana de "; | |
} | |
} | |
Integer.metaClass.getMg{-> return "$delegate mg" } | |
Integer.metaClass.losartanas{ n -> return (1..delegate).collect{ new Losartana().getNome(it) + n }} | |
3.losartanas 5.mg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Veja o código em execução no groovy console: https://groovyconsole.appspot.com/script/5751247093104640 | |
"user_name".split('_').collect{it[0].toUpperCase()+it.substring(1)}.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Original: http://mrhaki.blogspot.com.br/search/label/Groovy%3AGoodness | |
//Português: http://santograils.org/2015/06/12/descubra-os-novos-metodos-do-groovy-para-ordenacao-e-remocao-de-duplicacoes/ | |
@groovy.transform.Sortable | |
@groovy.transform.ToString | |
class User { | |
String username, email | |
} | |
def mrhaki1 = new User(username: 'mrhaki', email: 'mrhaki@localhost') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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:' { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def testSwitch(val) { | |
def result | |
switch (val) { | |
case ~/^Switch.*Groovy$/: | |
result = 'Pattern match' | |
break | |
case BigInteger: | |
result = 'Class isInstance' | |
break | |
case 60..90: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mdc(a, b) { return (b == 0) ? a : mdc (b, a%b) } | |
mdc 252, 105 |