This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 外部ファイルを動的ロードするサンプル | |
| * | |
| * node.js だとコードを修正するたびにプロセス殺して、もう一度立ちあげなきゃならないから面倒だよね。 | |
| * 実行中書き換えとかできないの? ってなわけで作ってみた。 | |
| * PHP とか Perl って CGI だから実行の度にプロセスが走るわけで、 | |
| * コード修正したら F5 するだけで結果がわかるから超手軽なんだけど、 | |
| * それだとプロセス起動のコストが高いわけで、これはその辺のジレンマも解消してみた。 | |
| * | |
| * コード見ればわかるんだけど外部ファイルが書き換えられた瞬間にスクリプトがコンパイルされる感じ。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ux_nu = require('./ux_nu'); | |
| //短縮(Shorten) | |
| ux_nu.shorten('http://www.gehirn.co.jp/', function (err, url, obj) { | |
| console.log(url); | |
| }); | |
| //元に戻す(Expand) | |
| ux_nu.expand('http://ux.nu/Gehirn', function (err, url, obj) { | |
| console.log(url); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var buf1 = new Buffer([0xe3, 0x81]); | |
| var buf2 = new Buffer([0x82, 0xe3, 0x81, 0x84]) | |
| Buffer.prototype.push = function (buf) { | |
| var newBuf = new Buffer(this.length + buf.length); | |
| this.copy(newBuf); | |
| buf.copy(newBuf, this.length); | |
| return newBuf; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| import "acme/oppai" | |
| func main() { | |
| var o oppai.Oppai; | |
| fmt.Printf( | |
| o.Massage(). | |
| Massage(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sleepSort(arr, cb) { | |
| var c = 0, result = []; | |
| for (var i = 0; i < arr.length; i++) { | |
| var n = arr[i]; | |
| setTimeout(function(n) { | |
| result.push(n); | |
| c++; | |
| if (c >= arr.length) { | |
| cb(result); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http = require 'http' | |
| server = http.createServer (req, res) -> | |
| req.writeHead 200, 'Content-Type': 'text/plain' | |
| req.end 'Hello coffee script on node.js' | |
| server.listen 3000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // この辺は自分でアプリ登録して書き換える | |
| var consumerKey = '', | |
| consumerSecret = '', | |
| token = '', | |
| tokenSecret = ''; | |
| // 投稿するメッセージの内容 | |
| var message = 'ゆれくる!!'; | |
| /* === 以下ごにょごにょ === */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var html = require("http"); | |
| var base_header = new Object({ | |
| "Content-Type":"text/html;charset=utf-8" | |
| }); | |
| var server = html.createServer(); | |
| server.on("request",function(req,res){ | |
| res.writeHead(200,base_header); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| i = 1 | |
| while i < 100 | |
| printf i.to_s + "\r" | |
| if i % 3 == 0 | |
| printf "Fizz" | |
| end | |
| if i % 5 == 0 | |
| printf "Buzz" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 情報の授業でやったbuggyな練習問題を仕様通りに動作させてみた | |
| /* | |
| * ==仕様== | |
| * | |
| * 1.整数の値tを入力する | |
| * 2.それが0-11の範囲なら「おはよう」、12なら「正午」、13-17なら「こんにちは」、18-23なら「こんばんは」、それ以外なら「範囲外」と出力 | |
| */ | |
| // 問題のコード(あまりにも汚いインデントだったので整形済み) | |
| // |