Skip to content

Instantly share code, notes, and snippets.

View dexterous's full-sized avatar

Saager Mhatre dexterous

View GitHub Profile
@dexterous
dexterous / grails-blog
Created February 28, 2011 08:02
minimum steps to create a Grails blog using simple-blog plugin (ignoring SCM commands)
$ grails create-app grails-blog
$ cd grails-blog
$ grails install-plugin simple-blog
$ cat >> grails-app/conf/Config.groovy
> grails.blog.author.evaluator = { request.remoteAddr }
> ^D
$ mkdir -p grails-app/domain/demo/blog/
$ cat > grails-app/domain/demo/blog/Commenter.groovy
> package demo.blog
>
@dexterous
dexterous / proc_expectations.rb
Created February 28, 2011 09:12
various use cases for ruby blocks
require 'rubygems'
require 'expectations'
Expectations do
expect(1){ proc{ |a| a }.call(1) }
expect([1, 2]){ proc{ |a| a }.call(1, 2) }
expect(1){ proc{ |a, b| a }.call(1, 2) }
expect(1){ Proc.new{ |a| a }.call(1) }
@dexterous
dexterous / check_svn_mirror.sh
Created March 3, 2011 05:23
That is one long-ass nagios plugin!
#!/bin/bash
/export/groups/nagios/libexec/check_http -f follow -H $1 -u /trainline -a tlsvn:\!4321abcd -r `/usr/bin/curl -u tlsvn:\!4321abcd -L http://bngsvn01.thoughtworks.co/trainline 2> /dev/null | /bin/sed -ne "/title.*Revision/ { s/.*trainline -Revision \([0-9]\+\):.*/\1/ ; p}"`
@dexterous
dexterous / CategoryGotcha.groovy
Created March 3, 2011 05:28
scoping gotcha with Groovy Categories
def f = new Foo('hello')
assert f.bar() == 'original hello'
use(FooCategory) { assert f.bar() == 'categorical hello' }
class Baz {
def quux(boo) { new Foo(boo).bar() }
}
@dexterous
dexterous / proc_indexer.rb
Created March 3, 2011 14:16
Ohh... my head hurts!
foo = lambda { |x| puts x }
foo.call('Hello, World!')
foo['You can index me too!']
@dexterous
dexterous / anon_blocks.groovy
Created March 3, 2011 14:29
sometimes Groovy just cracks me up!
({ it('ABCD') }) { "${it} and some more" } //=> 'ABCD and some more'
@dexterous
dexterous / BooleanCategory.groovy
Created March 3, 2011 15:04
No more if's; SmallTalk style conditionals in Groovy
class BooleanCategory {
public static Boolean then(Boolean self, Closure c) {
if(self) c()
return self
}
public static Boolean otherwise(Boolean self, Closure c) {
if(!self) c()
return self
@dexterous
dexterous / emails.sed
Created March 8, 2011 09:40
devcamp.in utils
#!/usr/gnu/bin/sed -rf
s_\|\s*(\[\S+\s*)?([^\|]+)\]?\s*\|\|([^\|]+)\|\|.*_"\2" <\3>, _
s_ "_"_g
s_]"_"_
s_< _<_
s_ >_>_
s_\s*\(at\)\s*_@_g
s_\s*\(dot\)\s*_._g
s_\s*\[dot\]\s*_._g
# http://github.com/c42/goldberg/raw/master/Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'sqlite3', '~> 1.3.3', :platforms => :ruby
gem 'haml', '~> 3.0.25'
platform :jruby do
@dexterous
dexterous / OS.groovy
Created June 21, 2011 09:31
a not so quick script hacked together to scrape the product info from lenovo's product listing page
enum OS {
DOS('PC DOS 2000 License'), WIN('Genuine Windows 7 Professional 32');
private final String text
private OS(text) { this.text = text }
public static parseText(text) { OS.values().find { it.text == text } }
}