Skip to content

Instantly share code, notes, and snippets.

@mresetar
mresetar / prettyTime.groovy
Created May 9, 2011 13:03
Pretty time u groovy za hrvatski locale
@Grab(group='com.ocpsoft', module='ocpsoft-pretty-time', version='1.0.7')
import groovy.time.TimeCategory
import com.ocpsoft.pretty.time.PrettyTime
Date.metaClass.pretty = {it ->
def p = new PrettyTime(it, new Locale("hr"))
p.format(delegate)
}
use(TimeCategory){
@mresetar
mresetar / gist:962501
Created May 9, 2011 13:19 — forked from anonymous/gist:800225
UUID generator
import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.StringSelection
import java.awt.Toolkit
import javax.swing.*
class UUIDgenerator {
def readIcon() {
byte[] iconBytes = new byte[990]
@mresetar
mresetar / ToJsonSucks.groovy
Created June 8, 2011 13:18
Groovy ToJsonSucks
import groovy.json.JsonOutput
class User {
def ime
def prezime
}
def u = new User(ime:'Ime', prezime:'Prezime')
use (JsonOutput) {
@mresetar
mresetar / generateHeapDump.py
Created August 25, 2011 20:20
WAS Jython script to generate heap dump
serverJvm = AdminControl.queryNames('WebSphere:type=JVM,*')
print 'Generating dump for server: ' + serverJvm
dumpFile = AdminControl.invoke(serverJvm, 'generateHeapDump')
print 'Heap dump file: ' + dumpFile
@mresetar
mresetar / euler1.groovy
Created September 12, 2011 21:51
euler problem one
int sum
(1..999).each { int i -> sum += i%3==0 ? i : i%5==0 ? i:0 }
print sum
@mresetar
mresetar / EulerTwo.groovy
Created September 12, 2011 22:30
Euler problem two
int fib(int to, int fibMinOne=0, int fibMinTwo=0) {
to > 2 ? ((fibMinTwo==0 ? fib(to - 2):fibMinTwo) + (fibMinOne==0 ? fib (to - 1):fibMinOne)) : to == 2 ? 2: (to== 1 ? 1: 0);
}
int sum
int fibMinOne
int fibMinTwo
for (int i=0;; i++) { def f = fib(i,fibMinOne,fibMinTwo); fibMinTwo=fibMinOne;fibMinOne=f;if (f>4e6) break; sum+=f%2==0?f:0}
print sum
@mresetar
mresetar / sendMail.groovy
Created January 29, 2012 14:50
Groovy send e-mail
@GrabConfig(systemClassLoader=true)
@Grapes(
@Grab(group='javax.mail', module='mail', version='1.4.4')
)
def ant = new AntBuilder()
ant.mail(mailhost:'localhost', mailport:25, subject:'Test message') {
from(address:'mySystem@localhost')
cc(address:'mySystem@localhost')
to(address:'tester@localhost')
@mresetar
mresetar / readMail.groovy
Created January 29, 2012 15:21
Read e-mail Groovy script
import javax.mail.*;
import javax.mail.internet.*;
@GrabConfig(systemClassLoader=true)
@Grapes(
@Grab(group='javax.mail', module='mail', version='1.4.4')
)
// setup connection
Properties props = new Properties();
def host = "localhost";
@mresetar
mresetar / SendJmsMessage.java
Created June 15, 2012 12:54
Used to test send JMS message in WebSphere
/**
*
*/
package net.croz.jms.test;
import java.util.Date;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
@mresetar
mresetar / createWinMaxLenDirName.groovy
Created August 29, 2012 09:14
Creates longest possible dir name for windows
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#maxpath
def dirName = 'd:\\tmp\\'
def MAX_PATH = 260
def FILE_NAME = 12
def NULL_SIZE = 1
def i = dirName.length()
while (i < MAX_PATH - FILE_NAME - NULL_SIZE) {
def iLen = (i as String).length()
def currLenValue = i + iLen