Skip to content

Instantly share code, notes, and snippets.

View st98's full-sized avatar

st98 st98

View GitHub Profile
var c1, c2;
c1 = console.log;
c2 = console.log.bind(console);
c1('hoge'); // => TypeError: Illegal invocation
c1.call(console, 'hoge'); // => hoge
c2('hoge'); // => hoge
@st98
st98 / rot-n.js
Last active August 29, 2015 14:03
ROT(13|47) の実装、変数の名前とかてけとー。
var rot = (function () {
function tr(str, from, to) {
return str.replace(new RegExp('[' + from + ']', 'g'), function (key) {
return to[from.indexOf(key)] || key;
});
}
function range(min, max) {
var result = '';
@st98
st98 / random.bat
Last active August 29, 2015 14:05
自分用。適当に選んで開くヤツ。
@echo off
python -c "import os, random, sys; os.popen('explorer ' + ' & explorer '.join(random.sample(os.listdir('.'), int(sys.argv[1]) if len(sys.argv) > 1 else 1)))" %1
function isStrict() {
try {
arguments.callee;
} catch (_) {
return true;
}
return false;
}
@st98
st98 / Number#length.js
Last active August 29, 2015 14:05
Number#length。何桁か調べます。
function log10(x) {
return Math.log(x) / Math.LN10;
}
Object.defineProperty(Number.prototype, 'length', {
get: function () {
return Math.floor(log10(Math.abs(this))) + 1;
},
set: function (value) {
return value;
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Icon</title>
<style>
body {
width: 30em;
margin: 0 auto;
font-family: Consolas, Meiryo, monospace;
@st98
st98 / hex.js
Last active August 29, 2015 14:06
function _repeat(str, n) {
return Array(n + 1).join(str);
}
function _zfill(str, n) {
return (_repeat('0', n) + str).slice(-n);
}
function hex(str) {
return str.split('').map(function (c) {
@st98
st98 / Array#has.js
Last active August 29, 2015 14:06
Array#has。
Object.defineProperty(Array.prototype, 'has', {
value: function (value) {
return this.indexOf(value) > -1;
},
enumerable: false,
configurable: true,
writable: false
});
Object.defineProperty(Array.prototype, 'contains',
@st98
st98 / r.js
Last active August 29, 2015 14:06
hOGEhoGe, HOgEhoge, hOGEHoge…
'hogehoge'.replace(/./g, function (c) {
return c['to' + ['Lower', 'Upper'][Math.random() * 2 | 0] + 'Case']();
});
@st98
st98 / shift.js
Last active August 29, 2015 14:06
Array#shift。
Object.defineProperty(Array.prototype, 'shift', {
value: function (n) {
return this.slice(n).concat(this.slice(0, n));
},
enumerable: false,
configurable: true,
writable: false
});
//-----