This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "http_request2" | |
version = "0.1.0" | |
[dependencies] | |
futures = "*" | |
hyper = "0.11.0" | |
tokio-core = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "http_request1" | |
version = "0.1.0" | |
[dependencies] | |
hyper = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module HList where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
NewerOlder