Skip to content

Instantly share code, notes, and snippets.

@kinoh
kinoh / give_bom.ps1
Created November 3, 2017 14:27
Give BOM to all the source files.
foreach($i in Get-ChildItem -Recurse) {
if ($i.PSIsContainer) {
continue
}
# You might need some more pattern
if ($i.FullName -like "*.cc" -or $i.FullName -like "*.h") {
echo $i.FullName
$tmp = $i.FullName + ".tmp"
get-content -Encoding UTF8 $i.FullName | set-content -Encoding UTF8 $tmp
@kinoh
kinoh / csv2wav.py
Created September 3, 2017 03:53
Convert csv/tsv to wav file
import argparse
import csv
import os
import struct
import wave
parser = argparse.ArgumentParser(description="Convert csv to wav.")
parser.add_argument("csv", help="csv file")
parser.add_argument("data", type=int, help="zero-based index of data row")
parser.add_argument("-f", dest="freq", metavar="SAMPLING_RATE", type=int, default=44100, help="sampling rate")
var grammar = `
Expression
= Scalar
/ GeneralVectorExpr
GeneralVectorExpr
= head: GeneralVector tail: (_ ("+" / "-") _ GeneralVector) * {
return head;
}
@kinoh
kinoh / range.fst
Created February 22, 2015 14:01
Fstar says "An unknown assertion in the term at this location was not provable"?
module Range
val length: list 'a -> Tot nat
let rec length l =
match l with
| [] -> 0
| _::tl -> 1 + length tl
val range: a:nat -> b:nat -> Tot (list nat)
(decreases (b-a))
@kinoh
kinoh / foldl.fst
Created February 21, 2015 09:35
F* tutorial : Exercise 4f
(* https://www.fstar-lang.org/tutorial/ *)
module FoldLeft
val append : list 'a -> list 'a -> Tot (list 'a)
let rec append l1 l2 = match l1 with
| [] -> l2
| hd :: tl -> hd :: append tl l2
val reverse: list 'a -> Tot (list 'a)
let rec reverse = function
@kinoh
kinoh / SourceSite.xml
Created October 4, 2014 10:55
scraping parameters
<?xml version="1.0" encoding="utf-8" ?>
<Site Uri="http://www.kinokuniya.co.jp/f/dsg-01-" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Preprocess xsi:type="Replace" Old="liitemprop" New="li itemprop"/>
<Field Name="Title" Path="//h3[@itemprop='name']/text()[last()]" Pattern=".+"/>
<Field Name="Label" Path="//h3[@itemprop='name']/text()[position()!=last()]" Pattern=".+"/>
<Field Name="Authors" Path="//div[contains(@class,'infobox')]/ul/li[1]" Pattern="(?'name'[^/【】〈〉]+)(?=(?:〈(?'spell'[^〈〉]+)〉)?(?:/[^【]+)*【(?'role'[^】]+)】(?:〈(?'spell'[^〈〉]+)〉)?|$)"/>
<Field Name="Publisher" Path="//div[contains(@class,'infobox')]/ul/li[count(./a)>0][last()]/a" Pattern=".+"/>
<Field Name="Published" Path="//div[contains(@class,'infobox')]/ul/li[4]" Pattern="(?'year'\d{4})/(?'month'\d{2})発売"/>
<Field Name="Size" Path="//div[contains(@class,'infbox')]/ul/li[1]" Pattern="サイズ (.+?)/"/>
<Field Name="Page" Path="//div[contains(@class,'infbox')]/ul/li[1]" Pattern=
@kinoh
kinoh / KaleidoScope.cs
Created August 3, 2014 12:44
LLVM & Irony in C#
using System;
using System.Collections.Generic;
using System.Linq;
using Irony.Parsing;
using LLVM;
namespace KaleidoScope
{
[Language("KaleidoScope")]
public class KaleidoScopeGrammar : Grammar
@kinoh
kinoh / wrapper.pl
Last active August 29, 2015 14:04
LLVM wrapper generator
use strict;
my $file = $ARGV[0];
my @data = ();
my @cast_types = ("AtomicOrdering", "SynchronizationScope", "BinOp", "BinaryOps", "Predicate", "OtherOps");
my @prim_types = ("bool", "unsigned", "unsigned short", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "int8_t", "int16_t", "int32_t", "int64_t", "float", "double");
unlink "$file.h";
unlink "$file.cpp";
@kinoh
kinoh / gauss_elim
Created July 18, 2014 15:39
Gauß Elimination
A: {1..m} * {1..n} -> Field
for i in {1..m-1}
k = max(k => abs(A[k,i]), {i..m})
A = swap(A, i, k)
for j in {i+1..m}
A[j] -= (A[j,1] / A[i,1]) * A[i]
@kinoh
kinoh / algebra12_1.tex
Last active August 29, 2015 14:03
体 F 上の n 次行列環 R = M(n,F) に於いて左零因子と右零因子は同値である
$ A \in R $を左零因子とすると、ある$ B \in R \setminus \{0\} $が存在して$ AB = 0 $が成り立つ。
このとき$A$が可逆とすると$ A^{-1}AB = B = 0 $となり矛盾するから$ \det(A) = 0 $である。
$A$が右零因子の場合も同様にして$ \det(A) = 0 $である。
一方$ A \in R $について$ \det(A) = 0 $とすると、Gau\ss 消去により$ EA $の第$n$行が全て$0$となる様な基本行列$ E \in R $が存在する。
ここで更に$ B = \left( \begin{array}{c|c} O_{n-1} & 0 \\ \hline 0 & 1 \end{array} \right) $とおくと$ BEA = 0 $であり、基本行列は可逆なので$ \det(E) \ne 0 $より全て$0$の行は存在しない、よって特に$ n-1 $行には$0$でない要素が存在し$ BE \ne 0 $である。
故に$A$は右零因子である。
同様にGau\ss 消去を右基本変形で行えば$ \det(A) = 0 $のとき$A$が左零因子である事が分かる。
以上より$ A \in R $が左零因子である事と右零因子である事は同値である。