Skip to content

Instantly share code, notes, and snippets.

View ishikawa's full-sized avatar
🏠
Working from home

Takanori Ishikawa ishikawa

🏠
Working from home
View GitHub Profile
# http://www.nasuinfo.or.jp/FreeSpace/kenji/sf/python/virtualMachine/PyVM.htm
import dis;import inspect as ins;dis.dis(ins.stack()[1][0].f_code)
# The Absolute and Relative Imports has been
# implemented in Python 2.5
#
# http://docs.python.org/whatsnew/pep-328.html
HAS_RELATIVE_IMPORTS = (sys.hexversion > 0x2050000)
# The Absolute and Relative Imports has been
# implemented in Python 2.5
#
# http://docs.python.org/whatsnew/pep-328.html
HAS_RELATIVE_IMPORTS = (sys.hexversion > 0x2050000)
@ishikawa
ishikawa / static_serve.py
Created October 9, 2008 07:14
(GAE) ZipHandler
"""
Serve static files from a zip file
"""
from google.appengine.ext import zipserve, webapp
class StaticFileHandler(zipserve.ZipHandler):
def get(self, prefix, filename):
if filename.endswith('/'):
#include <stdio.h>
/**
* Hexadecimal number character to integer
*/
static int c2n(int c) {
return c%87%48;
}
int main(void) {
/**
* check_pow2: Returns 1 if n is power of 2
*/
#include <stdio.h>
#include <assert.h>
static int check_pow2(unsigned int n) {
return n != 0 && (n&n-1) == 0;
}
@ishikawa
ishikawa / signed.c
Created October 12, 2008 08:03
Demonstrate signed and unsigned convertion
#include <stdio.h>
int main(void) {
unsigned int ui = 1234;
printf("unsigned int: %u\n", ui);
printf("interpreted as signed int: %d\n", ui);
printf("minus value: %d\n", ~ui + 1);
return 0;
/** itoa implementation */
#include <stdio.h>
#include <string.h>
#include <assert.h>
static int n2c(int n) {
assert(n >= 0 && n <= 15);
return n <= 9 ? n + '0' : n - 10 + 'a';
}
/**
* BridgeCrossing - SRM 146 Div 2 (3rd problem):
* http://www.topcoder.com/stat?c=problem_statement&pm=1599&rd=4535
*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
// % javac Fibonacci.java
// % java -ea Fibonacci
public class Fibonacci {
public static int fib(int n) {
if (n < 0) throw new IllegalArgumentException("n must be more than 0");
if (n <= 1) return n;
int fib0 = 1;