Skip to content

Instantly share code, notes, and snippets.

View playground.rs
macro_rules! externs {
( $name:ident with macros, $($rest:tt)* ) => {
externs!($x with macros);
externs!($($rest)*);
};
( $name:ident, $($rest:tt)* ) => {
externs!($name);
externs!($($rest)*);
};
( $name:ident with macros ) => {
@killercup
killercup / playground.rs
Last active Jan 20, 2017
gracefully_hysteria
View playground.rs
macro_rules! graceful_hysteria {
($($stuff:tt)*) => {
{
use std::io::Write;
let _ = writeln!(::std::io::stderr(), $($stuff)*);
::std::process::exit(1);
}
}
}
View playground.rs
fn fst<T1, T2>((t1, _t2): (T1, T2)) -> T1 {
t1
}
fn snd<T1, T2>((_t1, t2): (T1, T2)) -> T2 {
t2
}
fn main() {
let xs = vec![42, 43, 44, 45];
@killercup
killercup / Makefile
Created Jan 13, 2017
Auto Makefile CLI help
View Makefile
ARGS = $(filter-out $@,$(MAKECMDGOALS))
MAKEFLAGS += --silent
PROJECTNAME = foobar
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@killercup
killercup / playground.rs
Created Jan 12, 2017
Ping ALL the machines in a subnet
View playground.rs
use std::collections::BTreeMap;
use std::net::Ipv4Addr;
use std::thread;
use std::process::{Command, Stdio};
fn main() {
let subnet: u8 = std::env::args()
.skip(1)
.next()
.unwrap_or("20".into())
View playground.rs
#![allow(dead_code)]
/// Create method to access field of sub-resource
///
/// Similar to ActiveSupport's [`delegate`].
///
/// [`delegate`]: http://api.rubyonrails.org/classes/Module.html#method-i-delegate
///
/// # Limitations
///
View playground.rs
macro_rules! w {
($($x:ident)+) => {
vec![$(stringify!($x),)*]
}
}
#[test]
fn ident_vec() {
assert_eq!(w![foo bar baz], vec!["foo", "bar", "baz"]);
}
View playground.rs
/// Extend `Option` with a fallible map method
///
/// # Type parameters
///
/// - `T`: The input `Option`'s value type
/// - `U`: The outputs `Option`'s value type
/// - `E`: The possible error during the mapping
trait FallibleMapExt<T, U, E> {
/// Try to apply a fallible map function to the option
fn try_map<F>(&self, f: F) -> Result<Option<U>, E> where
View rust_features.md
Name Area Stablity Since version
abi_sysv64 lang unstable 1.13.0
abi_vectorcall lang unstable 1.7.0
addr_parse_error_error lib stable 1.4.0
advanced_slice_patterns lang unstable 1.0.0
alloc lib unstable None
alloc_jemalloc lib unstable None
alloc_system lib unstable None
allocator lang unstable 1.0.0
View viewport.scss
$breakpoints: (
s: 450px,
m: 600px,
l: 900px,
xl: 1200px
) !default;
@function get-breakpoint($name, $breakpoints: $breakpoints) {
$breakpoint: map-get($breakpoints, $name);
@if $breakpoint == null {