Skip to content

Instantly share code, notes, and snippets.

@kinoh
kinoh / linear.js
Created April 1, 2014 17:03
math.js extension for linear algebra
function mathjsEx()
{
var math = mathjs()
math.EPSILON = 1E-15
dot = function (x, y) { return math.subset(math.multiply(math.transpose(x), y), math.index(0, 0)) }
norm = function (x) { return math.sqrt(dot(math.conj(x), x)) }
diagBlock = function (A, B)
{
@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 / set
Created January 21, 2014 14:39
Set theory
Parameter set: Type.
Parameter uniqueObject: (set -> Prop) -> set.
Axiom UniqueObject: forall P, (exists! x, P x) -> P (uniqueObject P).
Parameter in_: set -> set -> Prop.
Axiom ZF_Ext: forall X Y, (forall z, in_ z X <-> in_ z Y) -> X = Y.
Axiom ZF_Pair: forall x y, exists Z, in_ x Z /\ in_ y Z.
Axiom ZF_Sep: forall P: set -> Prop, forall X,
@kinoh
kinoh / waitAny.fs
Created October 21, 2013 14:18
Wait for any succeeded task.
module Test
open System.IO
open System.Threading
open System.Threading.Tasks
let R = System.Random()
let _work (n : int) : int option =
Thread.Sleep (n * 1000)
if R.Next() % 3 = 0
@kinoh
kinoh / TypeCast.cs
Created October 9, 2013 16:52
Cast an object variable array to the array of the type specified by a Type variable in C#.
using System;
using System.Collections;
using System.Linq;
public class Test
{
public static T[] ConvArray<T>(object[] array)
{
return array.Cast<T>().ToArray();
}
@kinoh
kinoh / ISBNReader.cs
Created October 8, 2013 02:16
Simple ISBN bar code reader with OpenCVSharp and ZXing.Net.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using OpenCvSharp;
using ZXing;
namespace ISBNReader
{
static class Program
@kinoh
kinoh / twitter.cs
Last active December 24, 2015 01:29
UserStrem with LINQ to Twitter.
using System;
using System.Collections.Generic;
using System.Linq;
using LinqToTwitter;
using LitJson;
namespace TwitterConsole
{
class Program
{
@kinoh
kinoh / wavwriter.c
Created July 6, 2013 16:19
Convert gnuplot-like text data to wave format.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROW_SIZE 1024
char header[44] = {
'R', 'I', 'F', 'F',
0, 0, 0, 0,
'W', 'A', 'V', 'E',