Skip to content

Instantly share code, notes, and snippets.

import com.sun.net.httpserver.*
Object.metaClass.webapp = {
{ path ->
try {
def attrs = path.split('/')[1..-1]
[200, owner.delegate.invokeMethod(attrs.head(), attrs.tail() as Object[]) as String]
} catch (Exception e) {
[500, e as String]
}

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
# for gvm to autopick grails version only when cd in a grails proyect
alias autopick='AUTO_VERSION=`grep app.grails.version application.properties` ; AUTO_VERSION=${AUTO_VERSION:19}; gvm use grails $AUTO_VERSION'
chdir() {
local action="$1"; shift
case "$action" in
# popd needs special care not to pass empty string instead of no args
popd) [[ $# -eq 0 ]] && builtin popd || builtin popd "$*" ;;
cd)
if [ $# -eq 0 ]
def model = [model:[book:[title:"The Shinning"]]]
def magicMethod= { String exp ->
def out = [:]
out.result = Eval.x(model,"x.with{${exp}}")
try{
if(out.result){
Eval.x(model,"x.with{assert !(${exp})}")
}else{
Eval.x(model,"x.with{assert ${exp}}")
document.getElementById("referencia").innerHTML = parseInt(document.getElementById("referencia").innerHTML,10)
@dnoseda
dnoseda / gist:2406374
Created April 17, 2012 14:36
uncamelize key of map in groovy
Map toUncamelizedKeyMap(Map map){
(map+[:]).each{k,v->
map[k.replaceAll(/([A-Z])/,'_$1').toLowerCase()] = v
}
return map
}
Map toCamelizedKeyMap(def map){
(map+[:]).each{k,v->
def camelized = k.split("_").collect({"${it[0].toUpperCase()}${it[1..-1]}"}).join()
resultado=`grep $1 nota.txt`
if [ "$resultado" = "" ]; then
echo "no encontro"
else
echo "encontro"
fi
@dnoseda
dnoseda / gist:2252219
Created March 30, 2012 15:16
sort-appa
javascript:(function(){var%20s=document.createElement("script");s.src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js";s.onload=function(){var%20my_options=$("#roles%20option");my_options.sort(function(a,b){if(a.text>b.text){return%201;}else{return%20-1;}});$("#roles").empty().append(my_options);};document.body.appendChild(s);})()
window.twttr=window.twttr||{};
var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0,F=document,u=encodeURIComponent(F.location.href),t=encodeURIComponent(F.title);
if(C>A){
G=Math.round((C/2)-(A/2))
}
window.twttr.shareWin=window.open('http://linksdeviernes.com/add.php?url='+u+'&titulo='+t,'','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
#!/bin/sh
#find $1 -type f -print0 | xargs -0 sed -i 's/$2/$3/g'
echo $1 $2 $3
grep -rl $2 $1 | while read fn; do
echo "replacing in $fn $2 for $3"
sed -i "s/$2/$3/g" $fn
done