Skip to content

Instantly share code, notes, and snippets.

View qnighy's full-sized avatar

Masaki Hara qnighy

View GitHub Profile
@qnighy
qnighy / rust-patterns.md
Last active March 6, 2025 19:03
Rustのパターンっぽいやつメモ

パターンとはその言語が抽象化できなかった敗北の歴史である。 しかしどんなに優れた言語であってもあらゆる繰り返しに勝てるわけではない。 人は必ずメタ繰り返しを欲するからだ。 そしてそれはRustも例外ではない。

ここでは、OOPでも知られているパターンよりも、Rustに特有のパターンを思いつく限りまとめてみた。名前は適当。

  • crate splitting
    • でかいcrateを分割して、見通しを良くする・再コンパイルの分量を削減する・並列コンパイルを可能にする
  • 親玉crate(全てにdependする)と殿crate(全てにdependされる)があることが多いので、だいたい束みたいな形になる。
@qnighy
qnighy / normalforms.md
Last active February 9, 2025 17:57
いろいろな標準形

Jordan標準形 (Jordan normal form)

K:代数閉体, V:有限次元のK-線形空間, f : V → V 線形写像のとき、Vの基底を上手く選ぶと表現行列がJordanブロックを対角線上に並べた行列になる。

この標準形はJordanブロックの順列を除いて一意である。

計算方法1: 固有方程式を解き固有値を得る。(A-λI)x=0となるxを探す。(A-λI)y=xとなるyを探す。これを止まるまで繰り返すことで基底の一部が得られる。別の固有ベクトルや別の固有値に対しても同様のことを行う。

有理標準形 (Frobenius normal form)

@qnighy
qnighy / ruby-syntaxes.md
Last active January 3, 2025 08:33
Ruby syntaxes

Program-global

  • # frozen_string_literal
  • # encoding
  • __END__

Expressions

  • Singleton literals
  • nil
// この方法ならunwrap()もしなくてすむのではなかろうか
#[derive(Debug)]
struct Person {
id: u32,
name: String,
age: u32,
address: Option<String>,
zipcode: Option<String>,
}
@qnighy
qnighy / CBS.v
Created July 30, 2016 02:41
Cantor-Bernstein-Schroeder in Coq
Require Import Coq.Logic.ClassicalUniqueChoice.
(* Cantor-Bernstein-Schroeder *)
(* If there are injections between A and B bidirectionally,
A and B are isomorphic. *)
Theorem Bernstein: forall(A B:Type) (f:A->B) (g:B->A),
(forall a0 a1, f a0 = f a1 -> a0 = a1) ->
(forall b0 b1, g b0 = g b1 -> b0 = b1) ->
exists f : A -> B, exists g : B -> A,
(forall a, g (f a) = a) /\ (forall b, f (g b) = b).
@qnighy
qnighy / pqsieve.cpp
Created July 14, 2010 04:35
Eratosthenes' sieve in Haskell and Data.Map.Map
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int main(int argc, char **argv) {
priority_queue<pair<int,int> > pq;
printf("%d\n", 2);
pq.push(make_pair(-4, 2));
for(int i = 2; i < 100; ) {
@qnighy
qnighy / majority.rs
Created July 15, 2024 06:32
Fast 2-pass majority finder
// Copyright 2024 Masaki Hara
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE O

SATySFi構文メモ (2018/02/23)

SATySFiの字句解析器には主要なモードが4つある:

  • プログラムモード
  • 垂直モード
  • 水平モード
  • 数式モード

またサブモードとして

@qnighy
qnighy / PC98ext.md
Last active May 10, 2024 11:21
PC-9800シリーズ機種依存文字 (JIPS由来文字) 9区~12区

PC-9800シリーズ機種依存文字 (JIPS由来文字) 9区~12区

「NEC特殊文字」として有名な13区は標準化もされていて資料が豊富であるため省略。

字形のソースは http://www.kt.rim.or.jp/~aotaka/pc/character.htm

9区

2バイト半角英数。 JIS X 0201 ラテン文字集合に近いが、形状から考えて別の文字を指している可能性のある符号位置がある。

UI-OSF-USLP 共同技術資料 日本語EUCの定義と解説
日本語 EUC の定義