Skip to content

Instantly share code, notes, and snippets.

View nobishino's full-sized avatar

nobishii nobishino

View GitHub Profile
-- Monad laws and examples
-- Thanks to http://learnyouahaskell.com/a-fistful-of-monads#monad-laws
-- Left identity
-- return x >>= f equals to f x
l1 = return 3 >>= (\x -> Just (x + 100000))
l2 = (\x -> Just (x + 100000)) 3
l3 = return "WoM" >>= (\x -> [x,x,x])
package main
func main() {
v3 := Vector3D[int]{1,2,3}
println(DProd[Vector3D[int], int](v3,v3))
}
type Numeric interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
@nobishino
nobishino / pathpatterns.ts
Created April 16, 2021 12:00
Detect conflict between two path patterns.
// PathPattern codes
// "/hoge/:id"
// "/hoge/fuga/:name"
// "/hoge/fuga/hoho/:value"
// "/hoge/:param/fuga"
//
// :name = fuga AND :param = fuga
//
# S-043: レシート明細テーブル(receipt)と顧客テーブル(customer)を結合し、性別(gender)と年代(ageから計算)ごとに売上金額(amount)を合計した売上サマリテーブル(sales_summary)を作成せよ。性別は0が男性、1が女性、9が不明を表すものとする。
# ただし、項目構成は年代、女性の売上金額、男性の売上金額、性別不明の売上金額の4項目とすること(縦に年代、横に性別のクロス集計)。また、年代は10歳ごとの階級とすること。
with recursive ls(l,u) as (
select 0,10
union all
select l+10, u+10 from ls
), levels as (
select l,u, cast(l as text) || '-' || cast(u as text) as title
from ls
package main
import "fmt"
type T struct {
x int
}
func (t *T) Set(x int) {
t.x = x
// timerにexecutorを渡す例
// timerは定期実行と定期実行の終了に責任を持つ
// 実行される処理と処理を終了すべきかどうかの判断はexecutorが持つ
class Timer {
constructor(executor, interval) {
this.executor = executor;
this.interval = interval;
}
start() {
const execute = () => {
@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();
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());
}
}
package main
import (
"fmt"
"math"
"strconv"
)
func main() {
var answers []int