Skip to content

Instantly share code, notes, and snippets.

@juandiegoh
juandiegoh / groovy_static_method_change.groovy
Last active August 29, 2015 14:13
Groovy: dynamically change static method implementation
class StaticClass {
static def hello() {
println "hello"
}
}
StaticClass.hello() // prints "hello"
StaticClass.metaClass.static.hello = { println "bye" }
class MyClass {
def printAandB() {
print "A"
b()
}
def printB() {
print "B"
}
@juandiegoh
juandiegoh / export-schema.sh
Created November 22, 2013 02:18
Export Data Base schema with Grails
grails dev schema-export
@juandiegoh
juandiegoh / Redirect Mobile Users.js
Last active December 28, 2015 06:59
Redirect Mobile devices from JavaScript
<script type="text/javascript">
var ios = (/iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase()));
if (ios) {
document.location = "https://itunes.apple.com/us/app/moviz-guess-the-movie/id705337240?l=es&amp;ls=1&amp;mt=8";
}
var android = (/android/i.test(navigator.userAgent.toLowerCase()));
if(android) {
document.location = "https://play.google.com/store/apps/details?id=com.app.android.moviequiz";
}
@juandiegoh
juandiegoh / Difference between two collections - Java.java
Last active December 16, 2015 12:39
Best way (faster) to get the difference from two collections
public List<A> differenceBetween(List<A> minuend, List<A> subtrahend) {
List<A> difference = Lists.newArrayList();
Set<A> subtrahendSets = Sets.newHashSet(subtrahend);
for (A m1 : minuend) {
if (!subtrahendSets.contains(m1)) {
difference.add(m1);
}
}
return difference;
}
@juandiegoh
juandiegoh / .gitignore - Java
Created March 20, 2013 15:08
.gitignore for a Java project
*.class
.classpath
.project
.settings
/target/*
# Package Files #
*.jar
*.war
@juandiegoh
juandiegoh / Install MongoDB and run it on Mac OS X.sh
Last active December 15, 2015 04:09
First steps to install and run MongoDB on Mac OS X
-- you need to have brew installed
brew update
brew install mongodb
-- run mongod which fires the mongo service
mongod
-- open another terminal and run mongo, this opens MongoDB Shell
mongo
@juandiegoh
juandiegoh / Create empty maven project
Last active December 15, 2015 03:59
maven command to create an empty maven project with mvn archetype:create
mvn archetype:create -DgroupId=com.test -DartifactId=mytest