Skip to content

Instantly share code, notes, and snippets.

View uchan-nos's full-sized avatar

Kota UCHIDA uchan-nos

View GitHub Profile
@uchan-nos
uchan-nos / gen.py
Created September 4, 2012 08:49
generator for generator (one liner prime generator example)
def gen(init, ret, next):
while True:
yield ret(init)
init = next(init)
def myfor(iter, n):
a = []
for i, x in enumerate(iter):
if i == n:
break
@uchan-nos
uchan-nos / timer.py
Created October 3, 2012 01:47
OS X Mountain Lionの通知センターをPythonから使う
import pyNotificationCenter as nc
import sys
def runtimer(objective):
nc.notify('25 min timer started', None, objective, delay=0, sound=False)
nc.notify('25 min timer timeup', None, objective, delay=10, sound=True)
def makelogtemplate(objective):
import datetime
import locale
def str_collection(obj):
if isinstance(obj, list):
if len(obj) > 0:
result = ['[', str(obj[0])]
for o in obj[1:]:
result.append(', ')
result.append(o.__str__())
result.append(']')
return ''.join(result)
return obj.__str__()
url = 'http://toi.kuronekoyamato.co.jp/cgi-bin/tneko'
data = {
'number00' : '1',
'number01' : '000000000000'
}
data_e = urllib.parse.urlencode(data)
req = urllib.request.Request(url, data_e.encode('sjis'))
res = urllib.request.urlopen(req)
soup = BeautifulSoup(res.read())
# -*- coding: utf-8 -*-
import time
def separate_variations2(lst):
n = len(lst)
assert n >= 2
for bitpattern in xrange(1, 2 ** (n - 1)):
x = list()
@uchan-nos
uchan-nos / bootpack.ld
Created January 2, 2014 08:21
GNU LD linker script for BitNOS (HariboteOS-like operating system)
OUTPUT_FORMAT("binary")
ENTRY(KernelMain)
HEAP_SIZE = 0;
MMAREA_SIZE = 0;
__ctors = ADDR(.ctors);
__ctors_count = SIZEOF(.ctors) / 4;
SECTIONS
template <typename T, typename U, typename ... ApiArgs, typename ... Args>
T ExitOnWrongValue0(const U& expected, const char* api_name, T (api_exp)(ApiArgs...), Args... args)
{
T x = api_exp(args...);
if (x != expected)
{
std::cout << api_name << " Error: " << std::endl;
exit(1);
}
return x;
#include <iostream>
using namespace std;
// {{{
constexpr int get_hash(int hash, const char* p)
{
return *p == '\0' ? hash : get_hash(*p * 137, p + 1);
}
template <typename T, int N>
#include <iostream>
#include <utility>
#include <string>
using namespace std;
// {{{
struct ListTerminator
{
};
const ListTerminator NIL {};
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
using namespace std;