Skip to content

Instantly share code, notes, and snippets.

View behrangsa's full-sized avatar
💾

Behrang Saeedzadeh behrangsa

💾
View GitHub Profile
@behrangsa
behrangsa / gist:6712702
Created September 26, 2013 11:04
Java Quiz #1
public class Main {
public static void main(String[] args) {
A a = new A();
B b = null;
try {
b = new B(a);
} catch (Exception e) {}
System.out.println(a.b);
System.out.println(b);
class AbstractViewModel {
def model
def propertyMissing(String name) {
model.get(name)
}
def methodMissing(String name, args) {
model.invokeMethod(name, args)
}
@behrangsa
behrangsa / gist:5595848
Created May 16, 2013 23:13
Sub/Super/Delegate
class Del {
def del() { println "Del.del" }
}
class Super {
def sup() { println "Super.sup" }
}
class Sub extends Super {
@Delegate Del del = new Del()
grails test-app SrpMapSpec --stacktrace --verbose
| Packaging Grails application.....
| Packaging Grails application.....
| Packaging Grails application.....
| Packaging Grails application.....
| Running Grails application
May 13, 2013 10:44:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-7080"]
May 13, 2013 10:44:55 AM org.apache.catalina.core.StandardService startInternal
@behrangsa
behrangsa / gist:5545532
Created May 9, 2013 04:18
Indirect mixins not supported in Groovy 2.0.8
class MixinFoo {
def foo() { println "foo" }
}
@Mixin(MixinFoo)
class MixinBar {
def bar() { println "bar" }
}
@behrangsa
behrangsa / gist:5472950
Last active December 16, 2015 17:49
JavaScript arrays are lolsome :)

Two correct ways to use for/in in JavaScript:

for (var i in a) {
  if (!a.hasOwnProperty(i)) continue; 
  
  // loop body
}

for (var i in a) { 
@behrangsa
behrangsa / ParaTest.groovy
Created February 28, 2013 00:00
Parallel testing for Grails
includeTargets << grailsScript("_GrailsInit")
def createTestCommand(reportPath, serverPort, chromeDriverPort, testPhaseAndType) {
"grails -Dgrails.project.test.reports.dir=${reportPath} -Dserver.port=${serverPort} " +
"-Dchrome-driver.port=${chromeDriverPort} test-app ${testPhaseAndType}"
}
target(main: 'Run lego and functional tests in parallel') {
def threads = []
def reportsBaseDir = 'para-reports'
@behrangsa
behrangsa / dabblet.css
Created February 9, 2013 11:31
Untitled
.button-group {
margin: 100px auto;
width: 290px;
height: 50px;
border-radius: 4px;
background-image: -webkit-linear-gradient(top, #f1f6fa, #dee7f0);
box-shadow:
0 0 2px 0 rgba(64, 100, 138, 0.5),
0 4px 10px 0 #3b5c7f;
class Point  
    attr_accessor :x
    attr_accessor :y

    def initialize(*args)       
        init_methd_name = "_init_#{args.size}"      
        send(init_methd_name, *args)        
    end
@behrangsa
behrangsa / gist:4701009
Last active December 12, 2015 02:39
SmartInit: Smarter var-args constructors in Ruby

SmartInit: Smarter var-args constructors in Ruby

I was working on a small Ruby program today and I repeatedy needed to write classes that can accept a variable number of arguments in their constructors.

This is the initial solution I came up with:

class MyClass  
	def initialize(*args)		
		init_methd_name = "_init_#{args.size}"