Skip to content

Instantly share code, notes, and snippets.

View nakosung's full-sized avatar

Nako Sung nakosung

  • NAVER, CLOVA AI
  • Seoul, Korea
View GitHub Profile
@nakosung
nakosung / test.coffee
Created July 20, 2013 12:44
mux-demux dnode net
es = require 'event-stream'
dnode = require 'dnode'
MuxDemux = require 'mux-demux'
net = require 'net'
assert = require 'assert'
D = (send,recv) ->
d = dnode fn : (cb) -> cb(send)
d.on 'remote', (r) ->
assert r.fn
@nakosung
nakosung / gist:6153799
Created August 5, 2013 06:03
Switching between dnodes
colors = require 'colors'
es = require 'event-stream'
dnode = require 'dnode'
ss = require 'switch-stream'
server = ->
s = ss()
lobby = ->
d = dnode
Layer.tick : (dT) ->
sprite_nodes.map (s) ->
loc = s.getLocation()
unless s.vel?
s.vel = cc.p (Math.random() - 0.5) * 10, (Math.random() - 0.5) * 10
s.setLocation cc.p loc.x + s.vel.x * dT, loc.y + s.vel.y * dT
bboxes = sprite_nodes.map (n) -> n.getBoundingBox()
@nakosung
nakosung / cocosjsb.sublime-build
Created August 19, 2013 06:40
Sublime text - build script
{
"cmd": ["scripts/build_script.sh"],
"working_dir" : "${project_path:${folder}}/..",
"shell": "true",
"path":"/usr/local/bin:$PATH"
}
templ = {
"type" : "Layer",
"controller" : "MyLayerCtrl",
{
"type" : "LabelTTF",
"repeat" : "x in friends",
"text" : "{{this.x}}",
"click" : "this.invite(this.x);"
}
}
erver = cargoship()
server.get /.*/, (m) -> m.end()
gameserver = (create) ->
log.info 'game created', create.id, create.secret
players = []
(m) ->
unless m?
@nakosung
nakosung / gist:6448113
Created September 5, 2013 09:50
scope inheritance
gen_scope = (parentScope) ->
Scope = ->
Scope.prototype = parentScope
new Scope()
a = gen_scope()
a.x = 1
b = gen_scope a
@nakosung
nakosung / gist:6518458
Created September 11, 2013 01:55
Pinch transformation
http://www.wolframalpha.com/input/?i=inv%28+%7B+%7B+a%2C+-b%2C+1%2C+0+%7D%2C+%7Bb%2C+a%2C+0%2C+1%7D%2C+%7B+c%2C+-d%2C+1%2C+0+%7D%2C+%7B+d%2C+c%2C+0%2C+1+%7D+%7D+%29+*+%7B+%7Bx%7D%2C+%7By%7D%2C+%7Bz%7D%2C+%7Bw%7D+%7D
calc = (p1, p2, q1, q2) ->
low = (a,b,c,d,x,y,z,w) ->
scale = 1/(a^2-2 a c+b^2-2 b d+c^2+d^2)
sct = -b w+d w+a x-c x+b y-d y-a z+c z
sst = -a w+c w-b x+d x+a y-c y+b z-d z
tx = z a^2-d w a-c x a+d y a-c z a+b c w+c^2 x+d^2 x-b d x-b c y+b^2 z-b d z
ty = w a^2-c w a-d x a-c y a+d z a+b^2 w-b d w+b c x+c^2 y+d^2 y-b d y-b c z)
[scale * sct, scale * sst, scale * tx, scale * ty]
@nakosung
nakosung / gist:6548022
Created September 13, 2013 08:21
Items!
ship.use require 'cargoship-modules'
ship.register 'library', (a,next) ->
@require 'bank', (err,bank) ->
return next err if err
bank.get_library next
ship.use (m) ->
ship.require 'bank', 'library', (err,bank,library) ->
ship.methods
get_campaigns : (event,data,next) ->
# get_campaigns 'login:alkka', @user, (err,result) ->
result.media
result.coupon
callback : (coupon,next) ->
per campaign