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
// If there are two elements with the same freq, this code will take the first one | |
[1,2,2,3,3,3,4,4,4,4] | |
.countBy { it } | |
.max { it.value } | |
.key |
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 getPropertyFileKeys = { File file -> | |
file.readLines().collectEntries { Strin line -> | |
line.split('=').with{ [(first()):last()] } | |
}.keySet() | |
} | |
def compareAndAppend = { File source, File destination -> | |
sourceKeys = getPropertyFileKeys(source) | |
destinationKeys = getPropertyFileKeys(destination) | |
sourceKeys.each { key -> |
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("io.ratpack:ratpack-groovy:0.9.2") | |
import static ratpack.groovy.Groovy.* | |
import ratpack.handling.Handler | |
import ratpack.handling.Context | |
ratpack { | |
handlers { | |
get { | |
println "hola mundo ${new Date()}" | |
context.insert(new MyHandler()) |
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("io.ratpack:ratpack-groovy:0.9.2") | |
import static ratpack.groovy.Groovy.* | |
import ratpack.handling.Handler | |
import ratpack.handling.Context | |
import static groovy.json.JsonOutput.toJson | |
import static ratpack.registry.Registries.registry | |
ratpack { |
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("io.ratpack:ratpack-groovy:0.9.2") | |
import static ratpack.groovy.Groovy.* | |
import ratpack.handling.Handler | |
import ratpack.handling.Context | |
ratpack { | |
handlers { | |
get new TestHandler() | |
} | |
} |
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
# In config/application.rb | |
config.watchable_dirs['lib'] = [:rb] | |
# When requiring something, use require_dependency | |
# To use lib/myclass.rb | |
require_dependency 'myclass' |
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 socket = new Socket('localhost', 5000) | |
socket.withStreams { input, output -> | |
println input.newReader().readLine() | |
output << 'Imma socket' | |
} |
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
enum EitherStatus { | |
LEFT, RIGHT | |
} | |
class Either { | |
EitherStatus status = EitherStatus.RIGHT | |
Map data | |
String toString() { | |
return "[${this.status}] > ${this.data}" |
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
@GrabConfig(systemClassLoader=true) | |
@Grab('com.h2database:h2:1.4.180') | |
import groovy.sql.Sql | |
Sql sql = Sql.newInstance("jdbc:h2:/tmp/devDb", 'sa', '') | |
println "=================== TEST CONTENT" | |
println '>> You can invoke this script with two args to insert into test table (id, name)' | |
println '>> You can invoke this script with the argument CREATE or DESTROY to create or destroy the test table' |
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
import random | |
from functools import reduce | |
def to_fate(result): | |
if result < 3: | |
return '-' | |
elif result < 5: | |
return ' ' | |
else: | |
return '+' |