Skip to content

Instantly share code, notes, and snippets.

View cocoatomo's full-sized avatar
🐧
Translating

cocoatomo cocoatomo

🐧
Translating
View GitHub Profile
class InfiniteList:
def __init__(self, init_val=1, next_val=1):
self.real_list = []
self.init_val = init_val
self.diff = next_val - init_val
def __getitem__(self, index):
if index < 0:
raise IndexError('Out of index range.')
#include "permut-1.0.h"
#define DEBUG 0
int permut(int *sequence, int size, int index)
{
int tempIndex, mainIndex;
int *memo, *memoIndex;
#if DEBUG
printf("\n\nindex=%d:", index);
#include "permut-1.0.h"
#include "fact.h"
void swap(int *sequence, int i, int j) {
int tmp;
tmp = sequence[i];
sequence[i] = sequence[j];
sequence[j] = tmp;
}
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
def range(**ranged):
def arged(f):
def ret(*argv, **d):
minv = ranged['min']
maxv = ranged['max']
print('*** range check. min: {0}, max: {1} ***'.format(minv, maxv))
for a in argv:
package annotations;
import java.lang.reflect.InvocationTargetException;
@TestAnnotation(hoge="fuga")
public class Annotated {
/**
@cocoatomo
cocoatomo / object.c
Created November 18, 2010 03:36
instanciation in Python
/* Objects/object.c in Python2.7 */
PyObject *
_PyObject_New(PyTypeObject *tp)
{
PyObject *op;
op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
if (op == NULL)
return PyErr_NoMemory();
return PyObject_INIT(op, tp);
@cocoatomo
cocoatomo / mangling.py
Created December 7, 2010 11:38
Python での name mangling の上書き動作
class SecretFirst(object):
def __secret(self):
print('__secret')
def _SecretFirst__secret(self):
print('_SecretFirst__secret')
class SecretSecond(object):
def _SecretSecond__secret(self):
public class A {
public static void main(String[] args) {
A a = new A() {};
System.out.println(a.getClass());
}
}
>>> diff(['aaa bbb', 'ccc ddd'],
... ['aaa xxx', 'bbb ccc ddd'])
(((1, "aaa"), (1, "aaa"), NO_DIFF),
((1, ""), (1, "xxx"), ADD),
((1, "bbb"), (2, "bbb"), MOVE),
((2, "ccc"), (2, "ccc"), MOVE),
((2, "ddd"), (2, "ddd"), MOVE))
enum DataType {
// primitive
BOOLEAN(true),
CHARACTER(true),
INTEGER(true),
DECIMAL(true),
STRING(true),
// non-primitive
TYPE_HASH(false),