Skip to content

Instantly share code, notes, and snippets.

@hyone
hyone / Cargo.toml
Created Jul 2, 2017
Rust で並列HTTP Request (非同期IO版) ref: http://qiita.com/hyone/items/7f448c46611d9b19e643
View Cargo.toml
[package]
name = "http_request2"
version = "0.1.0"
[dependencies]
futures = "*"
hyper = "0.11.0"
tokio-core = "*"
View Cargo.toml
[package]
name = "http_request1"
version = "0.1.0"
[dependencies]
hyper = "*"
@hyone
hyone / gitfile1.rs
Last active Oct 15, 2016
open file with std::error::Error
View gitfile1.rs
use std::error::Error as StdError;
use std::env;
use std::fmt;
use std::fs::File;
use std::io::Error as ioError;
use std::io::prelude::*;
use std::path::Path;
macro_rules! eprintln {
@hyone
hyone / gist:02b81a2a176ca0ada59a3343b6787b79
Last active Oct 9, 2016
Practice: lifetime qualifier added version of sample code at http://rustbyexample.com/trait.html
View gist:02b81a2a176ca0ada59a3343b6787b79
struct Sheep<'a> { naked: bool, name: &'a str }
trait Animal<'a> {
fn new(name: &'a str) -> Self;
fn name(&self) -> &str;
fn noise(&self) -> &str;
fn talk(&self) {
println!("{} says {}", self.name(), self.noise());
@hyone
hyone / gist:d6018ee1ac8f9496fed839f481eb59d6
Last active Oct 2, 2016
Practice: implement `Display` trait for `slice` wrapper
View gist:d6018ee1ac8f9496fed839f481eb59d6
use std::fmt::{ Debug, Display, Formatter, Result };
use std::string::ToString;
#[derive(Debug)]
struct Slice<'a, T: 'a> {
data: &'a [T]
}
impl <'a, T: ToString> Display for Slice<'a, T> {
fn fmt(&self, f: &mut Formatter) -> Result {
View file0.txt
# iex -S mix
iex(1)> import Ecto.Query
nil
iex(2)> import Ecto.Adapters.SQL
nil
iex(3)> user_id = 2
2
iex(4)> q = from u in SampleApp.User, join: fu in assoc(u, :relationships), where: u.id == ^user_id, select: fu.id
@hyone
hyone / gist:8205717
Created Jan 1, 2014
ruby koans: about_scoring_project.rb
View gist:8205717
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used to calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
# * A set of three numbers (other than ones) is worth 100 times the
# number. (e.g. three fives is 500 points).
@hyone
hyone / gist:6128565
Last active Dec 20, 2015
Number of binary trees have N leaves with logging by Writer Monad #2 ( see: http://hyone.hatenablog.com/entry/20120803/1343996582 )
View gist:6128565
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.List
import Control.Monad.Trans (lift)
import Control.Monad.Writer
splites :: Int -> [(Int, Int)]
splites n = [ (x, n - x) | x <- [1..n-1] ]
liftList :: Monad m => [a] -> ListT m a
@hyone
hyone / HList.hs
Last active Dec 10, 2015
Typed Heterogeneous Lists with DataKinds language extension
View HList.hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module HList where
@hyone
hyone / gist:3994646
Created Nov 1, 2012
Example code to implement instances for Singlton types
View gist:3994646
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- | Example code to implement instances for Singlton types introduced GHC 7.6.1
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.