Skip to content

Instantly share code, notes, and snippets.

Avatar
🐧
Translating

cocoatomo cocoatomo

🐧
Translating
View GitHub Profile
View gist:394248
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.')
View permut.c
#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);
View permut.c
#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;
}
View annotation.py
#!/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:
View Annotated.java
package annotations;
import java.lang.reflect.InvocationTargetException;
@TestAnnotation(hoge="fuga")
public class Annotated {
/**
@cocoatomo
cocoatomo / object.c
Created Nov 18, 2010
instanciation in Python
View object.c
/* 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 Dec 7, 2010
Python での name mangling の上書き動作
View mangling.py
class SecretFirst(object):
def __secret(self):
print('__secret')
def _SecretFirst__secret(self):
print('_SecretFirst__secret')
class SecretSecond(object):
def _SecretSecond__secret(self):
View A.java
public class A {
public static void main(String[] args) {
A a = new A() {};
System.out.println(a.getClass());
}
}
View word_diff.py
>>> 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))
View DataType.java
enum DataType {
// primitive
BOOLEAN(true),
CHARACTER(true),
INTEGER(true),
DECIMAL(true),
STRING(true),
// non-primitive
TYPE_HASH(false),