Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / password-finder.js
Created February 14, 2014 04:55
[nodejs][cluster]fixed length password finder from salted-hash with standard `cluster` module
// fixed length password finder from salted-hash
// with standard `cluster` module
var cluster = require("cluster");
// `cluster.isMaster` as the only master process, otherwise worker process
if (cluster.isMaster) {
var spec = {
alg: "md5",
enc: "hex",
@bellbind
bellbind / mahjong-calc.html
Last active August 29, 2015 13:57
[javascript]mahjong calc
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="mahjong-calc.js"></script>
</head>
<body>
<h1>Mahjong Calc</h1>
<div>
Han: <input id="han" type="number" value="3" min="1" max="55" step="1" />
@bellbind
bellbind / skey.js
Created May 15, 2014 07:27
[nodejs]Understanding S/Key style One-time password system
// S/Key style One-time Password system
var crypto = require("crypto");
// [functions for OTP system]
// generate server info of one time password
var initAccount = function (passphrase) {
var alg = "sha256";
var enc = "hex";
var times = 100;
@bellbind
bellbind / paxos.js
Last active August 29, 2015 14:01
[nodejs][es6]emulate Paxos network consensus model
// Paxos network consensus protocols
// Promise of ECMAScript6 used.
// Promise utilities
var Utils = {
moreThanHalf: function (promises) {
return new Promise(function (fulfill, reject) {
var success = 0;
var failure = 0;
var half = (promises.length / 2)|0;
@bellbind
bellbind / capture.html
Created May 23, 2014 07:10
[html5][chrome]simple screen capture stream demo
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>screen capture on chrome</title>
<script>
(navigator.getUserMedia || navigator.webkitGetUserMedia).bind(navigator)({
video: {
mandatory: {
chromeMediaSource: "screen"
@bellbind
bellbind / check308.js
Created June 11, 2014 07:24
[nodejs][http]Check 308 Permanent Redirect on browsers
var http = require("http");
// see: http://tools.ietf.org/html/rfc7238
if (!http.STATUS_CODES["308"]) http.STATUS_CODES["308"] = "Permanent Redirect";
var server = http.createServer(function (req, res) {
if (req.url === "/redirect") {
var uri = "http://" + req.headers["host"] + "/result";
res.statusCode = 308;
res.setHeader("Location", uri);
@bellbind
bellbind / fizzbuzz-011.rs
Last active August 29, 2015 14:02
[rust]fizzbuzz and note on rust memory model
// fizzbuzz on rust 0.11
// rustc fizzbuzz.rs
// ./fizzbuzz
fn main() {
for i in range(1u, 101) {
// xxx! denotes xxx is defined as macro
println!("{}", fizzbuzz(i));
}
}
@bellbind
bellbind / fizzbuzz.go
Last active August 29, 2015 14:02
[go][training]fizzbuzz with channel
package main
import (
"fmt"
)
func fizzbuzz(n int) string {
switch f, b := n % 5 == 0, n % 3 == 0; {
case f && b: return "FizzBuzz"
case f: return "Fizz"
@bellbind
bellbind / gooal.js
Created July 28, 2014 07:45
[ES5][nodejs] g()()()()('al') -> "gooooal"
// [ES5][nodejs] g()()()()('al') -> "gooooal"
// see: https://github.com/eatnumber1/goal
var g = function g(al) {
"use strict";
var go = this ? this : "g";
return al ? go + al: g.bind(go + "o");
};
console.log(g('al')); // => "gal"
console.log(g()('al')); // => "goal"
@bellbind
bellbind / sync-bubble.html
Last active August 29, 2015 14:04
[d3js][javascript]Simulation of SYNC (Peskin model)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
window.addEventListener("load", function () {
"use strict";
var canvas = document.createElement("canvas");
document.body.appendChild(canvas);