Skip to content

Instantly share code, notes, and snippets.

View ksato9700's full-sized avatar

Ken Sato ksato9700

View GitHub Profile
@ksato9700
ksato9700 / gist:1074697
Created July 10, 2011 17:03 — forked from kevinpang/gist:1015599
JavaScript prototypal inheritance
function Shape(x, y) {
this.x = x;
this.y = y;
}
Shape.prototype.toString = function() {
return 'Shape at ' + this.x + ', ' + this.y;
};
function Circle(x, y, r) {
@ksato9700
ksato9700 / http_client.py
Created December 13, 2011 05:18
pyuv example
import pyuv
def on_close(tcp):
print "closed"
def on_read(tcp, data):
print "read"
if data is None:
tcp.close(on_close)
else:
@ksato9700
ksato9700 / ping_client.py
Created December 13, 2011 16:38
ping example
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import socket
import time
import struct
import datetime
def calculate_checksum(s):
csum = reduce(lambda a,b: a+b,
@ksato9700
ksato9700 / gitconfig
Created December 14, 2011 17:39
colored pager
[color]
ui = auto
[core]
pager = lv -c
@ksato9700
ksato9700 / http_client.js
Created December 17, 2011 08:00
HTTP client and server by node.js
var net = require('net')
console.log("main")
var client = net.connect(8080, function() {
console.log("connected")
var req_message = "GET / HTTP/1.0\r\n\r\n"
client.write(req_message)
});
@ksato9700
ksato9700 / http_client.coffee
Created December 17, 2011 08:27
HTTP client and server by coffee-script
net = require 'net'
console.log "main"
client = net.connect 8080, ()->
console.log "connected"
req_message = "GET / HTTP/1.0\r\n\r\n"
client.write req_message
client.on 'data', (data) ->
@ksato9700
ksato9700 / cell.coffee
Created December 28, 2011 22:02
Coffeescript implementation of systolic array simulation
events = require 'events'
initiator = new events.EventEmitter
class Pipe extends events.EventEmitter
constructor: (@name)->
@queue = []
recv: (event, value) =>
@queue.push(value)
@ksato9700
ksato9700 / systolic_simulator2.erl
Created December 29, 2011 09:20
A sample program to simulate systolic array compuatation
-module(systolic_simulator2).
-export([run/0, cell/6, input/3, terminator/0]).
input(AB, Next, [])->
Next ! {AB, stop};
input(AB, Next, Seq)->
[Head | Rest] = Seq,
Next ! {AB, Head},
input(AB, Next, Rest).
@ksato9700
ksato9700 / systolic_simulator3.erl
Created December 29, 2011 20:31
Yet another systolic array simulator implementation in Erlang
-module(systolic_simulator3).
-export([run/0, pipe/3, terminator/0, cell/2, cell/4, input/3]).
input(AB, Next, [])->
Next ! {AB, stop};
input(AB, Next, Seq)->
[Head | Rest] = Seq,
Next ! {AB, Head},
input(AB, Next, Rest).
@ksato9700
ksato9700 / result.txt
Created January 8, 2012 20:38
How to check python class instance
<type 'instance'> __main__.A True True
<class '__main__.B'> <class '__main__.B'> True True
<type 'int'> <type 'int'> False False
<type 'tuple'> <type 'tuple'> False False
<type 'list'> <type 'list'> False False
<type 'dict'> <type 'dict'> False False
<class '__main__.DD'> <class '__main__.DD'> True True
<type 'bool'> <type 'bool'> False False