Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / alc.py
Created January 23, 2010 11:37
[python] Look up words from JP/EN Dictionary of Eijiro on the WEB
#!/usr/bin/env python2.6
# -*- mode: python coding: utf-8 -*-
"""Look up words from JP/EN Dictionary of Eijiro on the WEB
Third party libs:
- `httplib2`
- `pyquery`
- `lxml`: required by pyquery
"""
from optparse import OptionParser
@bellbind
bellbind / xorg.conf
Created January 23, 2010 11:50
[virtualbox] /etc/X11/xorg.conf for virtualbox guest ubuntu lucid x86/amd64
# /etc/X11/xorg.conf for virtualbox guest ubuntu lucid x86/amd64
Section "Device"
Identifier "VirtualBox Video Card"
Driver "vboxvideo"
EndSection
Section "InputDevice"
Identifier "VBoxMouse"
Driver "vboxmouse"
Option "CorePointer"
@bellbind
bellbind / relimporter.py
Created July 26, 2010 14:33
[python] __import__ by relative module style
def import_as(module_name, globals_):
"""__import__ for relative module style.
usage:
mod = import_as("..templates.jinja2", globals())
# it is same as: import ..templates.jinja2 as mod
"""
level = 0
for ch in module_name:
if ch != ".": break
level += 1
@bellbind
bellbind / python-mode-with-stable-indent.el
Created August 10, 2010 18:40
[emacs] stable indent for python-mode.el or progmodes/python.el
;;; Make fixed TAB indent level for python mode
(add-hook
'python-mode-hook
'(lambda ()
(defun my-indent-line (&optional arg)
"modeless indent for python indentation"
(interactive "P")
(let ((old-this-command this-command))
(setq this-command t)
(cond
@bellbind
bellbind / ls2ts.py
Created August 12, 2010 17:12
[python] convert list of list to trees
"""ls2ts: list of list to trees
>>> tree = ls2ts([["a", "b", "c"],
... ["a", "c"]])
>>> result = [tn("a", [tn("b", [tn("c", [])]),
... tn("c", [])])]
>>> tree == result
True
"""
@bellbind
bellbind / Caps2RCtrl.cs
Created August 20, 2010 17:38
[c#] set CapsLock key to send RCtrl code for Windows7
using Microsoft.Win32;
using System.Collections.Generic;
// set CapsLock key to send RCtrl code for Windows7
// usage: execute this as Administrator, then log-off
class Caps2RCtrl {
static void Main(string[] args) {
List<byte> bytes = new List<byte>();
bytes.AddRange(System.BitConverter.GetBytes(0)); // alwats 0
bytes.AddRange(System.BitConverter.GetBytes(0)); // always 0
@bellbind
bellbind / microdata.py
Created September 13, 2010 10:42
[python] HTML5 microdata parser
"""HTML5 microdata parser for python 2.x/3.x
- it requires lxml
- microdata specification: http://dev.w3.org/html5/md/
"""
try: from urllib.parse import urljoin
except: from urlparse import urljoin
import lxml.html as lhtml
def items(html, types=None, uri=""):
@bellbind
bellbind / MathMLClip.cs
Created October 18, 2010 02:25
[c#][windows7]Print MathML clipboard data from Windows7 accessory "Math Input Panel"
// Print MathML clipboard data from Windows7 accessory "Math Input Panel"
// compile: csc MathMLClip.cs
// usage: run the command after pressed "Insert" button on MIP
using System;
//using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
@bellbind
bellbind / xetex-jp-example.tex
Created November 5, 2010 13:55
[tex]Japanese document for xelatex
We couldn’t find that file to show.
@bellbind
bellbind / dblatex-0.3-win32-makeindex.patch
Created November 7, 2010 09:25
[patch] dblatex-0.3 to use relative path for windows MiKTeX2.9 makeindex
diff -urN dblatex-0.3/lib/dbtexmf/dblatex/grubber/index.py dblatex-0.3-win32/lib/dbtexmf/dblatex/grubber/index.py
--- dblatex-0.3/lib/dbtexmf/dblatex/grubber/index.py 2010-04-05 09:07:53.000000000 +0900
+++ dblatex-0.3-win32/lib/dbtexmf/dblatex/grubber/index.py 2010-11-07 18:20:08.084692400 +0900
@@ -114,14 +114,16 @@
msg.progress(_("processing index %s") % self.source)
if self.tool == "makeindex":
- cmd = ["makeindex", "-o", self.target] + self.opts
- cmd.extend(["-t", self.transcript])
+ cwd = dirname(self.target)