Skip to content

Instantly share code, notes, and snippets.

View mgdelacroix's full-sized avatar
🎧
Working from home

Miguel de la Cruz mgdelacroix

🎧
Working from home
View GitHub Profile
@mgdelacroix
mgdelacroix / gist:903820
Created April 5, 2011 15:22
Averiguar los días de semana a partir de una fecha
import datetime
diccionario = {'MONDAY':'Lunes','TUESDAY':'Martes','WEDNESDAY':'Miercoles','THURSDAY':'Jueves', 'FRIDAY':'Viernes','SATURNDAY':'Sabado','SUNDAY':'Domingo'}
fecha = datetime.date(2011, 4, 6)
diaSemana = diccionario[fecha.strftime('%A').upper()]
@mgdelacroix
mgdelacroix / gist:2397424
Created April 16, 2012 10:04
Rename a file in Groovy
def file = new File("/tmp/image.jpg")
println ">> Nombre del fichero: ${file.name}"
println "HACEMOS EL RENAME"
def string = "/tmp/${file.name[0..-5]}_thumb.jpg"
def newFile = new File(string)
file.renameTo(newFile)
println ">> Nombre del fichero: ${newFile.name}"
@mgdelacroix
mgdelacroix / gist:5063524
Created March 1, 2013 09:32
OneLiner to execute and print the output of a system command using groovy
'ping -c 5 google.es'.execute().waitForProcessOutput(System.out, System.err)
@mgdelacroix
mgdelacroix / bookScript.groovy
Created April 19, 2013 10:19
FTPClient test. Download All Things!
@Grab(group='commons-net', module='commons-net', version='2.0')
import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPFile
new FTPClient().with {
connect '61.135.158.199'
println replyString
enterLocalPassiveMode()
login('anonymous', '')
@mgdelacroix
mgdelacroix / build.gradle
Created August 17, 2013 12:25
Gradle initial file to manage a grails project. Taken from the GR8 talk from Luke Daley "Building Grails Apps With Gradle" http://www.youtube.com/watch?v=FwZvDU2Jeh8
buildscript {
repositories {
maven { url "http://repo.grails.org/grails/repo" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT"
}
}
repositories {
@mgdelacroix
mgdelacroix / copyFile.groovy
Created December 11, 2013 15:55
Copy a file with groovy
new File(destinationPath) << new File(originPath).bytes
@mgdelacroix
mgdelacroix / asType.groovy
Created December 12, 2013 11:13
Implement the asType method for a class
Object asType(Class type) {
switch (type) {
case String:
return this.toString()
break
case Integer:
return this.toInteger()
break
@mgdelacroix
mgdelacroix / not.groovy
Last active January 4, 2016 08:18
Groovy: value not in list
Boolean not(Boolean val) {
return !val
}
def value = 7
def valueList = [1, 2, 3]
// not value in valueList
@mgdelacroix
mgdelacroix / urlCopy.groovy
Created January 24, 2014 11:40
Using URL to copy files in groovy
URL penny = new URL('http://tankian99.files.wordpress.com/2011/08/kaley_cuoco_by_m4rios.jpg')
new File('/tmp/penny.jpg') << penny.openStream()
URL localPenny = new URL('file:///tmp/penny.jpg')
new File('/tmp/penny2.jpg') << localPenny.openStream()
@mgdelacroix
mgdelacroix / pprint.groovy
Created February 13, 2014 16:24
Pretty printer in groovy Lists and Maps
import groovy.json.JsonBuilder
java.util.LinkedHashMap.metaClass.pprint = { -> new JsonBuilder(delegate).toPrettyString() }
java.util.ArrayList.metaClass.pprint = { -> new JsonBuilder(delegate).toPrettyString() }