Skip to content

Instantly share code, notes, and snippets.

View kdabir's full-sized avatar
👨‍💻
go git it

Kunal Dabir kdabir

👨‍💻
go git it
View GitHub Profile
@kdabir
kdabir / finalizer.gradle
Created February 23, 2016 11:21
When a task must always execute!
task someTask << {
println 'A task that will fail'
throw new RuntimeException()
}
task cleanup << {
println 'Will perform cleanup no matter what'
}
someTask.finalizedBy cleanup
@kdabir
kdabir / webpack_c9.sh
Created December 11, 2015 06:44
Running webpack on c9.io
webpack-dev-server --progress --colors --host $IP --port $PORT
@kdabir
kdabir / using_call.groovy
Created November 26, 2015 07:15
using call on groovy object.
def now = new A()
class A{
def getCurrentDate() {new Date().format("yyyy-MM-dd HH:mm:ss")}
def call(){ getCurrentDate() }
}
now()
@kdabir
kdabir / hypotenuse.coffee
Created November 25, 2015 08:24
Check screen size diagonally by providing height and width
sqr = (n) -> n*n
sqrt = (n) -> Math.sqrt n
hypt = (h,w) -> sqrt (sqr(h) + sqr(w))
console.log hypt(10, 6.5)
console.log hypt(10, 6)
console.log hypt(6, 9)
console.log hypt(6, 9)
@kdabir
kdabir / test_failures_logging.gradle
Created October 19, 2015 08:56
Instead of having to open a report html file, it is desirable to see them in console. source: http://stackoverflow.com/questions/28614865/how-to-read-test-result-reports-on-travis-ci?lq=1
test {
testLogging {
events "failed"
exceptionFormat "short"
}
}
@kdabir
kdabir / find_repos.sh
Created August 16, 2015 07:50
finding all git repos in dir recursively
find . -type d -name .git ! -path "*/node_modules/*" ! -path "*/bower_components/*"
@kdabir
kdabir / recursive_cons.coffee
Created August 12, 2015 06:41
recursive instantiation in constructor in coffee
class A
constructor: (@a)->
if @a>0 then @child = new A(@a-1)
console.log new A(2)
@kdabir
kdabir / dry_run.groovy
Created July 18, 2015 06:59
using directree
@Grab('io.github.kdabir.directree:directree:0.3.0')
import static directree.DirTree.build
def d = build("test"){
dir "mydir", {
}
}
assert d.mydir.file == new File("test/mydir")
@kdabir
kdabir / ext.groovy
Created July 17, 2015 13:52
Get extention of line on command line
groovy -ne 'println line.split(/\./)[-1]'
@kdabir
kdabir / sleep.coffee
Last active May 14, 2017 14:26
Sleep with a promise
sleep = (ms) ->
new Promise (resolve, reject) ->
try
setTimeout(resolve, ms)
catch e
reject(e)
return
sleep(1000).then( -> console.log "hola" )