Skip to content

Instantly share code, notes, and snippets.

View foota's full-sized avatar

Noriyuki Futatsugi foota

View GitHub Profile
@foota
foota / partitions.cpp
Created May 14, 2012 18:16
Integer partitions
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
void partitions(int n, int max_n, vector<int>& v, vector<vector<int> >& vv)
{
if (n == 0) {
@foota
foota / y_combinator.cpp
Created May 14, 2012 18:14
Y combinator
#include <iostream>
#include <functional>
using namespace std;
// Y-combinator for the int type
function<int(int)> y(function<int(function<int(int)>, int)> f)
{ return bind(f, bind(&y, f), placeholders::_1); }
int main()
@foota
foota / tw_oauth_ase.py
Created May 14, 2012 18:13
Twitter client using OAuth for Android devices
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, pickle, time, android
from oauthtwitter import *
CONSUMER_KEY = "CONSUMER_KEY"
CONSUMER_SECRET = "CONSUMER_SECRET"
KEY_FILE = "/sdcard/ase/scripts/twitter_key.dat"
@foota
foota / CellularAutomaton.as
Created May 14, 2012 18:10
Cellular Automaton
// CellularAutomaton.as
// by nox, 2010.7.9
// http://handasse.blogspot.com/
/*
1-9 : ルール設定 - セルの周りの生存セル数(0-8)に対応
: '.' 死亡, '&' 変化, '+' 誕生, '=' 維持
SPACE : 一時停止
ENTER : リセット
V : メッセージ表示/非表示
@foota
foota / sudoku_solver_oneliner.py
Created May 14, 2012 18:08
Sudoku solver (oneliner)
import sys;L=[];S=lambda D:(0in D)and[L.append(D.index(0)),[(D.__setitem__(L[-1],i),S(D),D.__setitem__(L.pop(),0))for i in set(range(1,10))-set(D[L[-1]/9*9:L[-1]/9*9+9]+D[L[-1]%9:81:9]+[d for n in(0,1,2)for d in D[L[-1]/27*27+L[-1]%9/3*3+n*9:L[-1]/27*27+L[-1]%9/3*3+n*9+3]])]]or([sys.stdout.write('%d'%d+('\n'if i%9==8 else' '))for i,d in enumerate(D)],sys.exit());S([int(c)if c!='.'else 0for c in'..53.....8......2..7..1.5..4....53...1..7...6..32...8..6.5....9..4....3......97..'])
@foota
foota / sieve.cpp
Created May 14, 2012 18:07
Sieve of Eratosthenes
std::vector<int> primes;
for (int i = 3; i < 100; i += 2) primes.push_back(i);
auto end = primes.end();
for (auto x = primes.begin(); *x * *x <= *(end-1); ++x)
end = std::remove_if(x + 1, end, [&x](int p){ return p % *x == 0; });
primes.erase(end, primes.end());
for (auto p = primes.begin(); p != primes.end(); ++p) std::cout << *p << " ";
std::cout << std::endl;
@foota
foota / sudoku_solver.py
Created May 14, 2012 18:05
Sudoku solver for Android devices (SL4A)
# -*- coding: utf-8 -*-
import sys,android
droid=android.Android()
L=[]
def S(D):
if 0 in D:
L.append(D.index(0))
@foota
foota / remote_camera.py
Created May 14, 2012 18:03
Remote camera using Android devices (SL4A)
import android
from wsgiref.simple_server import make_server
droid=android.Android()
pic='/sdcard/snapshot.jpg'
def camera(env,res):
if env['PATH_INFO']=='/':
droid.cameraCapturePicture(pic)
res('200 OK',[('Content-type','image/jpeg')])
@foota
foota / android_bbs.py
Created May 14, 2012 18:02
BBS on Android devices (SL4A)
# -*- coding: utf-8 -*-
import cgi,sqlite3,datetime
from wsgiref.simple_server import make_server
LIMIT=50 # 最大表示記事数.
DB_FILE='/sdcard/bbs.sqlite'
con=sqlite3.connect(DB_FILE)
cur=con.cursor()
@foota
foota / fake_japanese.py
Created May 14, 2012 18:00
SL4A speaks in Japanese
# -*- coding: utf-8 -*-
import android
import sys,os,urllib,urllib2,simplejson
from BeautifulSoup import BeautifulSoup
YAHOO_APP_ID='Yahoo!デベロッパーネットワークのアプリケーションID'
KEITAISO_API='http://jlp.yahooapis.jp/MAService/V1/parse?appid=%s&results=ma&sentence=%s'
KANA=[u'きゃ',u'きぃ',u'きゅ',u'きぇ',u'きょ',