Skip to content

Instantly share code, notes, and snippets.

View Kroisse's full-sized avatar

Eunchong Yu Kroisse

View GitHub Profile
Prelude> let all@x:xs@a:b:s = [1..4]
Prelude> (all, x, xs, a, b, s)
(1,1,2,2,3,[4])
Prelude> let all@(x:xs)@(a:b:s) = [1..4]
<interactive>:9:15: parse error on input `@'
Prelude> let all@(x:xs@a:b:s) = [1..4]
Prelude> (all, x, xs, a, b, s)
([1,2,3,4],1,2,2,3,[4])
@Kroisse
Kroisse / ks.rs
Last active August 29, 2015 13:57
// #[feature(globs)];
extern crate collections;
// use std::iter::*;
use std::from_str::from_str;
// use std::str::from_utf8;
// use collections::hashmap::HashSet;
#[deriving(Clone)]
struct Knapsack {
score: uint,
use std::rand;
use std::rand::Rng;
struct BinTree<T>(Option<~BinNode<T>>);
struct BinNode<T> {
value: T,
left: BinTree<T>,
right: BinTree<T>,
}
@Kroisse
Kroisse / gist:9187028
Created February 24, 2014 11:54
curious
def chunks(iterable, size):
if not size > 0:
raise ValueError('size should greater than 0; not {}'.format(size))
it = iter(iterable)
def iterate():
while True:
chunk = list(islice(it, size))
if not chunk:
break
@Kroisse
Kroisse / gist:9001369
Created February 14, 2014 13:55
Forward remained arguments to the other script, in Flask-Script
class CeleryDaemon(script.Command):
capture_all_args = True
def run(self, args):
from project.tasks import initialize
celery = initialize(current_app)
celery.worker_main(argv=sys.argv[:1] + args)
manager.add_command('celeryd', CeleryDaemon())
@Kroisse
Kroisse / 369.rs
Created November 17, 2013 18:16
369
// $ rustc --version
// rustc 0.9-pre (90754ae 2013-11-14 22:01:26 -0800)
// host: x86_64-apple-darwin
use std::task::{task, with_task_name, deschedule};
use std::comm;
use std::io::{Timer};
use std::ascii::AsciiCast;
fn main() {
@Kroisse
Kroisse / gist:6473348
Last active December 22, 2015 12:38
from_bytes()
use std::to_bytes::*;
use std::num::{Zero, Add, Shl, NumCast};
use N = std::i16;
trait FromBytes {
fn from_bytes(bytes: &[u8], lsb0: bool) -> Self;
}
impl<N: Zero + Add<N, N> + Shl<N, N> + NumCast> FromBytes for N {
@Kroisse
Kroisse / gist:6363281
Created August 28, 2013 08:00
Python indexer sample like C#
class indexer(object):
def __init__(self, getter, setter=None, deleter=None, doc=None):
self._getter = getter
self._setter = setter
self._deleter = deleter
self.__doc__ = doc or getter.__doc__
self._delegates = {}
def setter(self, func):
self._setter = func
#!/usr/bin/env python
import sys
import text
if __name__ == '__main__':
for line in sys.stdin:
line = line.decode('utf-8').rstrip(u'\n')
while True:
a, line = text.east_asian_partition(line, 44)
a = a.rstrip(u'\0')