diff --git a/cidr2.groovy b/cidr2.groovy new file mode 100644 index 0000000..411eba4 --- /dev/null +++ b/cidr2.groovy @@ -0,0 +1,36 @@ +def packAddr(symbolic) { + packd = 0 + symbolic.split(/\./).eachWithIndex { b, i -> + packd |= (b as Long) << (8*(3-i)) + } + return packd +} + +def packIP(symbolic) { + i = 0 + symbolic.split(/\./).inject(0) { p, b -> + p |= (b as Long) << (8*(3-(i++))) + } +} + +def packIt(symbolic) { + symbolic.split(/\./)*.toLong().inject([p:0,i:0]) { m, b -> + [p: m.p |= b << (8*(3-m.i++)), i: m.i] + }.p +} + +def unpackIt(packed) { + (0..3).collect(new ArrayList()) { i -> + packed >>> (8*(3-i)) & 255 + }.join('.') +} + +def addr = '198.50.24.68' +def pckd = 3325171780 + +println packIt(addr) +println unpackIt(pckd) + +[addr.split(/\./),[24,16,8,0]].transpose().collect(new HashSet()) { m -> + (m[0]as Long) << m[1] +}.sum() diff --git a/domain_artifact.groovy b/domain_artifact.groovy deleted file mode 100644 index f1fbd18..0000000 --- a/domain_artifact.groovy +++ /dev/null @@ -1,33 +0,0 @@ -@artifact.package@/** - * @artifact.name@ - * A domain class describes the data object and it's mapping to the database - */ -class @artifact.name@ { - - /* Default (injected) attributes of GORM */ -// Long id -// Long version - - /* Automatic timestamping of GORM */ -// Date dateCreated -// Date lastUpdated - -// static belongsTo = [] // tells GORM to cascade commands: e.g., delete this object if the "parent" is deleted. -// static hasOne = [] // tells GORM to associate another domain object as an owner in a 1-1 mapping -// static hasMany = [] // tells GORM to associate other domain objects for a 1-n or n-m mapping -// static mappedBy = [] // specifies which property should be used in a mapping - - static mapping = { - } - - static constraints = { - } - - /* - * Methods of the Domain Class - */ -// @Override // Override toString for a nicer / more descriptive UI -// public String toString() { -// return "${name}"; -// } -} diff --git a/tc.groovy b/tc.groovy new file mode 100644 index 0000000..f629ff2 --- /dev/null +++ b/tc.groovy @@ -0,0 +1,18 @@ +import groovy.time.TimeCategory + +rt = Runtime.getRuntime() +threads = rt.availableProcessors() + +def now = new Date() +def then = new Date().parse('yyyy-MM-dd-hh','2015-09-23-18') +def cruise = Calendar.instance +cruise.set(2015,9,5,16,0,0) + +use TimeCategory, { + println "Current DateTime: " + now + def c = then - now + def b = cruise.time - now + println "My contract ends in ${c.days.intdiv(7)} weeks, ${c.days % 7} days, ${c.hours +1} hours." + print "Our Bahama cruise leaves the port in " + println "${b.days.intdiv(7)} weeks, ${b.days % 7} days, ${b.hours} hours, and ${b.minutes} minutes." +} diff --git a/wordCounter.groovy b/wordCounter.groovy new file mode 100644 index 0000000..424d505 --- /dev/null +++ b/wordCounter.groovy @@ -0,0 +1,8 @@ +count = [:] +count.test = 1 +count.is = 2 +['this', 'is', 'a', 'test'].each { + count[it] ? (count[it] += 1) : (count[it] = 1) +} + +println count