Skip to content

Instantly share code, notes, and snippets.

View ichiban's full-sized avatar

Yutaka Ichibangase ichiban

View GitHub Profile
@ichiban
ichiban / map.go
Last active July 19, 2024 23:52
red-black tree with generics
package rbtree
import (
"cmp"
"slices"
)
type color int8
const (
#!/usr/bin/env swipl
:- use_module(library(clpfd)).
:- initialization(main, main).
main(_) :-
current_prolog_flag(max_tagged_integer, Max),
between(3, Max, N),
fermat(X, Y, Z, N),
format('X = ~d~n', X),
@ichiban
ichiban / main.go
Created July 4, 2018 08:25
Pratt Parser
package main
// go port of https://eli.thegreenplace.net/2010/01/02/top-down-operator-precedence-parsing
import (
"fmt"
"log"
"regexp"
"strconv"
)
@ichiban
ichiban / bulma-navbar-burger-delegation.js
Last active December 31, 2017 14:26
Toggle Bulma's navbar-burger with delegation
// https://bulma.io/documentation/components/navbar/#navbarJsExample
document.addEventListener('click', function (e) {
if (!e.target || !e.target.matches('.navbar-burger')) {
return;
}
// Get the target from the "data-target" attribute
const target = e.target.dataset.target;
const $target = document.getElementById(target);
@ichiban
ichiban / _links.json.jbuilder
Created January 8, 2017 06:38
An easy way to implement HAL+JSON in Rails
@ichiban
ichiban / 0.json
Last active September 19, 2016 11:44
How to parse JSON w/ a field which can be string or number in Go
[
{
"name" : "foo",
"value" : 100
},
{
"name" : "bar",
"value" : 200
}
]
$ echo '<n' | ./bnf
>>> "<"
<<< "<"
>>> upper case char
^^^ upper case char
>>> lower case char
<<< lower case char
>>> upper case char
^^^ upper case char
>>> lower case char
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for i := 0; i < dy; i++ {
row := make([]uint8, dx)
for j := 0; j < dx; j++ {
row[j] = uint8(i ^ j)
@ichiban
ichiban / MainViewController.m
Created March 5, 2016 07:34
JSからカスタムURIスキームでObjective-Cの処理を呼ぶ。
// http://qiita.com/GeneralD/items/5a05f176ac2321e7a51b
#define CASE(str) if ([__s__ isEqualToString:(str)])
#define SWITCH(s) for (NSString *__s__ = (s); __s__; __s__ = nil)
#define DEFAULT
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
if ([self isExternalUrl:url]) {
@ichiban
ichiban / gist:15a3267ba0d3b37d9e2b
Created March 4, 2016 09:02
進捗です。1w: main: Unix.Unix_error(Unix.ECONNRESET, "read", "")とは?
$ wrk -t12 -c400 -d30s http://localhost:9000/
Running 30s test @ http://localhost:9000/
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 10.92ms 1.86ms 23.20ms 91.61%
Req/Sec 2.44k 745.81 3.65k 65.37%
655855 requests in 30.09s, 56.29MB read
Socket errors: connect 157, read 56, write 13, timeout 0
Requests/sec: 21799.25
Transfer/sec: 1.87MB