Skip to content

Instantly share code, notes, and snippets.

View mainiak's full-sized avatar

Jakub Viták mainiak

View GitHub Profile
@mainiak
mainiak / fun1.js
Last active August 29, 2015 14:03
locking in node.js
#!/usr/bin/env node
var Lock = require('./lock.js');
var lock1 = new Lock();
console.log('lock1.get() #1: ' + lock1.get(function () {
console.log('this will never run');
}));
console.log('lock1.get() #2: ' + lock1.get(function () {
@mainiak
mainiak / .gitignore
Last active September 10, 2015 23:44
webpack vs coffee-script
*.swp
*~
bundle.js
node_modules
@mainiak
mainiak / timerScopeIssue.coffee
Created December 5, 2012 11:32
nodejs setInterval and setTimeout doesn't persist scope
#!/usr/bin/coffee
###
node v0.8.15
###
# this doesn't work for setInterval either
class Test
constructor: (@text) ->
@mainiak
mainiak / read-file.coffee
Created December 8, 2012 17:31
file seeking in nodejs
#!/usr/bin/env coffee
###
in native fs,
we could set position from where to read,
but we have to track it manually
if run many times with position null,
and once with position=0, it doesn't reset to 0
@mainiak
mainiak / Task.coffee
Last active December 10, 2015 00:59
testing time bending in browser - see http://tryjasmine.com - an nodejs
class Task
constructor: (@text) ->
@intervalId = null
hello: -> window.alert @text
delay: 1000 # 1 sec
timeout: ->
var max = 10,
x = {vs:') versus '};
for (var i=0; i<max; i++) {
console.log('i: ', i);
setTimeout((function(number) { console.log('i(' + i + this.vs + number); }).bind(x), (i * 500), i);
}
@mainiak
mainiak / this.coffee
Created January 24, 2013 14:28
learning callbacks and scopes
#!/usr/bin/env coffee
class Test
constructor: (cb) -> cb(@)
hello: -> console.log 'Hello, World!'
cb = (obj) -> obj.hello()
test = new Test cb
@mainiak
mainiak / clean.sh
Created February 28, 2013 13:48
remove tempory files afer vim editing
#!/bin/sh
find "$(pwd -P)" -type f \( -name "*~" -o -name ".*~" \) -exec rm -vf {} +
#!/usr/bin/env coffee
MAX_CALLS = 10
class Test
constructor: ->
@reset()
run1: (returnFn) ->
@count += 1
console.log 'A| count:', @count