Browse Source

second commit

master
Jim Infield 9 years ago
parent
commit
7766e4ffbe
  1. 36
      cidr2.groovy
  2. 33
      domain_artifact.groovy
  3. 18
      tc.groovy
  4. 8
      wordCounter.groovy

36
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()

33
domain_artifact.groovy

@ -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}";
// }
}

18
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."
}

8
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
Loading…
Cancel
Save