Skip to content

Instantly share code, notes, and snippets.

@peysal
peysal / introduction6.groovy
Created August 25, 2013 10:28
introduction to groovy 1) empty map 2) adding things to map 3) concat map to map 4) iterating
def emptyMap = [:]
assert emptyMap.size() == 0
def notEmptyMap = ["person1":"john", "person2":"mus"]
assert notEmptyMap.size() == 2
notEmptyMap.put "person3","test" //adding to existing one
assert notEmptyMap.size() == 3
notEmptyMap["person4"] = "beth"
assert notEmptyMap.size() == 4
@peysal
peysal / introduction7.groovy
Created August 25, 2013 23:01
introduction to groovy 1) range declaration 2) iterate range 3) contains and reverse 4) size, from, to
def myRange = 1..3
assert myRange.size() == 3
(1..3).each{it -> println it} //iterate range
myRange.each{println it}
assert myRange.from == 1
assert myRange.to == 3
assert myRange.contains(2)
assert myRange.reverse() == [3,2,1]
@peysal
peysal / introduction8.groovy
Created August 25, 2013 23:23
groovy introduction closure 1) default it parameter 2) parameter more than 1 3) passing closure to method
def myCodeBlock1 = {println it; it} //closure with 1 parameter
myCodeBlock1("test")
assert myCodeBlock1("test") == "test"
def myCodeBlock2 = {a,b -> a+b}
assert myCodeBlock2(1,2) == 3
def list = ['a','b','c','d']
def newList = []
def clos = { it.toUpperCase() } //accept 1 argument
@peysal
peysal / Date.groovy
Created December 23, 2013 13:54
Setting date and time
package main.groovy
Calendar calendar = Calendar.instance
calendar.set(2011, 2, 26)
println calendar.time
calendar.set(2012, 0, 1, 13,13,59)
println calendar.time
package main.groovy.fp
def isHeader = true
def columns = []
def records1stFile = []
println "1st file ACCOUNT-after.csv"
new File("ACCOUNT-after.csv").eachLine { line ->
if (isHeader) {
columns = line.split(",")
import groovy.io.FileType
class FileInfo {
def path
def parentFolder
def name
def sizeBytes
def sizeKb
FileInfo(File file) {
@peysal
peysal / SqlGroovy.groovy
Created March 26, 2014 09:23
Basic sql query to db using groovy
import groovy.sql.Sql
String db_server = "bun"
String db_database = "bun"
String db_port = "1433"
String db_user = "bun"
String db_password = "bun"
String connectionUrl = "jdbc:sqlserver://" + db_server + ":" + db_port +
";database=" + db_database +
";user=" + db_user +
@peysal
peysal / GroovyShell.groovy
Created March 26, 2014 09:28
Groovy process calling external groovy script
def shell = new GroovyShell()
def file = new File("SqlGroovy.groovy")
shell.evaluate(file)
@peysal
peysal / 0_reuse_code.js
Created August 12, 2014 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@peysal
peysal / input.html
Created August 14, 2014 13:57
Basic input
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
Example page header <small>Subtext for header</small>
</h1>
</div>
<ul class="nav nav-tabs">
<li class="active">