Skip to content

Instantly share code, notes, and snippets.

@hitsujiwool
hitsujiwool / fiddle.js
Created March 30, 2012 18:19
What is 'this'
var foo = {
bar: function() {
console.log('this is ' + this.toString());
}
};
var baz = foo.bar;
foo.bar(); // thisはfoo
baz(); // thisはwindow
@hitsujiwool
hitsujiwool / fiddle.js
Created April 2, 2012 00:52
module export pattern in Node.js
// module pattern 1
(function(exports) {
var ns = {};
ns.method = function() {};
exports.ns = ns;
}(this));
// module pattern 2
var ns = (function(exports) {
exports.method = function() {};
@hitsujiwool
hitsujiwool / fiddle.html
Created April 3, 2012 12:40
JSONP Request Fails in IE6
<a href="javascript:void(0);">click</a>
<div id="log"></div>
@hitsujiwool
hitsujiwool / app.js
Created May 28, 2012 03:19
module autoload in Node.js
var foo = {};
foo.__defineGetter__('bar', function() {
return require('./bar');
});
foo.bar();
@hitsujiwool
hitsujiwool / ibmModel1.js
Created July 15, 2012 04:33
IBM Model 1
/*
* IBM Model 1
*/
(function(exports) {
function train(sentencePairs, iteration) {
iteration = iteration || 100;
var count,
@hitsujiwool
hitsujiwool / clock.js
Created August 25, 2012 06:57
clock with changable tick interval
/*!
* clock
* Copyright (c) 2012 hitsujiwool <utatanenohibi@gmail.com>
* MIT Licensed
*/
;(function(exports) {
function Clock(speed) {
@hitsujiwool
hitsujiwool / csssprite.rb
Created September 16, 2012 07:37
CSS Sprite Generator
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# CSS Sprite Generator
# require imagemagick
# require Ruby >= 1.9
# Usage:
# ruby csssprite.rb file1 file2 file3 [options]
# Options:
@hitsujiwool
hitsujiwool / phrase-extract.js
Created September 27, 2012 04:30
Phrase Extraction
/**
* Phrase Extraction
*/
;(function(exports) {
function extractPhrases(e, f, a) {
var fStart,
fEnd,
result = [];
@hitsujiwool
hitsujiwool / hello.js
Created December 2, 2012 16:01 — forked from shigeki/hello.js
第1回Node.js入門勉強会 レポート課題
var http = require('http');
server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
server.close();
});
server.listen(8080, 0, function () {
console.log('Server running at http://localhost:8080/');
});
function App() {
this.specAndMessages = [];
};
App.prototype.addSpecAndMessage = function(spec, message) {
this.specAndMessages.push({
spec: spec,
message: message
});
};