Skip to content

Instantly share code, notes, and snippets.

@tomgullo
tomgullo / BasicGroovySql.groovy
Created August 16, 2009 15:11
basic groovy sql
import groovy.sql.Sql
def sql = new Sql(dataSource)
def query = "select * from table"
def rows = sql.rows(query)
@tomgullo
tomgullo / sql_with_like_clause.groovy
Created August 28, 2009 03:26
groovy sql with like clause
def query_params = []
def and_where_string = ''
if (params.name) {
and_where_string = " and where upper(name) like ? "
query_params << "%" + params.name.toUpperCase() + "%"
}
def query = """
select * from table
where table.id is not null
$and_where_string
@tomgullo
tomgullo / bind_user_connection_sql.groovy
Created September 1, 2009 07:05
bind user connection to groovy sql
//bind user connection to groovy sql
Connection conn = dataSource.getConnection(username, password)
def hibernateSession = sessionFactory.currentSession
hibernateSession.reconnect(conn)
def sql = new Sql(sessionFactory.getCurrentSession().connection())
//
//perform sql
@tomgullo
tomgullo / using_groovy_put_params_in_request.groovy
Created September 5, 2009 15:36
put params into request object using groovy
def user_params = ['firstName', 'lastName']
//put params in request in case of errors
for (e in params) {
if (e.key in user_params) {
request."$e.key" = e.value
}
}
//in view, value="${request?.firstName}"
@tomgullo
tomgullo / send_params_to_grails_controller.groovy
Created September 8, 2009 00:23
send params to grails controller
def send_params = [:]
for (e in request.parameterMap) {
if (e.key & e.key instanceof java.lang.String && e.key in user_params && e.value) {
send_params."${e.key}" = e.value[0]
}
}
<g:link action="" params="${send_params}"/>
<!-- Hadoop -->
<!-- core-site.xml -->
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
@tomgullo
tomgullo / GrailsTestWithDataSource.groovy
Created September 11, 2009 12:02
grails test with datasource
GrailsTest extends GroovyTestCase implements ApplicationContextAware {
ApplicationContext app
def controller
void setUp() {
super.setUp()
controller = MyController()
controller.dataSource = app.getBean("dataSource")
@tomgullo
tomgullo / RegexpGroovy.groovy
Created September 11, 2009 12:05
groovy regexp
static String anInvalidCharacter = /[^-A-Za-z9-9@\s()\,\;\:\.]+/
if (s =~ anInvalidCharacter)
//an invalid character
@tomgullo
tomgullo / wordcount.pig
Created September 14, 2009 02:47
wordcount using hadoop pig
A = load '/tmp/alice.txt';
B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word;
C = filter B by word matches '\\w+';
D = group C by word;
E = foreach D generate COUNT(C), group;
store E into '/tmp/alice_wordcount';
let maplocalleader = ","
let mapleader = ","
set number
set nowrap
syntax on
filetype plugin indent on
colorscheme koehler
set guioptions-=T