Skip to content

Instantly share code, notes, and snippets.

@mlist
mlist / config.txt
Created November 24, 2013 19:25
Xbian extras for /boot/config.txt
hdmi_force_edid_audio=1
decode_MPG2=0x7a641de0
decode_WVC1=0x47751316
@mlist
mlist / add_mean_label.r
Created November 26, 2013 13:21
how to add mean labels to groups in ggplot2
stat_summary(aes(label=round(..y..,2)), fun.y=mean, geom="text", size=6, vjust = -0.5)
@mlist
mlist / projections.groovy
Created December 13, 2013 12:32
grails projections with alias and left outer join
def criteria = Spot.createCriteria()
def result = criteria.list {
eq("slide.id", params.long("id"))
createAlias('layoutSpot', 'lSpot', CriteriaSpecification.LEFT_JOIN)
createAlias('lSpot.sample', 'smpl', CriteriaSpecification.LEFT_JOIN)
projections {
property "id"
property "signal"
property "block"
property "row"
@mlist
mlist / jackson.groovy
Created December 13, 2013 12:34
grails with jackson
def criteria = SomeDomainClass.createCriteria()
def result = criteria.list {
...
}
ObjectMapper mapper = new ObjectMapper()
def jsonResult = mapper.writeValueAsString(result)
response.contentType = "text/json"
render jsonResult
@mlist
mlist / SecurityTokenService.groovy
Created December 13, 2013 12:40
SecurityTokenService in grails
class SecurityTokenService {
def getSecurityToken(SomeDomainClass sdc) {
if(!sdc?.uuid){
sdc.uuid = UUID.randomUUID().toString()
sdc.save(flush:true)
}
return sdc.uuid
}
@mlist
mlist / TokenUsingController.groovy
Created December 13, 2013 12:43
how to apply security token service in a controller
private def accessAllowed = { securityToken, uuid ->
//check if user is authenticated
if(!springSecurityService.isLoggedIn()){
//alternatively check if a security token is provided
if(!securityToken || securityToken != uuid){
return(false)
}
}
return(true)
@mlist
mlist / Rcurl_grails.r
Created December 13, 2013 12:45
how to use RCurl to access a grails controller
authenticate <- function(baseUrl="http://localhost:8080/GrailsApp/", user, password, verbose=F){
require(RCurl)
loginUrl = paste(baseUrl, "login/auth", sep="")
authenticateUrl = paste(baseUrl, "j_spring_security_check", sep="")
cat(paste("trying to authenticate user", user))
agent="Mozilla/5.0"
#Set RCurl pars
curl = getCurlHandle()
@mlist
mlist / miracle.groovy
Created April 8, 2014 12:15
MIRACLE example configuration
dataSource {
driverClassName = 'com.mysql.jdbc.Driver'
url = 'jdbc:mysql://localhost/miracle'
username = 'miracle'
password = 'rppa4ever'
dbCreate = 'update'
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
@mlist
mlist / awk.csv.filter.bash
Created May 1, 2014 07:29
How to filter out lines from a CSV file that begin with either CDS or UTR3 using awk, allowing you to process a 2GB file in mere seconds
awk -F, '$1 !~ /(^CDS|^UTR3)/' microT_CDS_data.csv > microT_CDS_data.filtered.csv
@mlist
mlist / createdb.sh
Last active August 29, 2015 14:16
bash script to create a database + user in mysql.
#!/bin/bash
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`
Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT USAGE ON *.* TO $2@localhost IDENTIFIED BY '$3';"
Q3="GRANT ALL PRIVILEGES ON $1.* TO $2@localhost;"
Q4="FLUSH PRIVILEGES;"