Skip to content

Instantly share code, notes, and snippets.

View carols10cents's full-sized avatar

Carol (Nichols || Goulding) carols10cents

View GitHub Profile
@nyinyithann
nyinyithann / semi_monad_function_of_result_type.rs
Last active February 8, 2019 18:45
composition of functions of Result<T,E>
use std::io;
use std::io::prelude::*;
fn main() {
loop {
let r = get_input("Enter the first number: ")
.and_then(|x| get_input("Enter the second number: ")
.and_then(|y| get_input("Enter the third number: ")
.and_then(|z| Ok(x + y + z))));
anonymous
anonymous / playground.rs
Created December 31, 2016 22:15
Rust code shared from the playground
use std::collections::BTreeMap;
// Why we might want multiple lifetimes...
// We want this structure to be trivially copyable as we pass it
// around and modify the position.
#[derive(Copy, Clone)]
struct Cache<'d, 's: 'd> {
data: &'d BTreeMap<usize, &'s str>,
position: usize,
@wycats
wycats / errors.md
Last active October 21, 2018 12:04
How I think about error handling in Rust
  • Option: "None is a totally valid result, usually found in data structures"
    • unwrap(): YOLO use in prototyping
    • expect(...): to indicate the reason you believe None is impossible (or a contract violation for the method)
  • Result: 😱 "Errors are unexpected but not bugs; the decision for how to handle them is up to the caller"
    • unwrap(): YOLO "I'm an app and don't know how to handle this error -- I'm fine if the whole process aborts"
    • try! / ?: "Leave the decision about how to handle this error to the caller; they have more information"
    • match / catch: "I'm going to handle the error right here right now"
  • panic!: ☠ "The error is a bug and can't be recovered from. Game over man. Rust is allowed to abort the process if it wants"
enum Meal {
TvDinner,
HomeCooked { healthy: bool },
}
let lunch = Meal::TvDinner;
let dinner = Meal::HomeCooked { healthy: true };
match lunch {
Meal::TvDinner => println!("Eating a TV dinner"),
anonymous
anonymous / playground.rs
Created March 17, 2016 00:07
Shared via Rust Playground
// The error is that there's an unused generic G declared...
fn foo<G>() -> String {
String::from("hi")
}
fn main() {
println!("{}", foo());
// ^ but here is where the error message points to:
// error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]

WARNING - INCOMPLETE AND MIGHT BE WRONG

I'm not a C# dev and haven't gotten one to look at this yet, it might be very very wrong.

C# to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in C# and Rust so that programmers most comfortable with C# can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

@carols10cents
carols10cents / gist:ea6e6d492c72df325dc1
Last active August 29, 2015 14:05
http://rstat.us is dead. Long live rstat.us?

http://rstat.us is dead. Long live rstat.us?

Hey everyone,

As you may have noticed, I have been a Bad Open Source Maintainer and I have not been doing even the minimum amount of maintenance on either the codebase or the main node living at http://rstat.us.

Wilkie has been poking around the code lately, and I'm encouraged because he's got his own node running.

Which brings me to the point of this email-- growing http://rstat.us was never the dream of this project, the dream was to have everyone owning and operating their own nodes that would talk to each other.

@carols10cents
carols10cents / .bashrc
Created April 17, 2014 22:48
Test command with tab completion
# Add this to your .bashrc:
source ~/.test_completion.sh
@hadees
hadees / gist:7308571
Last active December 27, 2015 10:09 — forked from ericboehs/gist:7125105
Poltergeist hack to silence CoreText performance notes from phantomjs that works with billy.
module Capybara::Poltergeist
class Client
private
def redirect_stdout
prev = STDOUT.dup
prev.autoclose = false
$stdout = @write_io
STDOUT.reopen(@write_io)
prev = STDERR.dup
@carols10cents
carols10cents / gist:6049798
Created July 21, 2013 20:12
Slim 2.0 deprecation warnings
# How to find files that have spaces around attribute delimiters
git ls-files *.slim* | xargs -I {} slimrb -c {} | grep "spaces around attribute delimiters"