Skip to content

Instantly share code, notes, and snippets.

View config_magic.rs
/// just some api ideas
#[test]
fn config_loading() {
let fs = MockFS::new()
.file("/usr/local/etc/foo", "fancy = 10")
.file("~/.config/foo", "fancy = 20")
.file(".env", "LE_PREFIX_FANCY=30");
#[derive(Default, Configure, StructOpt)]
View Cargo.lock
[[package]]
name = "alsa-sys"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@killercup
killercup / fixit.fish
Last active Sep 16, 2018
Fish function to restart a bunch of macOS services that tend to break
View fixit.fish
function fixit --description 'restart a bunch of macOS services that tend to break'
sudo killall -KILL appleeventsd
sudo killall VDCAssistant
sudo killall AppleCameraAssistant
sudo killall -HUP mDNSResponder
killall Dock
killall Spotlight
end
View Cargo.toml
[package]
name = "steves-csv-thingy"
version = "0.1.0"
authors = ["Pascal Hertleif <killercup@gmail.com>"]
[[bin]]
name = "quicsv"
path = "main.rs"
[dependencies]
View Cargo.lock
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
@killercup
killercup / playground.rs
Last active Oct 5, 2017
Glorious `join with and` code
View playground.rs
#![feature(slice_patterns)]
fn join_with_and(xs: &[&str]) -> String {
match xs.split_last() {
None => String::new(),
Some((last, &[])) => last.to_string(),
Some((last, &[first])) => format!("{} and {}", first, last),
Some((last, beginning)) => format!("{}, and {}", beginning.join(", "), last),
}
}
View playground.rs
use std::collections::HashMap;
fn count_words(text: &str) -> HashMap<&str, usize> {
text.split(' ').fold(
HashMap::new(),
|mut map, word| { *map.entry(word).or_insert(0) += 1; map }
)
}
#[test]
View playpen.rs
macro_rules! enum_with_str_repr {
($enum_name:ident { $($variant:ident => $str:expr),* }) => {
#[derive(PartialEq, PartialOrd, Copy, Clone, Eq, Ord, Hash, Debug)]
pub enum $enum_name {
$(
#[doc=$str]
$variant,
)*
}
@killercup
killercup / Cargo.lock
Created May 8, 2017
extern crate in doctest
View Cargo.lock
[root]
name = "playground"
version = "0.1.0"
dependencies = [
"serde_json 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.1"