Skip to content

Instantly share code, notes, and snippets.

View miceno's full-sized avatar

Orestes Sanchez miceno

  • Barcelona, Spain
View GitHub Profile
@miceno
miceno / gist:738266
Created December 12, 2010 19:42
Read commandline with DSL CliBuilder
// An example of how to configure the CliBuilder to read command line arguments in Groovy.
def cli = new CliBuilder( usage: 'groovy launcher' )
// Option help
cli.h(longOpt: 'help', 'usage information')
// Option script
cli.s(argName:'script', longOpt:'script', required: true,
args: 1, 'Script filename')
@miceno
miceno / sample-getopts.bash
Created December 17, 2010 12:58
How to combine getopts options with (-) and non-options. After processing all options, variable OPTIND contains the value of the first non-option (commandline argument that doesn't start with (-)). Shift command will clean previous commandline optio
#!/bin/bash
while getopts "u:p:" opt; do
case $opt in
u)
echo "-u was triggered, Parameter: $OPTARG"
dbuser="$OPTARG"
;;
p)
@miceno
miceno / title.groovy
Created December 17, 2010 22:11
Create a String centered and filled with a character
"title".center( 40, "-")
@miceno
miceno / Read formatted file one-liner.groovy
Created December 30, 2010 09:24
Read formatted file one-liner
new File("simple.tab").withReader{r->
line = r.readLine();
println "first line: $line"
r.splitEachLine("\t"){fields->
println "fields on line: $fields"
}
}
@miceno
miceno / var_dump.groovy
Created December 30, 2010 20:34
var_dump in Groovy
// ReflectionToStringBuilder wraps a class and outputs a string describing
// its attributes, more or less similar to var_dump in PHP
import org.apache.commons.lang.builder.ReflectionToStringBuilder
variable= new ComplexObject()
println new ReflectionToStringBuilder( variable).toString()
@miceno
miceno / reading and parsing xml.groovy
Created January 2, 2011 11:35
Reading XML with Java DocumentBuilder parsing with Java XPath
// Groovy: Reading XML with Java DocumentBuilder parsing with Java XPath
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.*
import org.w3c.dom.Document;
File f= new File( 'data.xml')
// Reading a Document Builder with Java style
@miceno
miceno / read xml from url.groovy
Created January 2, 2011 12:03
Read an XML from an URL
import groovy.xml.DOMBuilder
import javax.xml.parsers.*
// URL to read
def url= "http://stackoverflow.com/feeds/tag?tagnames=groovy&sort=newest"
// Parse the text
def doc
// Reading with XmlSlurper
doc = new XmlSlurper().parse( url)
@miceno
miceno / gist:762488
Created January 2, 2011 12:27
Read XML and parse with Groovy Style
// Groovy
import static javax.xml.xpath.XPathConstants.*
import javax.xml.xpath.*
import groovy.xml.DOMBuilder
import groovy.xml.dom.DOMCategory
import org.w3c.dom.Document;
url= "http://stackoverflow.com/feeds/tag?tagnames=groovy&sort=newest"
xml= url.toURL().text
@miceno
miceno / table_size.sql
Created January 2, 2011 19:18
Get the size of all tables of a database
mysql -e "show table status" | awk -F'\t' '\
{\
printf ("%-25s %15d\n", $1,$7); \
s+=$7 \
} \
END{ print "resultado: ", s} \
'
@miceno
miceno / notas desarrollo bbpress.txt
Created January 3, 2011 10:36
Notas desarrollo bbpress
notas de integracion
opciones:
public_key
private_key
bluevia_auth_cookie_name: la cookie que vamos a utilizar para la autenticacion.
bluevia_cookies: nombres de las cookies.
bluevia_login_url: url de la pagina de login de bluevia
bluevia_register_url: url de la pagina de registro de bluevia
bluevia_edit_profile_url: url de la pagina de perfil de un usuario de bluevia