Skip to content

Instantly share code, notes, and snippets.

function basetrans(srcchars, dstchars){
var srcbase = isUnique(srcchars) && baseNum(srcchars, false),
dstbase = isUnique(dstchars) && baseNum(dstchars, true),
srcbase_bitlen = Math.log2(srcbase),
dstbase_bitlen = Math.log2(dstbase)
if(!srcbase || !dstbase){
throw new Error("argument string is not unique chars")
}
if(!srcbase_bitlen || !dstbase_bitlen){
throw new Error("length of argument string is too short")
@nexpr
nexpr / makeIndex.js
Created December 4, 2015 08:53
h系タグからインデックスを作る
function makeIndex(get_elem_selector, set_elem_selector){
var glem = document.querySelector(get_elem_selector)
var slem = document.querySelector(set_elem_selector)
if(!glem || !slem) throw "element not found"
var hs = []
!function recur(elem){
var match = elem.tagName.match(/^H([1-9])$/)
if(match){
hs.push([+match[1], elem.textContent])
}else{
@nexpr
nexpr / loading-curtain.js
Last active January 15, 2016 13:13
ローディング画面
!function(){
// style
var style_inner = `
.loading-container{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
@nexpr
nexpr / cursor.js
Created December 4, 2015 08:57
配列にカーソル付ける
!function(){
Array.prototype.cursorInit = function(){
this.cursor = 0
return this
}
Array.prototype.cursorEnd = function(){
this.cursor = this.length ? this.length - 1 : 0
return this
@nexpr
nexpr / color-util.js
Created December 4, 2015 08:58
色扱う時のライブラリ。css3のカラーに対応。
var Colors = {
dat : {
aliceblue:"#f0f8ff",
antiquewhite:"#faebd7",
aqua:"#00ffff",
aquamarine:"#7fffd4",
azure:"#f0ffff",
beige:"#f5f5dc",
bisque:"#ffe4c4",
black:"#000000",
!function(){
Object.prototype.mcall = function(method, bind_this){
var that = this
var this_to_arg = true
var fn = method
if(typeof fn === "string" && fn.charAt(0) === ":"){
fn = fn.substr(1)
bind_this = window
}
else if(arguments.length < 2){
@nexpr
nexpr / zoom.js
Created December 4, 2015 09:06
右クリック+ホイールでズームレベル変更(たしかChromeのみ動く)
!function(){
var zoom_active = false
var zoom_change = false
var zoom_per = 1.08
var init = function(){
document.body.style.zoom = 1
}
if(document.readyState === "complete"){
init()
@nexpr
nexpr / prototype-chain.php
Created December 4, 2015 09:09
prototype chain in php
<?php
class Object{
function __call($name, $arguments){
if(is_object($this->__proto__)){
$meth = $this->__proto__->$name;
array_unshift($arguments, $this);
return call_user_func_array($meth, $arguments);
}else{
throw new Exception();
}
<?php
class InputGetter{
function __get($key){
return null;
}
function __construct($array){
foreach($array as $key => $val){
$this->$key = $val;
}
function FlowControl(auto){
this.auto = !!auto
this.finish = {}
this.wait = []
this.units = {}
if(document.readyState === "complete"){
this.set("load")
}else{
window.addEventListener("load", function(){