Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / main.rs
Created January 6, 2017 20:23
#![feature(non_ascii_idents)]
fn main() {
std::env::args().nth(1)
.ok_or(format!("Usage: {} FILE", std::env::args().next().unwrap())) // File name
.and_then(|filename| {
std::fs::File::open(&filename)
.map_err(|e| (&e as &std::error::Error).description().to_string())
}).map(|f| (f, String::new()))
.map(|(mut f, mut s)| ((&mut f as &mut std::io::Read).read_to_string(&mut s), s))
@staltz
staltz / introrx.md
Last active July 22, 2024 09:31
The introduction to Reactive Programming you've been missing
@bvssvni
bvssvni / gist:9674632
Last active December 23, 2023 22:56
A Rust Chain Macro
//! Chain macro in Rust
//!
//! A typical usage is to avoid nested match expressions.
//!
//! Supports:
//! - Pattern matching
//! - Or expressions (A | B => ...)
//! - Guarded statements (x if <cond> => ...)
//! - Implicit else (requires all arms to return same type)
@Antarix
Antarix / LocalBroadcastExampleActivity.java
Created December 26, 2013 08:31
Simple Example of using LocalBroadcastManager in Android
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;