Skip to content

Instantly share code, notes, and snippets.

Help the docs!

So! The new tutorial will be focused on building several small projects in Rust. This example is the first one: a classic 'guessing game.' This was one of the first programs I wrote when I first learned C. 😄

I'd like the feedback of the community before I actually start writing the guide. So this code will be the final code of the first real example Rust programmers see. So I want it to be good. I don't claim this code is good, I just worked something out real quick.

The idea is that I will slowly build from hello world to this final code in steps, introducing one concept at a time. Here are the concepts I'd like a Rust programmer to understand by the time they're done:

Concepts

@Ryman
Ryman / latency.txt
Last active August 29, 2015 14:07 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms

Things that programmers don't know but should

(A book that I might eventually write!)

Gary Bernhardt

I imagine each of these chapters being about 2,000 words, making the whole book about the size of a small novel. For comparison, articles in large papers like the New York Times average about 1,200 words. Each topic gets whatever level of detail I can fit into that space. For simple topics, that's a lot of space: I can probably walk through a very basic, but working, implementation of the IP protocol.

@Ryman
Ryman / example.rs
Created October 24, 2015 15:22
Nickel json for custom types example
#[macro_use] extern crate nickel;
extern crate rustc_serialize;
use nickel::{Nickel, MediaType};
use rustc_serialize::json;
#[derive(RustcEncodable)]
struct Fruit<'a> {
name: &'a str
}
@Ryman
Ryman / gist:1759d18a952d47be6d60
Created November 24, 2015 03:29 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
Windstad to Heljarchen = 379
Windstad to Riverwood = 65
Windstad to Ivarstead = 43
Windstad to Helgen = 101
Windstad to Whiterun = 229
Windstad to Riften = 445
Windstad to Windhelm = 334
Windstad to Markarth = 384
Windstad to Solitude = 195
Windstad to Falkreath = 100

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer. In that case, the programmer isn't allowed to say x = true; that would be an invalid program. The compiler will refuse to compile it, so we can't even run it.

@Ryman
Ryman / .gitignore
Created December 11, 2017 18:46 — forked from maaku/.gitignore
BIP specifying fast merkle trees, as used in the Merkle branch verification opcodes
*~
require 'octokit'
username = ''
password = ''
org_name = 'honeypotio'
board_name = 'The Agile Bear'
column_name = 'Live/Done'
client = Octokit::Client.new(login: username, password: password)
user = client.user
# This file extends and overrides parts of the ActiveAdmin DSL and internals
# in order to provide support for automatically displaying and editing images,
# which in our infrastructure are stored as URLs whose column names end in "img".
# Since this file will be reloaded frequently in the development environment,
# all operations done at load time (class_eval's, etc.) MUST be idempotent.
ActiveAdmin::Views::TableFor.class_eval do
def img_column(col_sym=:img, title="Image")
column title, sortable: false do |obj|