Skip to content

Instantly share code, notes, and snippets.

View KOBA789's full-sized avatar
🚀

KOBA789 KOBA789

🚀
View GitHub Profile
var toList = function (value) {
return Array.isArray(value) ? value : [value];
};
var range = function (from, to) {
var result = [];
for (var i = from; i <= to; i ++) {
result.push(i);
}
@KOBA789
KOBA789 / gist:1447435
Created December 8, 2011 16:05 — forked from alice1017/gist:1447401
showbox.js
$(function(){
$("span#search_box").click(
function(){
if ($("span#search").css("display") == "none"){
$("span#search").slideDown("nomal");
}
else {
$("span#search").slideUp("nomal");
}
});
var routes = require('./routes');
// 中略
app.get('/', routes.index);
app.get('/topics/', routes.topics.index);
app.get('/topics/:topic_id', routes.topics.show);
app.get('/topics/:topic_id/posts/:post_id', routes.topics.post.show);
@KOBA789
KOBA789 / monadic.js
Created November 26, 2011 13:23
きっとMonadic
var fs = require('fs');
function putStrLn (m) {
return function (cb) {
if (m) {
m(function (str) {
console.log(str);
cb();
});
} else {
@KOBA789
KOBA789 / main.js
Created November 25, 2011 13:58
real-async-without-indent
var fs = require('fs');
function readFile (filename) {
return function () {
fs.readFile(filename, 'utf8', arguments.callee.next);
}
}
function getData() {
return function (err, data) {
@KOBA789
KOBA789 / a.txt
Created November 25, 2011 13:29
async-without-indent
some
@KOBA789
KOBA789 / compose.js
Created November 23, 2011 10:32
JavaScript で関数を合成してみた
function compose () {
return Array.prototype.reduce.call(arguments, function (f, g) {
return function (x) {
return f(g(x));
}
});
}
@KOBA789
KOBA789 / gist:1380442
Created November 20, 2011 16:30
電磁リレーシミュレータのソースコード
#1bit + 1bit の加算回路(XOR)
-C(R1 L)A-B(R2 L)C-A(L1)C-
(R1 L)B-A(R2 L)
-C(R1 R)A-C(R2 R)A-A(L2)C-
#ハンドアセンブルしたもの
['VCC', 'R1LC']
['R1LA', 'R2LB']
['R2LC', 'L1A']
['L1C', 'GND']
@KOBA789
KOBA789 / nb.js
Created November 16, 2011 15:36
NodeBench
var http = require('http');
var maxConnections = 1000, maxRequests = 10000;
var connections = 0, requests = 0, errors = 0, done = 0;
var options = {
host: 'target',
port: 80,
path: '/'
@KOBA789
KOBA789 / fizzbuzz.coffee
Created October 9, 2011 11:55
CoffeeScript で FizzBuzz
fizzbuzz = (num) ->
if num % 15 == 0 then 'FizzBuzz'
else if num % 3 == 0 then 'Fizz'
else if num % 5 == 0 then 'Buzz'
else num
console.log (fizzbuzz num for num in [1..100]).join('\n')