Skip to content

Instantly share code, notes, and snippets.

View Kroisse's full-sized avatar

Eunchong Yu Kroisse

View GitHub Profile
>>> f = open('setup.py')
>>> f
<_io.TextIOWrapper name='setup.py' mode='r' encoding='UTF-8'>
>>> import io
>>> isinstance(f, io.TextIOBase)
True
>>> isinstance(f, io.BufferedIOBase)
False
>>> isinstance(f, io.RawIOBase)
False
@Kroisse
Kroisse / lib.rs
Last active March 3, 2019 11:13
Static Dispatch vs Dynamic Dispatch
#![feature(test)]
extern crate test;
// 지극히 평범한 함수. 아래 두 함수와의 형평성을 위해 일부러 레퍼런스를 받도록 정의했습니다.
pub fn plain(t: &i64) -> i64 {
t.double()
}
// 트레이트 객체를 인자로 받는 함수.

Keybase proof

I hereby claim:

  • I am kroisse on github.
  • I am kroisse (https://keybase.io/kroisse) on keybase.
  • I have a public key ASDLkqUXx3YlzVg8RgH6H2gz5QOMAoIqnRczbwD09A0FLgo

To claim this, I am signing this object:

fn eternal_pain<'a>(
&self,
handle: &'a Handle,
code: &str,
redirect_uri: Option<&str>,
) -> impl Future<Item=Output, Error=failure::Error> + 'a {
future::result::<_, Error>(
self.build_request_uri(code, redirect_uri)
).and_then(move |uri| {
Client::new(&handle).get(uri).map_err(From::from)
@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')
@Kroisse
Kroisse / pool.py
Last active December 17, 2015 17:39 — forked from eungju/pool.py
class KyotoTycoon(object):
...
def get(self, key):
with self.pool.acquire() as c:
return c.get(key, db=self.db)
# example #2
def set(self, key, value):
conn = self.pool.acquire()
with conn: