Skip to content

Instantly share code, notes, and snippets.

@whosaysni
whosaysni / gist:5237182
Last active December 15, 2015 09:19
argparseをちょろっと翻訳。
# coding: utf-8
from gettext import NullTranslations
import argparse, sys
argparse.str = lambda s: s.encode(sys.stdout.encoding) if isinstance(s, unicode) else s
CATALOGUE = dict([
('usage: ',
u'使い方: '),
@whosaysni
whosaysni / fetch_issues.py
Created June 7, 2013 05:32
Fetching issues feed from GoogleCode hosted project.
# coding: utf-8
import os
import sys
import urllib
import tarfile
import time
from xml.etree import ElementTree as ET
from StringIO import StringIO
@whosaysni
whosaysni / gist:5733660
Created June 8, 2013 02:17
Hello world with Xlib.
/*
hellox -- Hello world with Xlib.
$(CC) -o hellox hellox.c -lX11 -L/usr/X11/lib
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@whosaysni
whosaysni / gist:5733681
Created June 8, 2013 02:22
hello and farewell pthread
/*
pthtest --- hello pthread.
gcc -pthread -o pthtest pthtest.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@whosaysni
whosaysni / gist:5733769
Created June 8, 2013 02:43
Yoshinoya Merlin/吉野家マーリン
import win32com.client, time, binascii
Agent = win32com.client.Dispatch("Agent.Control.2")
Agent.Connected = 1
Agent.Characters.Load("Merlin", "C:\WINDOWS\MSAGENT\CHARS\MERLIN.ACS")
Merlin = Agent.Characters("Merlin")
Merlin.Show()
bdat = [ \
@whosaysni
whosaysni / gist:5733902
Created June 8, 2013 03:31
外字領域から256文字
# coding: utf-8
import sys
offset = 0xe000
sys.stdout.write(('|'.join([unichr(offset+i) for i in range(256)])).encode('utf-8'))
@whosaysni
whosaysni / gist:5733994
Created June 8, 2013 04:03
wx.GenericDirCtrl usage
# coding: utf-8
import wx
class MyDirCtrl(wx.GenericDirCtrl):
def __init__(self, *args, **kwargs):
wx.GenericDirCtrl.__init__(self, *args, **kwargs)
tree = self.GetTreeCtrl()
tree.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnTreeExpanded)
@whosaysni
whosaysni / gist:5749644
Last active December 18, 2015 07:49
とこちゃんはどこ
# coding: utf-8
"""とこちゃんはどこ
"""
from random import choice, randrange
import random, sys
s = ["と", "こ", "ち", "ゃ", "ん"]
def tokochan(width, height):
@whosaysni
whosaysni / force_etree_ns
Created July 4, 2013 05:46
Forcing ElementTree to serialize extra namespaces
# coding: utf-8
"""
To parse XML with namespaces using ElementTree, keeping namespace prefix, you will need register_namespace.
>>> from xml.etree.ElementTree import register_namespace, fromstring, tostring
>>> base_ns = {
... 'http://example.com/article': 'article',
... 'http://example.com/report': 'report',
... 'http://example.com/book': 'book',
@whosaysni
whosaysni / gist:7685186
Created November 28, 2013 00:02
HTTP digest auth client for Catalyst
# do HTTP digest login
sub digest_login_request {
my ($schema, $username, $pw_override) = @_;
my $res = request('/login');
my %digest_hdr = map {
my @key_val = split /=/, $_, 2; # /
$key_val[0] = lc $key_val[0];
$key_val[1] =~ s{"}{}g; # remove the quotes
@key_val;
} split /,\s?/, substr( $res->header('WWW-Authenticate'), 7 ); #/;