Skip to content

Instantly share code, notes, and snippets.

View ww24's full-sized avatar
🏢
≡GO

Takenori Nakagawa ww24

🏢
≡GO
View GitHub Profile
@ww24
ww24 / api.js
Created June 6, 2012 14:18
HIT講義情報API
var http = require('http'),
https = require('https'),
Iconv = require('iconv').Iconv,
iconv = new Iconv('EUC-JP', 'UTF-8//TRANSLIT//IGNORE'),
cheerio = require('cheerio'),
request = require('request');
var site = 'http://www.hit.ac.jp/gakusei/chgschool/',
port = 8880;
@ww24
ww24 / xhr.js
Created June 17, 2012 02:41
Cross Browser XHR
// XHR
var ajax = function (method, url, data, callback) {
var xhr = /*@cc_on!@*/true ? new XMLHttpRequest() : new XDomainRequest();
xhr.timeout = 3000;
xhr.ontimeout = function () {
alert("timeout");
};
xhr.onerror = function () {
alert("error");
};
@ww24
ww24 / bookmarklet.js
Created June 17, 2012 02:55
Gmailの一番上にあるメールの件名を任意のサーバーへ送る
javascript:(function(){var e=document.getElementById("canvas_frame").contentWindow.document.getElementsByClassName("BltHke nH oy8Mbf"),t;for(var i=0,l=e.length;i<l;i++){t=e[i];if(t.style.display!=="none")break}var s=t.getElementsByTagName("table")[1].getElementsByTagName("tr")[0].getElementsByTagName("td")[5].getElementsByTagName("span")[0].innerText;var x=/*@cc_on!@*/true?new XMLHttpRequest():new XDomainRequest();x.timeout=3000;x.ontimeout=function(){alert("timeout")};x.onerror=function(){alert("error")};x.onload=function(){alert(decodeURIComponent(x.responseText))};x.open("POST",prompt("Subject:"+s+"を送信するサーバを指定してください","http://echo.ww24.jp"),false);x.setRequestHeader("Content-Type","application\/x-www-form-urlencoded;charset=UTF-8");x.send("subject="+encodeURIComponent(s))})()
@ww24
ww24 / Function.prototype.js
Created June 20, 2012 11:30
フィボナッチ数列の実装とメモ化
Function.prototype.memo = function () {
var f = this,
result = {};
return function () {
var key = JSON.stringify(arguments);
if (result[key] === undefined) result[key] = f.apply(null, arguments);
return result[key];
};
};
@ww24
ww24 / blink.js
Created June 21, 2012 12:07
瞬きっぽいものの実装(Googleのトップページで動きます)
@ww24
ww24 / windowManager.js
Created June 23, 2012 13:04
Window Manager
window.windowManager = (function () {
var orgOpen = open,
windows = [];
window.open = function () {
var win = orgOpen.apply(null, arguments);
windows.push({
option: arguments,
window: win
});
return win;
@ww24
ww24 / trim.js
Created June 30, 2012 06:58
String.prototype.trim
// 先頭および末尾の空白を削除
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
@ww24
ww24 / depth.js
Created June 30, 2012 07:18
Array.prototype.depth
// 配列の深さ(次元)を返す
Array.prototype.depth = function () {
function isArray(a) {
return typeof(a) === "object" && (a instanceof Array);
};
var arr = this;
return (function(a, b) {
a = a || arr;
b = b || 0;
@ww24
ww24 / mie.js
Created July 1, 2012 16:11
なにこれ
function mie(name, output) {
var that = this;
output = output ? output : alert;
function create(str) {
return function () {
output(this.name + str);
return this;
};
}
this.name = name;
// https://twitter.com/ww24/status/224148383642824704
console.log(require("fs").readFileSync(__filename, "utf8").length < 100 ? "素敵!" : "長いわ!");