Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / password-finder.js
Created Feb 14, 2014
[nodejs][cluster]fixed length password finder from salted-hash with standard `cluster` module
View password-finder.js
// 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 Aug 29, 2015
[javascript]mahjong calc
View mahjong-calc.html
<!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
[nodejs]Understanding S/Key style One-time password system
View skey.js
// 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 Aug 29, 2015
[nodejs][es6]emulate Paxos network consensus model
View paxos.js
// 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
[html5][chrome]simple screen capture stream demo
View capture.html
<!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 Jun 11, 2014
[nodejs][http]Check 308 Permanent Redirect on browsers
View check308.js
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 Aug 29, 2015
[rust]fizzbuzz and note on rust memory model
View fizzbuzz-011.rs
// 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 Aug 29, 2015
[go][training]fizzbuzz with channel
View fizzbuzz.go
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 Jul 28, 2014
[ES5][nodejs] g()()()()('al') -> "gooooal"
View gooal.js
// [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 Aug 29, 2015
[d3js][javascript]Simulation of SYNC (Peskin model)
View sync-bubble.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
window.addEventListener("load", function () {
"use strict";
var canvas = document.createElement("canvas");
document.body.appendChild(canvas);