This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
################################################################################ | |
# possibly slightly more reasonable error handling in bash. | |
# ideally you'd like set -e to just abort your script whenever something | |
# goes unexpectedly wrong. there's a couple snags, tho. | |
# 1) set -e doesn't persist through command substitutions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trace-file() { | |
local cmd="$1" | |
local path | |
if [[ "$cmd" == /* ]]; then | |
path="$cmd" | |
elif [[ "$cmd" == */* ]]; then | |
path="$PWD/$cmd" | |
else | |
path="$(type -P "$cmd")" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate gif; | |
fn make_file() { | |
// http://www.piston.rs/image/gif/index.html#encoding-gif-files | |
use gif::{Frame, Encoder, Repeat, SetParameter}; | |
use std::fs::File; | |
use std::borrow::Cow; | |
let color_map = &[0xFF, 0xFF, 0xFF, 0, 0, 0]; | |
let (width, height) = (6, 6); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn with_current_dir<F, T>(path: &Path, f: F) -> std::io::Result<T> | |
where F: FnOnce() -> T { | |
let previous_dir = try!(current_dir()); | |
let rewind = || { | |
match set_current_dir(&previous_dir) { | |
Err(e) => { | |
let _ = set_current_dir("/"); | |
let _ = writeln!( | |
&mut stderr(), | |
"couldn't chdir back to {:?}: {:?}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use self::string10_mod::inlinevec::InlineVec as VecString10; | |
use self::int4_mod::inlinevec::InlineVec as FourBoundedArray; | |
mod string10_mod { | |
type T = String; | |
static N: uint = 10; | |
static Size: uint = 3 * 8; | |
static Align: uint = 8; | |
#[path = "../inlinevec.rs"] pub mod inlinevec; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(macro_rules)] | |
use std::task; | |
use std::any::{Any, AnyRefExt}; | |
use std::io; | |
use std::iter; | |
// a channel for transmitting failure context info while unwinding | |
local_data_key!(diag_tx_key: Sender<FailureContext>) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Allocator { | |
unsafe fn store<T>(obj: T) -> *T; | |
unsafe fn store_mut<T>(obj: T) -> *mut T; | |
unsafe fn release<T>(ptr: *T); | |
} | |
struct Malloc; | |
struct OwnedPtr; | |
impl Allocator for Malloc { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use core::util::replace; | |
#[deriving(Clone)] | |
struct S(int); | |
impl Drop for S { | |
fn finalize(&self) { | |
io::println(fmt!("~S(%?)", **self)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use core::unstable::intrinsics; | |
struct S; | |
impl Drop for S { | |
fn finalize(&self) {} | |
} | |
fn discard(_s: S) {} | |
fn main() { | |
unsafe { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zero ruby IO happens here: | |
def assert_type(x, klass) | |
return if x.kind_of?(klass) | |
raise TypeError, "expected #{klass}, got #{x.inspect} :: #{x.class}" | |
end | |
class IOAction < Struct.new(:primop, :args) | |
end |