Skip to content

Instantly share code, notes, and snippets.

View uhyo's full-sized avatar
🈚
Current status: totemo yowai programmer

uhyo uhyo

🈚
Current status: totemo yowai programmer
View GitHub Profile
@uhyo
uhyo / gist:6774159
Created October 1, 2013 05:18
for jinrou
type Rank = Int
data Jobname = Human | Diviner | Werewolf Rank deriving (Eq,Show)
data State=State Jobname Bool deriving (Show)
type Plid=String
type Pattern = (Plid,State)
-- 配列を一つ抜く
cutoff :: Int -> [a] -> (Maybe a,[a])
cutoff _ [] = (Nothing,[])
cutoff n list = case (splitAt n list) of (mae, []) -> (Nothing,mae)
@uhyo
uhyo / gist:6775234
Created October 1, 2013 08:07
jinrou2
type Rank = Int
data Jobname = Human | Diviner | Werewolf Rank deriving (Eq,Show)
data State=State Jobname Bool deriving (Show)
type Plid=String
type Pattern = (Plid,State)
-- 配列を一つ抜く
cutoff :: Int -> [a] -> (Maybe a,[a])
cutoff _ [] = (Nothing,[])
cutoff n list = case (splitAt n list) of (mae, []) -> (Nothing,mae)
@uhyo
uhyo / tcp.js
Created July 16, 2016 15:51
tcp
const PORT = 8080;
const net = require('net');
const srv = net.createServer(sock=>{
console.log('New connection');
sock.on('data', buf=>{
console.log('---------- data start ----------');
@uhyo
uhyo / g.js
Last active November 9, 2016 04:46
Googleの"大統領選"の検索結果の州をクリックすると色が変えられるやつ
(()=>{
const svg = document.querySelector('svg');
const svg2 = cl(svg);
const gs = svg2.querySelectorAll('g');
for (let i=0; i < gs.length; i++){
const g = gs[i];
const cl = g.getAttribute('class');
if (cl){
const c = g.getAttribute('class').split(' ');
if (c.some(x=>/__states$/.test(x))){
@uhyo
uhyo / count.sh
Last active January 19, 2017 17:16
Sotsuron word counter
#!/bin/bash
CHAP=
ALLFLAG=0
while getopts ac: OPT
do
case $OPT in
a) ALLFLAG=1;;
c) CHAP=$OPTARG;;
@uhyo
uhyo / count.js
Last active January 10, 2019 04:53
Sotsuron counter (for node.js)
#! /usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const child_process = require('child_process');
// parse args
@uhyo
uhyo / perm.js
Created December 8, 2017 08:24
Permutation using generator
function* perm(arr, prefix=[]){
if (arr.length <= 1){
yield [...prefix, ...arr];
return;
}
for (const [i, x] of arr.entries()) {
const arr2 = [...arr.slice(0, i), ...arr.slice(i+1)];
yield* perm(arr2, [...prefix, x]);
}
}
@uhyo
uhyo / content.js
Created July 4, 2018 13:19
Firefox EventTarget bug reproduction
console.log('Test 1: raw EventTarget');
const et = new EventTarget();
// add handler of 'foo' event
et.addEventListener('foo', (e)=> {
console.log('foo event emitted:', e.detail);
});
// dispatch 'foo' event
et.dispatchEvent(new CustomEvent('foo', { detail: 123 }));
console.log('Test 2: subclass of EventTarget');
// Builderオブジェクトの型
type Builder<Props, Result> = ({} extends Props
? {
build: () => Result;
}
: {}) &
{ [P in keyof Props]-?: SetFunction<Props, P, Result> };
type SetFunction<Props, K extends keyof Props, Result> = (
value: Exclude<Props[K], undefined>
type Digged<T, Keys extends string[]> = DigFunI<T, (...args: Keys) => void>[0];
interface DigFunI<T, F> extends Array<F extends (()=>void) ? T :
F extends ((key: infer K, ...rest: infer Rest) => void) ?
K extends keyof T ? (DigFunI<T[K],((...args: Rest)=>void)> extends Array<infer E> ? E : unknown)
: unknown : unknown>{
}
function dig<T, Keys extends string[]>(obj: T, ...keys: Keys): Digged<T, Keys> {
let result: any= obj;