Skip to content

Instantly share code, notes, and snippets.

View mike-neck's full-sized avatar
🏠
Working from home

mike_neck mike-neck

🏠
Working from home
View GitHub Profile
@mike-neck
mike-neck / GeneratePassword.groovy
Created June 17, 2011 08:13
Generating Password
def xml = new groovy.xml.MarkupBuilder()
def introduction = {
'my-information'{
name('mike_neck')
'twitter-id'('@mike_neck')
job('SE')
}
'why-groovy'{
'I-Tweeted'('To rewrite a copy of sample code is too bore for me. So I will write it in Groovy')
import static groovyx.gpars.GParsPool.*;
def numero = [1,2,3,4]
def square = [1,4,9,16]
withPool{
assert square == numero.collectParallel {
println it
it * it
}
@mike-neck
mike-neck / GParsSample2mapReduce.groovy
Created June 17, 2011 11:04
GPars Sample Map-Reduce
import static groovyx.gpars.GParsPool.*;
withPool {
assert 30 ==
[1,2,3,4,5,6,7,8,9,10].parallel
.filter {
println "filter -> $it"
it <= 5
}
.map {
@mike-neck
mike-neck / GParsActorSample.groovy
Created June 17, 2011 11:22
GPars Actor Sample
import static groovyx.gpars.actor.Actors.*;
def console = actor{
loop{
react {msg ->
println msg
}
}
}
@mike-neck
mike-neck / jquery_mobile.groovy
Created July 1, 2011 08:29
Groovy Markup Builder for jquery mobile
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.html('lang' : 'ja'){
head{
meta('http-equiv' : 'Content-Type', 'content' : 'text/html; charset=UTF-8')
title('jQuery Mobile Sample')
link('rel' : 'stylesheet', 'href' : 'http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css')
['http://code.jquery.com/jquery-1.6.1.min.js', 'http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js'].each{
@mike-neck
mike-neck / jquery_mobile_grid.groovy
Created July 2, 2011 05:36
Groovy Markup Builder for jquery mobile (Grid Records)
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.html('lang' : 'ja'){
head{
meta('http-equiv' : 'Content-Type', 'content' : 'text/html; charset=UTF-8')
title('jQuery Mobile Sample')
link('rel' : 'stylesheet', 'href' : 'http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css')
['http://code.jquery.com/jquery-1.6.1.min.js', 'http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js'].each{
@mike-neck
mike-neck / create_random_int.groovy
Created July 5, 2011 08:29
creates random integer between given range
IntRange.metaClass.random = {(new Random()).nextInt(delegate.to - delegate.from + 1) + delegate.from}
@mike-neck
mike-neck / min_max.groovy
Created July 5, 2011 08:36
get minimum value and maximum value
def max = {num1, num2 ->
(num1 - num2 > 0) ? num1 : num2
}
def min = {num1, num2 ->
(num1 - num2 > 0) ? num2 : num1
}
assert max(1,2) == 2
assert min(2,1) == 1
@mike-neck
mike-neck / AndroidExtendedTestCase.java
Created July 11, 2011 08:38
Invoking android.test.AndroidTestCase#getTestContext method
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.content.Context;
import android.test.AndroidTestCase;
public class AndroidExtendedTestCase extends AndroidTestCase {
public Context getTestContext(){
Context context = null;
@mike-neck
mike-neck / getInetAddress.groovy
Created July 12, 2011 06:41
get InetAddress
import java.net.*;
NetworkInterface.getNetworkInterfaces().each{nInterface ->
println 'display name : ' + nInterface.getDisplayName()
nInterface.getInetAddresses().each{addr ->
address = addr.getHostAddress()
println 'address : ' + address
}
}