Skip to content

Instantly share code, notes, and snippets.

View sgk's full-sized avatar

Shigeru KANEMOTO sgk

  • Switch Science /144Lab
  • Tokyo / Osaka
View GitHub Profile
//
// Export the EAGLE cream layers to DXF for the Craft-ROBO cutting plotter.
//
// Copyright (c) 2010 Switch Science, Inc.
//
// Type "run cream-dxf" in the board editor window.
// Options:
// -o Add one more line segment for pads to make sure the cut.
// -c Cut off corners of pads. The resulting pads are octagons.
//
#include <LiquidCrystal.h>
/*
*
* Config
*
*/
#define BUTTON 3
#define HEATER 9
#define SENSOR 10
@sgk
sgk / xmlobj.py
Created December 9, 2010 15:44
Simple to use XML parser
import xml.sax.handler
import xml.sax
class Node(object):
def __init__(self, name=None, attrs=None):
self.name_ = name
self.attrs_ = attrs
self.dict_ = {}
self.str_ = ''
@sgk
sgk / fix-id3.py
Created March 31, 2011 15:43
ID3タグにダメなエンコーダソフトがつっこんだ、SJIS文字列を修正する。 eyeD3を使用 http://eyed3.nicfit.net/
#vim:fileencoding=utf-8
#
# 古いMP3エンコードソフトを使った時、
# ID3タグにSJIS文字列が入っているのを修正する。
#
# エンコーディングがLatin-1なのにSJISらしき物を修正。
#
# 2011-3-31 Shigeru KANEMOTO
# Public Domain
#
@sgk
sgk / tzconv.py
Created May 29, 2011 14:44
Timezone conversion
# by sgk
import datetime
class TZ(datetime.tzinfo):
def __init__(self, name, offset):
self.name_ = name
self.offset_ = offset
def utcoffset(self, dt):
return datetime.timedelta(hours=self.offset_)
@sgk
sgk / trac2down.py
Created October 14, 2011 09:35
Trac Wiki to Markdown converter
#!/usr/bin/python
# vim:set fileencoding=utf-8 sw=2 ai:
import sqlite3
import datetime
import re
SQL = '''
select
name, version, time, author, text
@sgk
sgk / compat.php
Created June 15, 2012 01:36
Backward compatibility for PHP 5.4
<?
# Add following line in ".htaccess".
# php_value auto_prepend_file compat.php
$HTTP_SERVER_VARS = $_SERVER;
$HTTP_COOKIE_VARS = $_COOKIE;
$HTTP_POST_VARS = $_POST;
$HTTP_GET_VARS = $_GET;
@sgk
sgk / RelativePath.java
Created June 16, 2012 06:35
Compute relative path from a directory to other file or directory.
/*
* by Shigeru KANEMOTO at SWITCHSCIENCE.
*/
import java.io.File;
import java.io.IOException;
class RelativePath {
//
// Compute relative path to "target" from a directory "origin".
@sgk
sgk / job.sh
Created June 25, 2012 17:04
Simple backup script
#!/bin/sh
export PATH=/usr/sbin:/sbin:$PATH
export TZ=Asia/Tokyo
export LANG=en
SERVERHOST=mybackupserver.example.com
SERVERLOGIN=mybackup
SERVER="$SERVERLOGIN@$SERVERHOST"
WEEKDAY=$(date +%a)
@sgk
sgk / whois.py
Created November 25, 2012 04:11
Whois query
import socket
def whois(host, query):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 43))
sock.send(query + '\r\n');
text = ''
while True:
t = sock.recv(1024)
if not t: