Skip to content

Instantly share code, notes, and snippets.

View uchida's full-sized avatar

Akihiro Uchida uchida

View GitHub Profile
@uchida
uchida / gist:949753
Created April 30, 2011 15:34
crontab format
# crontab format
# * * * * * command to be execute
# | | | | +---- day of week (0 - 6) (Sunday = 0 or 7) or sun, mon, ..., sat
# | | | +------ month (1 - 12) or jan, feb, ..., dec
# | | +-------- day of month (1 - 31)
# | +---------- hour (0 - 23)
# +------------ minute (0 - 59)
# special string
# string meaning
# ------ -------
@uchida
uchida / bookmark.py
Created April 30, 2011 21:50
bookmark script for newsbeuter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# bookmark script for newsbeuter
# by Akihiro Uchida, CC0 dedicated to the public domain
# see http://creativecommons.org/publicdomain/zero/1.0/
import sys
import os.path
import cPickle as pickle
BOOKMARK = os.path.expanduser('~/newsbeuter/bookmark.pkl')
@uchida
uchida / open_nt.sh
Created April 30, 2011 21:55
open url in Safari with new Tab
#!/bin/sh
osascript -e "tell application \"Safari\"
tell window 1
set current tab to (make new tab)
set currenttab to open location \"$@\"
end tell
end tell"
@uchida
uchida / ndindex.py
Created May 20, 2011 10:40
a portable and compact version of numpy.ndindex
import functools, operator
prod = functools.partial(functools.reduce, operator.mul)
def ndindex(maxvals):
total = prod(maxvals)
index = [0] * len(maxvals)
for _ in range(total):
yield tuple(index)
for i, n in enumerate(reversed(maxvals)):
index[-i-1] += 1
if index[-i-1] < n:
@uchida
uchida / gist:1285408
Created October 13, 2011 20:26
Tokyo.Scipy#2 ディスカッション事前アンケート3
# -*- coding:utf8 -*-
# Tokyo.Scipy#2 ディスカッション事前アンケート
# http://www.surveymonkey.com/s/XJ2KNBW
#
# 3. nanやInfを含む値の列
# x = numpy.array([[1,0,nan,1,Inf,1,....]])
# が与えられたとき、
# NaNやInf以外のxの要素の合計を計算する方法が直ぐに思い浮かびますか?
from numpy import array
@uchida
uchida / gist:1285419
Created October 13, 2011 20:29
Tokyo.Scipy#2 ディスカッション事前アンケート4
# -*- coding:utf8 -*-
# Tokyo.Scipy#2 ディスカッション事前アンケート
# http://www.surveymonkey.com/s/XJ2KNBW
#
# 4. nanを含む4x2行列
# m = numpy.array([[1,nan,-1,0],[0,0,nan,1]])
# が与えられたとき、
# nanを含む行を削除して2x2行列にする方法が直ぐに思い浮かびますか?
from numpy import array
@uchida
uchida / gist:1285432
Created October 13, 2011 20:31
Tokyo.Scipy#2 ディスカッション事前アンケート5
# -*- coding:utf8 -*-
# Tokyo.Scipy#2 ディスカッション事前アンケート
# http://www.surveymonkey.com/s/XJ2KNBW
#
# 5. numpy.array([[1,3,2]]) を、1-of-K表記法変換して
# numpy.array([[1,0,0],[0,0,1],[0,1,0]])
# にする処理方法が直ぐに思い浮かびますか?
from numpy import array, zeros
@uchida
uchida / enumerate.cs
Created November 28, 2011 13:55
C# sample code for equivalent of python enumerate()
// GWLlosa's answer in http://stackoverflow.com/questions/521687/c-sharp-foreach-with-index
using System;
using System.Collections.Generic;
using System.Linq;
namespace EnumerateTest {
class Program {
static void Main(string[] args) {
List<int> list = new List<int> {4, 2, 3, 1, 8};
@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>();