Skip to content

Instantly share code, notes, and snippets.

View gaogao-9's full-sized avatar

がお gaogao-9

  • えいえんのじゅうはっさい管理組合
  • がお星
View GitHub Profile
<?php
$getURLParam = function($input,$method=''){
if(!is_array($input)) return [];
$info = [];
foreach($input as $key => $val){
unset($_param);
unset($_key);
unset($_type);
unset($_def);
@gaogao-9
gaogao-9 / userscript.js
Last active December 21, 2015 17:14
いわゆるテンプレ
// ==UserScript==
// @name ユーザースクリプトの名前をここに入力
// @namespace http://your.homepage/
// @version 0.1
// @description enter something useful
// @author あなたの名前をここに
// @match http://www.want_to_match-url.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
class HtmlSpecialChars{
constructor(list){
if(typeof(list) === "undefined") return;
this.escapeList = list;
}
set escapeList(value){
if(typeof(value) !== "object"){
throw new TypeError("escapeListはObject型のプロパティです");
@gaogao-9
gaogao-9 / stack.v
Last active January 28, 2016 16:09 — forked from ebal5/stack.v
作ったはいいけど思った通りの動作をしてくれない子。馬鹿な子ほど可愛いというけれども……
// module stack
// it is submodule of pc
module stack(clk, en, pu_po, qi, qo);
parameter WIDTH = 9;
input clk, en, pu_po;
input [WIDTH-1:0] qi;
output [WIDTH-1:0] qo;
@gaogao-9
gaogao-9 / AccessModifiers.js
Last active May 8, 2016 15:01
Symbolを利用したprivate/protectedのプロパティ及びメソッドを実装しました。Symbolを利用してるのでgetOwnPropertySymbolsでリフレクション出来ます
const classMap = new Map();
const inheritPrototype = Symbol();
const isAccessModifiers = Symbol();
// Proxy使用時用のハンドラ
const proxyHandler = {
set(obj,name,value){
// Symbol以外はセットしないようにする
if(typeof(value)!=="symbol") return;
obj[name] = value;
@gaogao-9
gaogao-9 / asyncDOMContentLoaded.js
Last active March 17, 2016 11:15
async/await等で頻繁に利用する待機可能なPromiseパターンを予めパッケージ化してしまえば便利かなーと思いましたので、色々作っておきました。
import asyncSleep from "./asyncSleep.js";
function asyncDOMContentLoaded(target=window, timeout=10000){
if(target.document.readyState !== "loading"){
return Promise.resolve({ target, data: null });
}
return Promise.race([
asyncSleep(timeout).then(Promise.reject(new Error("asyncDOMContentLoaded is timeout"))),
new Promise((resolve, reject)=>{
@gaogao-9
gaogao-9 / 修正箇所.md
Last active March 6, 2016 11:29
紙の上の魔法使いスクロールバーのバグ修正の話
  • scenario/GraphicalScrollbar.tjs 186行目
- drawState(mask.getMainPixel(x, y) ? 2 : 0);
+ drawState((mask.imageLeft<=x && x<(mask.imageLeft+mask.imageWidth) && mask.imageTop<=y && y<(mask.imageTop+mask.imageHeight)) ? 2 : 0);
  • scenario/GraphicalScrollbar.tjs 192行目
- if(mask === void || mask.getMainPixel(cursorX, cursorY))
+ if(mask === void || (mask.imageLeft&lt;=cursorX &amp;&amp; cursorX&lt;(mask.imageLeft+mask.imageWidth) &amp;&amp; mask.imageTop&lt;=cursorY &amp;&amp; cursorY&lt;(mask.imageTop+mask.imageHeight)))
@gaogao-9
gaogao-9 / Promise.js
Last active October 30, 2021 19:18
正しいPromise.reverseとPromise.anyの実装例
Promise.reverse = function reverse(promise){
// 範囲を広げるために、一応instanceof Promiseではなく、thenableを通すようにしてる。
switch(true){
case (typeof(promise) !== "object"):
case (promise === null):
case (typeof(promise.then) !== "function"):
return Promise.reject(promise);
}
return promise.then((data)=> Promise.reject(data), (err)=> Promise.resolve(err));
@gaogao-9
gaogao-9 / PromiseAdder.js
Last active March 16, 2016 12:04
PromiseでNbit加算器を作るまでの壮大な話(babel replで動かせます。)
(()=>{
const timeMap = new Map();
try{
console.time();
console.timeEnd();
}
catch(err){
console.time = function time(str){
timeMap.set(str, Date.now());
};
@gaogao-9
gaogao-9 / index.js
Last active March 16, 2016 10:24
世界一有名なステートマシンの話としての自動販売機
const vm = vendingMachine();
console.log(vm.next()); // {"value":[0,0],"done":false}
console.log(vm.next(50)); // {"value":[50,0],"done":false}
console.log(vm.next(50)); // {"value":[100,0],"done":false}
console.log(vm.next(100)); // {"value":[80,1],"done":false}
console.log(vm.next(10)); // {"value":[90,0],"done":false}
console.log(vm.next(10)); // {"value":[100,0],"done":false}
console.log(vm.next(10)); // {"value":[110,0],"done":false}
console.log(vm.next(10)); // {"value":[0,1],"done":false}