Skip to content

Instantly share code, notes, and snippets.

#!/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.
trace-file() {
local cmd="$1"
local path
if [[ "$cmd" == /* ]]; then
path="$cmd"
elif [[ "$cmd" == */* ]]; then
path="$PWD/$cmd"
else
path="$(type -P "$cmd")"
fi
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);
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 {:?}: {:?}",
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;
}
#![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>)
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 {
use core::util::replace;
#[deriving(Clone)]
struct S(int);
impl Drop for S {
fn finalize(&self) {
io::println(fmt!("~S(%?)", **self));
}
}
@ben0x539
ben0x539 / baz.rs
Last active December 17, 2015 02:59
use core::unstable::intrinsics;
struct S;
impl Drop for S {
fn finalize(&self) {}
}
fn discard(_s: S) {}
fn main() {
unsafe {
# 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