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 / sierpinski.hs
Created October 31, 2015 09:32
Draw a Sierpinski triangle
module Main where
import Data.List (genericLength, genericReplicate)
import System.Environment (getArgs, getProgName)
import System.Exit (exitSuccess)
sierpinskiRows :: Integer -> [String]
sierpinskiRows 0 = []
sierpinskiRows 1 = ["*"]
sierpinskiRows n
main :: IO ()
main = do
let xs = replicate 4 getLine
head xs >>= print
@Kroisse
Kroisse / promise.rs
Last active August 29, 2015 14:11
Madness
#![feature(unboxed_closures)]
use std::sync::{Arc, Mutex};
use std::mem;
use PromiseState::{Ready, Fulfilled, Deferred, Done};
enum PromiseState<T, F: FnOnce(T) + Send> {
Ready,

Keybase proof

I hereby claim:

  • I am kroisse on github.
  • I am kroisse (https://keybase.io/kroisse) on keybase.
  • I have a public key whose fingerprint is 1E03 AD64 5079 0E12 CD28 2FF2 B39A 3CA2 AD8D 5DC3

To claim this, I am signing this object:

use std::{iter, slice};
use std::io::{IoResult, Writer};
pub struct BlockWriter {
blk_size: uint,
blks: Vec<Vec<u8>>,
}
struct Blocks<'a>(slice::Items<'a, Vec<u8>>);
use std::io::IoResult;
trait Shape {
fn draw(&self, size: uint, buf: &mut Writer) -> IoResult<()>;
}
fn draw<T: Shape>(shape: T, size: uint) {
match shape.draw(size, &mut std::io::stdio::stdout()) {
Ok(_) => (),
Err(e) => fail!(e),