Skip to content

Instantly share code, notes, and snippets.

@killercup
killercup / playground.rs
Created May 31, 2018 22:07
Serde Cows (2 of 3)
#[macro_use] extern crate serde_derive;
extern crate serde_json;
use std::borrow::Cow;
#[derive(Debug, Deserialize)]
struct Foo<'input> {
#[serde(borrow)]
bar: Cow<'input, str>,
}
@killercup
killercup / playground.rs
Created May 31, 2018 22:06
Serde Cows (1 of 3)
#[macro_use] extern crate serde_derive;
extern crate serde_json;
use std::borrow::Cow;
#[derive(Debug, Deserialize)]
struct Foo<'input> {
bar: Cow<'input, str>,
}
/// Add this as integration test
extern crate rsass;
pub fn fuzz_rsass_sass(data: &[u8]) {
use rsass::{OutputStyle, compile_scss};
let _ = compile_scss(data, OutputStyle::Compressed);
}
#[test]
/// 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)]
@killercup
killercup / Cargo.lock
Created March 22, 2018 21:39
midimacro
[[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 September 16, 2018 08:03
Fish function to restart a bunch of macOS services that tend to break
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
[package]
name = "steves-csv-thingy"
version = "0.1.0"
authors = ["Pascal Hertleif <killercup@gmail.com>"]
[[bin]]
name = "quicsv"
path = "main.rs"
[dependencies]
[[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 October 5, 2017 18:16
Glorious `join with and` code
#![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),
}
}
@killercup
killercup / playground.rs
Last active September 2, 2017 16:53
Count words
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]