Skip to content

Instantly share code, notes, and snippets.

@ishiduca
ishiduca / gist:1913409
Created February 26, 2012 05:23
Math.(min|max) で配列のmax, minメソッドの実装
var ap = Array.prototype;
if (! ap.forEach_) {
ap.forEach_ = function (f) {
for (var i = 0, len = this.length; i < len; i++) {
f(this[i], i);
}
};
}
if (! ap.grep) {
@ishiduca
ishiduca / gist:1957132
Created March 2, 2012 09:22
revolver.another.js
function revolverSetUp (config) {
var focus = config.focus || 0,
list = tags(config.doms.list, 'li'),
last = list.length - 1,
lock = false,
pos = function (n) {
if (! isNumber(n)) n = 0;
config.doms.list.style.top = (config.doms.defaultTop - n) + "px";
},
@ishiduca
ishiduca / gist:1984241
Created March 6, 2012 06:29
お気に入りユーザの作品を する
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent::Pixiv::Download;
use AnyEvent::FIFO;
use Config::Pit qw(pit_get);
use URI;
use URI::QueryParam;
my $WWW_PIXIX_NET = 'http://www.pixiv.net';
@ishiduca
ishiduca / gist:2168022
Created March 23, 2012 07:37
直列setTimer
// var t = new Timer;
// t.setTimeout(function () {
// console.log('start!');
// }, 250).setInterval(function () {
// var c = t.vars('count');
// if (c > 10) {
// console.log('finish!');
// t.stop();
// return;
// }
@ishiduca
ishiduca / gist:2211941
Created March 27, 2012 02:30
join(joint)(arguments);
function join (joint) {
joint = joint || '';
return function () {
return Array.prototype.join.apply(arguments, [ joint ]);
};
}
join('\n')('<!doctype html>'
, '<head>'
, '<meta charset="utf-8" />'
@ishiduca
ishiduca / parseJSON.js
Created March 27, 2012 02:51
parseJSONFile
var fs = require('fs');
module.exports = function parseJSONFile (path, cb) {
if (typeof cb !== 'function') throw('2nd argument must be "Function"');
try {
fs.readFile(path, 'utf-8', function (err, data) {
if (err) throw err;
cb(JSON.parse(data));
});
} catch (e) { throw e; }
};
@ishiduca
ishiduca / gist:2236346
Created March 29, 2012 11:43
node.js http.agent の agent.maxSockets の上限を避ける
var http, url, path;
http = require('http');
url = require('url');
path = require('path');
function httpRequest (/* getURL, method, options, onResponse */) {
var that, watcher, helper,
args, getURL, uri, uriPath, method, options, headers, body, requestOptions;
@ishiduca
ishiduca / gist:2270042
Created April 1, 2012 00:32
convert shift_jis -> utf8 :node.js
var Iconv, iconv, httpRequest;
httpRequest = require('httpclient').httpRequest;
Iconv = require('iconv').Iconv;
//iconv = new Iconv('SHIFT_JIS', 'UTF-8//TRANSLIT//IGNORE');
iconv = new Iconv('CP932', 'UTF-8//TRANSLIT//IGNORE');
function gsURL (uri) {
return function (_uri) {
if (_uri && _uri !== uri) uri = _uri;
@ishiduca
ishiduca / gist:2280639
Created April 2, 2012 04:09
node.js http.agent の agent.maxSockets の上限を避ける その2
var events,http, url, path;
events = require('events');
http = require('http');
url = require('url');
path = require('path');
var agents = {};
agent.onSocketsLengthChange;
if (http.getAgent) {
@ishiduca
ishiduca / gist:2291667
Created April 3, 2012 12:40
nodebrew の導入 2012.04.03
  • node modules の アンインストール

    $ npm ls # モジュールのリストを見る $ sudo npm uninstall "module name"

  • npm のアンインストール

    $ sudo npm uninstall -g

  • node.js のアンインストール