Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
export DISPLAY=:0
Xvfb -screen 0 1280x1024x24 > /dev/null 2> /dev/null &
sleep 5
fluxbox > /dev/null 2> /dev/null &
@hktechn0
hktechn0 / replace_htmlentity.py
Created November 6, 2009 15:11
Replace HTML character entity reference
import re
import htmlentitydefs
def replace_htmlentity(string):
amp = string.find('&')
if amp == -1:
return string
entity = re.compile("&([A-Za-z]+);")
entity_match = entity.findall(string)
@hktechn0
hktechn0 / is_ascii.py
Created November 10, 2009 16:58
isascii() on Python
def isascii(c, printable = False):
if 0x00 <= ord(c) <= 0x7f:
if printable:
if 0x20 <= ord(c) <= 0x7e:
return True
else:
return False
else:
return True
else:
@hktechn0
hktechn0 / convert_utf8_to_unicode.py
Created November 10, 2009 17:01
Convert int or long UTF-8 code to Unicode character on Python.
def utf2ucs(utf):
if utf & 0x80:
# multibyte
buf = []
while not(utf & 0x40):
buf.append(utf & 0x3f)
utf >>= 8
buf.append(utf & (0x3f >> len(buf)))
ucs = 0
@hktechn0
hktechn0 / post_status.py
Created November 24, 2009 21:01
Test script of impersonation from ~ on twitter
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import twitter
#==============================
# Settings
USER = ""
PASS = ""
#==============================
@hktechn0
hktechn0 / oauth.py
Created November 25, 2009 20:01
Twitter OAuth Sample Script
import time, random
import urllib, urllib2
import hmac, hashlib
import cgi
#
# Twitter OAuth Sample Script
# * techno - Hirotaka Kawata
# * http://techno-st.net/
#
@hktechn0
hktechn0 / newinput.py
Created November 27, 2009 17:58
curses multibyte input method for Python
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import curses
def mbgetstr(stdcur, sety, setx, debug = False):
s = u""
i = 0
curses.noecho()
@hktechn0
hktechn0 / oauth-twitter.py
Created December 2, 2009 14:51
OAuth for Twitter
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import time, random
import urllib, urllib2
import hmac, hashlib
import cgi
#
# OAuth Module for Twitter
@hktechn0
hktechn0 / print_dict.py
Created December 7, 2009 07:10
print dict for python
#!/usr/bin/env python
def print_dict(dic, h = ""):
print "%s{" % h
for d in dic:
print " %s%s\t:" % (h, d),
if isinstance(dic[d], dict):
print ""
print_dict(dic[d], h + " ")
else:
#!/usr/bin/env python
def test1(id, **kwargs):
print id, kwargs
def test2(*args, **kwargs):
print args
print kwargs
def test3(id, name, mail,