Skip to content

Instantly share code, notes, and snippets.

@mitaki28
mitaki28 / inc_dec.py
Created October 24, 2012 06:44
Support Increment and Decrement on Python
# ~*~ coding:utf-8 ~*~
"""
=============================================
Support Increment and Decrement on Python
=============================================
>>> import inc_dec
>>> i = int(1)
>>> ++i
>>> print i
@mitaki28
mitaki28 / factor.py
Created December 2, 2012 17:40
paren to factor
# ~*~ coding:utf-8 ~*~
"""
数学でよく使う、掛け算記号の省略をやってみた
"""
def _(method):
def __(self, *args, **kw):
r = getattr(float, method)(self, *args, **kw)
return Float2(r) if isinstance(r, float) else r
/**
* Priority Queue for JavaScript
*
* simple implementation of priority queue with heap on javascript.
*
*/
var PriorityQueue = function(cmp){
this.heap = [];
this.cmp = (cmp == null) ? PriorityQueue.CMP : cmp;
@mitaki28
mitaki28 / mini-sqlite.cc
Created October 13, 2015 10:59
Simple wrapper for SQLite3
/*
Simple wrapper for SQLite3
This code is Public Domain
**CAUTION**
1. No Warrantry
2. This code is *NOT* safe against SQL Injection.
3. This code can *NOT* handle BLOB or TEXT including '\0'.
4. You should *NOT* use this for production.
@mitaki28
mitaki28 / lens.ts
Created November 5, 2016 17:51
Type-safe Lens (TypeScript 2.1)
// requires TypeScript 2.1 or higher
export abstract class Lens<T, U> {
abstract get: (obj: T) => U;
abstract set: (value: U) => (obj: T) => T;
then = <V>(lens: Lens<U, V>) => new ComposedLens(this, lens);
thenKey = <L extends keyof U>(key: L): Lens<T, U[L]> => this.then(new ObjectLens<U, L>(key));
modify = (f: (value: U) => U) => (obj: T) => this.set(f(this.get(obj)))(obj);
}
export class IdLens<T> extends Lens<T, T> {