Skip to content

Instantly share code, notes, and snippets.

View pythonesque's full-sized avatar

Joshua Yanovski pythonesque

  • Lanetix
  • San Francisco, CA
View GitHub Profile
#!/usr/bin/env ruby
require 'uri'
require 'set'
urls = Set.new()
STDIN.each_line do|line|
begin
url = URI.parse(line.downcase).host
@pythonesque
pythonesque / phonebook.rs
Last active December 26, 2015 14:09
Failing with a runtime assertion on Rust 0.8 on Ubuntu 12.0.4.
#0 0x00007ffff62c9910 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x00007ffff741db0a in rust_begin_unwind (token=839147) at /home/ubuntu/rust/rust-0.8/src/rt/rust_builtin.cpp:509
#2 0x00007ffff77a04a6 in rt::task::Unwinder::begin_unwind::h7c12263797ed078hEa6::v0.8 ()
from /home/ubuntu/rust/src/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8.so
#3 0x00007ffff779f7d3 in sys::begin_unwind_::h89e154cd0915671ak::v0.8 () from /home/ubuntu/rust/src/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8.so
#4 0x00007ffff779f302 in sys::__extensions__::fail_with::anon::anon::expr_fn::aV () from /home/ubuntu/rust/src/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8.so
#5 0x00007ffff779f228 in c_str::ToCStr::with_c_str::hc6798931b183a7aS::v0.8 () from /home/ubuntu/rust/src/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8.so
#6 0x00007f
struct Foo(uint);
fn main()
{
enum Bar { Baz(Foo) };
let x = Baz(Foo(4));
fn foo(_bar : uint) -> Foo { Foo(3) }
match x {
Baz(foo(x)) => println!("{:?}", x)
@pythonesque
pythonesque / OPTIMIZATION.md
Last active August 29, 2015 13:57
Optimization techniques

Five basic methods of optimization

These are just some thoughts I had today about optimization and I decided to write them down before I forgot what I was thinking or changed my mind.

Suppose you have a bottleneck function, f, as part of a larger system.

  1. Do exactly f, but faster.

This is the most straightforward approach. Basically, compute the exact same thing f is, but do it faster. This can include speeding up subproblems, improving the algorithm used in f itself, switching to faster hardware, performing precomputation in places that aren't time-critical (so there isn't a tradeoff from this perspective), and so on.

use std::fmt;
trait Trait { }
impl <T: Trait> fmt::String for T {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Err(fmt::WriteError)
}
}
// Implements http://rosettacode.org/wiki/Checkpoint_synchronization
//
// We implement this task using Rust's Barriers. Barriers are simply thread
// synchronization points--if a task waits at a barrier, it will not continue
// until the number of tasks for which the variable was initialized are also
// waiting at the barrier, at which point all of them will stop waiting. This
// can be used to allow threads to do asynchronous work and guarantee properties
// at checkpoints.
use std::sync::atomic::AtomicBool;
#![feature(overloaded_calls)]
pub struct G<T, U> {
n: T,
}
impl<T: Add<U, T> + Clone, U> FnMut<(U,), T> for G<T, U> {
extern "rust-call" fn call_mut(&mut self, (i,):(U,)) -> T {
self.n = self.n + i;
self.n.clone()
pub mod bitmap {
pub type ColorComponent = u8;
#[deriving(Clone, Default, Eq, PartialEq)]
pub struct Pixel {
pub r: ColorComponent,
pub g: ColorComponent,
pub b: ColorComponent,
}
#![feature(if_let)]
extern crate arena;
extern crate rustc;
use arena::Arena;
use rustc::util::nodemap::FnvHashMap;
use std::any::{Any, AnyRefExt};
use std::cell::RefCell;
use std::collections::hashmap;
#![feature(unsafe_destructor)]
/*
For safety, here are some guarantees we need fulfilled for allocated types for
an allocator of size class <M, N, O>.
* <T>::Size < M
e.g. consider 1-sized struct aligned at 4096.