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
@sgk
sgk / ping.py
Created January 15, 2013 15:05
Modified ping.py to check and log the net down times.
#!/usr/bin/env python
"""
A pure python ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.
Derived from ping.c distributed in Linux's netkit. That code is
@sgk
sgk / ir_send.ino
Last active December 11, 2015 10:19 — forked from ytsuboi/ir_send.ino
/*
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2013 Yoshihiro TSUBOI <ytsuboi-at-gmail.com>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
@sgk
sgk / printflen.c
Last active December 11, 2015 19:18
Compute the length printf would print.
#include <stdio.h>
#include <stdarg.h>
/* returns the length printf would print. */
int
printflen(const char* format, ...) {
va_list ap;
char buf[1];
int len;
@sgk
sgk / fft.py
Last active December 12, 2015 08:39
FFT study in Python. Original in C: http://www.kurims.kyoto-u.ac.jp/~ooura/fftman/ftmn1_2.html
import math
def fft(data):
n = len(data)
assert 2 ** int(math.log(n, 2)) == n, "Number of samples should be 2^n."
theta = math.pi * 2 / n
def scramble(k, i):
while True:
@sgk
sgk / LeonardoTest.ino
Created February 21, 2013 12:18
LeonardoTest
int i = 0;
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
while(!Serial) {
}
}
void loop() {
@sgk
sgk / build.sh
Last active December 14, 2015 04:48
Build and install GIT 1.8.1.4 on the very old Solaris 9.
#!/usr/bin/env bash
SOURCE=git-1.8.1.4.tar.gz
SOURCEDIR=git-1.8.1.4
BASH=/usr/bin/bash
MAKE=/usr/local/bin/make
PERL=/usr/local/bin/perl
PYTHON=/usr/local/bin/python
LIBDIR=/usr/local/lib
@sgk
sgk / gist:5537886
Created May 8, 2013 02:58
ipythonで、^Dで確認なしで終了できるようにする。
ipythonで、^Dで確認なしで終了できるようにする。
% ipython profile create
% vi $HOME/.ipython/profile_default/ipython_config.py
以下の設定を行う。
c.TerminalInteractiveShell.confirm_exit = False
@sgk
sgk / ddns.py
Last active December 17, 2015 21:59
A simple script to update the AWS Route53 entry using "boto".
#!/usr/bin/python
import boto
import boto.route53.record
access_key = 'XXXXXXXXXXXXXXXXXXXX'
secret_access_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
zone_id = 'XXXXXXXXXXXXXX'
domain = 'example.com.' # last '.' required.
@sgk
sgk / update53-couchdb.py
Last active December 17, 2015 22:59
Linux startup script to update Route53 zone entry using the EC2 dynamically allocated IP address.
#!/usr/bin/python
### BEGIN INIT INFO
# Provides: update53
# Required-Start: $network $local_fs
# Required-Stop:
# Should-Start:
# Should-Stop:
# X-Start-Before: couchbase-server
# X-Stop-After: couchbase-server
@sgk
sgk / cache.py
Last active December 18, 2015 12:59
Simple cache: dictionary with expire
#vim:set fileencoding=utf-8
import time
# Cache with Expire
class Cache:
def __init__(self, timeout):
# Actual expire is more than timeout and less than timeout*3.
self.timeout_ = timeout
self.clear()