Skip to content

Instantly share code, notes, and snippets.

View qsona's full-sized avatar

qsona qsona

View GitHub Profile
package calendar;
public class Calendar {
public static final int[] DAY_NUMS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public static final String[] Days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
public static final int BASIS_YEAR = 2014;
public static final int BASIS_JAN_1ST_DAY_INDEX = 3; // Wed
const createEach = (withIndex) => {
return withIndex ?
(arr, iterator) => arr.forEach((elem, index) => iterator(elem, index)) :
(arr, iterator) => arr.forEach((elem) => iterator(elem));
};
const createMap = (withIndex) => {
return withIndex ?
(arr, iterator) => arr.map((elem, index) => iterator(elem, index)) :
(arr, iterator) => arr.map((elem) => iterator(elem));
@qsona
qsona / axios-wrap.js
Last active December 30, 2016 07:56
ie9 formdata axios
if (isIE9()) {
// https://github.com/mzabriskie/axios/blob/master/lib/core/Axios.js
const keys = ['post', 'patch', 'put'];
const origPostFetcher = fetcher.post.bind(fetcher);
['post', 'patch', 'put'].forEach((key) => {
fetcher[key] = function(url, data, config) {
if (data && data.toPlainObject) {
data = data.toPlainObject();
}
if (key !== 'post') {
@qsona
qsona / mizogu.rb
Created May 27, 2017 00:17
mizogu-
# 2〜99のカードの中から2枚取り、その2つの数の和だけをAさんに、積だけをBさんに教えた時の会話が
# A「Bさん、わかりませんね」
# B「お、ならわかった」
# A「なら僕もわかった」
# となった場合、2つの数字はそれぞれ何でしょう。なお、AさんとBさんはそれぞれ完璧に合理的に発言しています。
# (Aさんが一言目をしゃべっているとき、すでに「Bさんがまだわかっていないこと」を察してる前提)
class Candidate
def initialize(low, high)
@low = low
@qsona
qsona / ruby.rb
Created August 18, 2017 06:24
form encode/decode
Faraday::NestedParamsEncoder.encode({"a"=>[{"b"=>"1", "c"=>"2"}, {"b"=>"3", "c"=>"4"}]})
# => "a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bb%5D=3&a%5B%5D%5Bc%5D=4"
URI.decode('a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bb%5D=3&a%5B%5D%5Bc%5D=4')
# => "a[][b]=1&a[][c]=2&a[][b]=3&a[][c]=4"
Faraday::NestedParamsEncoder.encode({"a"=>[{"b"=>"1", "c"=>"2"}, {"d"=>"3", "e"=>"4"}]})
# => "a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bd%5D=3&a%5B%5D%5Be%5D=4"
URI.decode("a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bd%5D=3&a%5B%5D%5Be%5D=4")
# => "a[][b]=1&a[][c]=2&a[][d]=3&a[][e]=4"
Faraday::NestedParamsEncoder.decode("a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bd%5D=3&a%5B%5D%5Be%5D=4")
@qsona
qsona / microfrontends_meetup.md
Last active July 30, 2018 02:22
Micro Frontends Meetup (WIP)

(WIP) Microservices Meetup vol.7 - Micro Frontends -

Micro Frontendsについて議論を深めたい欲が高まっているので

時期

2018年7月下旬 (登壇者決まり次第調整)

内容 (案)

# 22 引数に配列をとって、重複している値を昇順の配列にして返す関数を作れ。
# 例)引数 [1, 3, 2, 3, 8, 3, 2] => 返り値 [2, 3]
def q22(array)
dup = {} # key: number, value: duplicate count (2以上のときは2)
ans = []
array.each do |num|
case dup[num]
when nil
dup[num] = 1
@qsona
qsona / kanpe.md
Last active January 10, 2019 11:37
App Client Melting Pot #1 Panel Discussion

App Client Melting Pot #1 Panel Discussion

ダンボー田中vs軍曹関の設計トークバトル! ひゃたもあるよ

登壇者

@qsona
qsona / App.tsx
Last active August 17, 2020 13:32
TypeScript example of boardgame.io tutorial
import React from 'react';
import './App.css';
import { Client } from 'boardgame.io/react';
import { Game, IPlayer, IGameCtx } from 'boardgame.io/core';
import { AI, IAIMoveObj } from 'boardgame.io/ai';
type GameState = {
cells: Array<IPlayer | null>
};
@qsona
qsona / yubisen.ts
Created August 18, 2019 18:03
yubisen後退解析
import assert from 'assert';
type State = [number, number, number, number];
function stateToHashNum(state: State): number {
const [x1, x2, y1, y2] = state;
return (x1 << 9) | (x2 << 6) | (y1 << 3) | y2;
}
function hashNumToState(num: number): State {