Skip to content

Instantly share code, notes, and snippets.

View uchida's full-sized avatar

Akihiro Uchida uchida

View GitHub Profile
@uchida
uchida / indexsort.cs
Created November 28, 2011 13:59
C# sample code for index based sort
// Guffa's answer in http://stackoverflow.com/questions/659866/is-there-c-sharp-support-for-an-index-based-sort
using System;
using System.Collections.Generic;
using System.Linq;
namespace IndexSortTest {
class Program {
static void Main(string[] args) {
List<int> list = new List<int> {4, 2, 3, 1, 8};
int N = list.Count;
@uchida
uchida / shuffle.cs
Last active September 28, 2015 07:58
C# sample code for the random permutation generation of finite set
// the Fisher–Yates shuffle algorithm
// see http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
using System;
using System.Collections.Generic;
using System.Linq;
namespace ShuffleTest {
class Program {
static void Main(string[] args) {
List<int> shuffled = ShuffleRange(0, 10).ToList<int>();
@uchida
uchida / primes.py
Created February 1, 2012 13:44
naive prime numbers generator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from itertools import count, takewhile, islice
def primes():
yield 2
primes = [2]
for i in count(3, step=2):
if all(i % prime != 0 for prime in primes):
@uchida
uchida / primes.py
Created February 1, 2012 13:45
prime numbers generator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from itertools import count, takewhile, islice
def primes():
yield 2
yield 3
primes = [2, 3]
for i in count(start=5, step=6):
@uchida
uchida / gist:1759930
Last active September 30, 2015 09:28
latexmkrc sample for Japanese LaTeX documents
# -*- cperl -*-
# ~/.latexmkrc
# setting for pdflatex
$pdflatex = 'pdflatex -8bit -etex -halt-on-error -synctex=1 %O %S';
# setting for Japanese
$latex = 'platex -synctex=1 -halt-on-error %O %S';
$bibtex = 'pbibtex %O %B';
$makeindex = 'mendex %O -o %D %S';
$dvipdf = 'dvipdfmx %O -o %D %S';
# use bibtex as default
@uchida
uchida / snippet.py
Last active October 1, 2015 09:38
convert snippet file for neosnippet into snippet files for yasnippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# convert snippet file for neosnippet into snippet files for yasnippet
# by Akihiro Uchida, CC0 dedicated to the public domain
# see http://creativecommons.org/publicdomain/zero/1.0/
import argparse
import os.path
import textwrap
YASNIPPET_TEMPLATE = """# -*- mode: snippet -*-
@uchida
uchida / showfonts.py
Created March 3, 2012 11:18
show available font names for matplotlib
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os.path
from matplotlib import get_configdir
import pickle
fpath = os.path.join(get_configdir(), 'fontList.cache')
with open(fpath, 'r') as f:
fontmgr = pickle.load(f)
for fontentry in fontmgr.ttflist:
@uchida
uchida / replicate.bash
Created June 13, 2012 04:01
A replication script for ZFS
#!/usr/bin/env bash
# coding: utf-8
# A replication script for ZFS
# by Akihiro Uchida, CC0 dedicated to the public domain
# see http://creativecommons.org/publicdomain/zero/1.0/
usage="usage: $(basename $0) [-v] src dst"
die() {
echo "$@" >&2
exit 1
@uchida
uchida / rotate.bash
Last active October 6, 2015 02:47
A ZFS snapshots rotation script
#!/usr/bin/env bash
# A ZFS snapshots rotation script
# by Akihiro Uchida, CC0 dedicated to the public domain
# see http://creativecommons.org/publicdomain/zero/1.0/
usage="usage: $(basename $0) [-v] filesystem generation"
die() {
echo "$@" >&2
exit 1
}
@uchida
uchida / load_complex.py
Created September 6, 2012 06:54
sample shot how to load from the complex number array saved with iostream such as (x, y) for x + y i by numpy.loadtxt
import sys
import numpy
array = numpy.loadtxt("test.npy", converters={0: lambda s: eval(s)}).view(complex).reshape(-1)
print array