Skip to content

Instantly share code, notes, and snippets.

View htsign's full-sized avatar
🤔

htsign htsign

🤔
View GitHub Profile
@htsign
htsign / Pair.java
Created July 6, 2021 03:47
nicely worked on Java8
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Pair<Left, Right> {
private static final List<Pair<?, ?>> cache = new ArrayList<>();
public final Left left;
public final Right right;
private Pair(Left left, Right right) {
// required: FSharp.Control.AsyncSeq
open FSharp.Control
open System.Diagnostics
open System.Drawing
open System.Windows.Forms
let inline initCollectionWithCtor< ^a, 'b, 'c when ^a : (member Add : 'b -> 'c)> items collection =
let add xs x = (^a : (member Add : 'b -> 'c) (xs, x))
items |> List.fold (fun (xs : 'a) x -> add xs x |> ignore; xs) collection
@htsign
htsign / phantomTypeSample.ml
Last active April 13, 2021 01:03
prevent excessive sorting w/ phantom types
module MyArray : sig
type ('a, 'status) t
type regular
type sorted
val create : 'a array -> ('a, regular) t
val to_array : ('a, 'status) t -> 'a array
val sort : ?comparer:('a -> 'a -> int) -> ('a, regular) t -> ('a, sorted) t
end = struct
type ('a, 'status) t = Array of 'a array
@htsign
htsign / StdIn.go
Last active April 23, 2021 14:35
get stdin lines
// Go
package main
import (
"bufio"
"fmt"
"os"
)
// ==UserScript==
// @name Key media control for niconico
// @namespace https://htsign.hateblo.jp
// @version 0.9.6
// @description ニコニコ動画本体側でいろいろ便利になった結果、今は音量を表示させる機能と次の動画を自動再生させない機能のみ
// @author htsign
// @match https://www.nicovideo.jp/watch/*
// @match https://live.nicovideo.jp/watch/*
// @updateURL https://gist.github.com/htsign/014c9b053f5eb62791fc04570ce79dcc/raw/MediaControlNiconico.user.js
// @downloadURL https://gist.github.com/htsign/014c9b053f5eb62791fc04570ce79dcc/raw/MediaControlNiconico.user.js
@htsign
htsign / ExceptionWrapper.java
Last active August 22, 2023 07:00
Lambda expression implementation with wrapping Checked exception for Java
public class ExceptionWrapper {
@SuppressWarnings("unchecked")
public static <T, E extends Exception> T exec(ThrowableSupplier<T, E> func, Function<E, T> orElse) {
try {
return func.getThrowable();
}
catch (WrapperException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception) {
return orElse.apply((E) cause);
@htsign
htsign / ScancodeMap.reg
Created December 2, 2020 01:43
無変換キーを左Shiftに、変換キーを右Shiftに置き換える
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,2a,00,7b,00,36,00,79,00,00,00,00,00
@htsign
htsign / monad.ml
Created August 30, 2020 16:39
OCamlではモナドを一般化できない…?
module Monad = struct
module type MonadType = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val return : 'a -> 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val flatmap : ('a -> 'b t) -> 'a t -> 'b t
end
module type MonadType2 = sig
@htsign
htsign / list.ml
Last active December 31, 2020 09:17
include Stdlib.List
let scan f ?init xs =
let scan' xs =
let rec aux acc xs =
match acc, xs with
| _, [] -> acc
| [], x :: xs -> aux [x] xs
| x :: _, y :: ys -> aux (f x y :: acc) ys
in
@htsign
htsign / seq.ml
Last active May 12, 2022 03:22
Stdlib.Seq extension / 正直 Core とか Batteries とか使えば終わる話ではある
include Stdlib.Seq
let cons x xs = fun () -> Cons (x, xs)
let rev xs =
let rec aux acc ys =
match ys () with
| Nil -> acc
| Cons (y, ys) -> aux (cons y acc) ys
in