Skip to content

Instantly share code, notes, and snippets.

View nobishino's full-sized avatar

nobishii nobishino

View GitHub Profile
@nobishino
nobishino / Promise_and_Bind.js
Last active October 18, 2019 12:53
Promiseであそんでみる
/*
* Promiseはモナドじゃないらしいけどモナドっぽく書いてみる試み
* 次の3つの「Promiseを返す関数」をつなげてみる
* f :: number -> Promise number
* g :: number -> Promise string
* h :: string -> Promise ()
*/
const FAILURE_PROBABILITY = 0.1; //一定確率で各プロミスがrejectされるものとする
@nobishino
nobishino / Maybe_Monad_Sample.hs
Last active October 18, 2019 12:42
Maybe Monadサンプル
-- Maybe a (aは任意の型)は「失敗するかもしれない計算」を表す
-- f,g,hという3つのMaybeモナド(を返す関数)をつなぐやつ
-- f :: Int -> Maybe Int
-- g :: Int -> Maybe String
-- h :: String -> Maybe ()
f :: Int -> Maybe Int
f n = if n < 10 then Just (n * 3) else Nothing
-- *Main> f 3
@nobishino
nobishino / Some SQL.md
Last active December 17, 2019 06:36
Some SQL

DDL

CREATE TABLE PRACTICE (
    ID      INTEGER      PRIMARY KEY AUTOINCREMENT,
    [GROUP] VARCHAR (30) NOT NULL
                         DEFAULT ('DEFAULT'),
    LABEL   VARCHAR (30) NOT NULL,
    VALUE   INTEGER      NOT NULL
    );

DDL

CREATE TABLE vertex (
    id       INTEGER PRIMARY KEY AUTOINCREMENT,
    parent_id INTEGER
);

Data

with recursive fibb(x,y) as (
select 0,1
union
select y,x+y from fibb
limit 100
)
select x from fibb;
with recursive euclid(x,y) as (
select 56,12
union all
select y, x%y from euclid
where y != 0
)
select x from euclid
where y = 0;
/*
package main
//1
type Vertex struct {
X, Y int
}
//pointer receiver
func (v *Vertex) Plus() int {
return v.X + v.Y
package main
import (
"fmt"
"math"
"strconv"
)
func main() {
var answers []int
use std::collections::HashSet;
fn main() {
let mut candidate_count = 0;
for i in 1..100000 {
if satisfy(i) {
candidate_count += 1;
println!("Candidate: {}", i.to_string());
}
}
@nobishino
nobishino / auto_lottery.js
Created July 23, 2020 07:57
一定回数実行するかボタンがクリックされるとキャンセルされるlotteryの例1
// timer機能と、定期的に実行される操作が混ざっている
class AutoLottery {
constructor(action, interval) {
this.action = action;
this.interval = interval;
this.count = 0;
}
start() {
const execute = () => {
this.action();