Skip to content

Instantly share code, notes, and snippets.

View tilpner's full-sized avatar

Till Höppner tilpner

  • Germany
  • 07:53 (UTC +02:00)
View GitHub Profile
#![no_std]
#![feature(libc, lang_items, start)]
#![no_main]
//! ```sh
//! # compile
//! rustc -C opt-level=3 -C no-stack-check standalone.rs
//! # strip
//! strip -sR .comment -R .gnu.hash -R .gnu.version -R .note.ABI-tag -R .note.gnu.build-id standalone
//! # check size
@tilpner
tilpner / keybase.md
Created February 4, 2016 23:01
Keybase GitHub verification

Keybase proof

I hereby claim:

  • I am tilpner on github.
  • I am tilpner (https://keybase.io/tilpner) on keybase.
  • I have a public key whose fingerprint is DEEA E3CB ABED 5094 9255 CDC2 4D79 DB6D BB81 7349

To claim this, I am signing this object:

@tilpner
tilpner / lazy.rs
Last active February 4, 2016 01:28
Lazy evaluation, currently without closure support due to Box<FnOnce> problems in current Rust
use std::ptr;
use std::cell::UnsafeCell;
use std::ops::Deref;
// Inline definition of anonymous functions. Examples:
// l!(42;)
// l!(i32 := 42)
// l!(i: i32 := i + 42)
// l!(i: i32, j: i32 -> i32 := i + j)
#[macro_export]
@tilpner
tilpner / Cargo.toml
Last active September 12, 2015 17:53
read_by_line
[package]
name = "read_by_line"
version = "0.0.1"
authors = ["Till Hoeppner <till@hoeppner.ws>"]
use std::env;
use std::fs::File;
use std::io::{ BufReader, BufRead };
fn main() {
let file = File::open(env::args().nth(1).expect("Must supply one argument"))
.ok().expect("Couldn't open file");
let input = BufReader::new(file);
for line in input.lines() {
match line {
@tilpner
tilpner / l.rs
Last active September 30, 2023 10:41
Macro for inline definition of anonymous functions, and examples of passing functions.
fn once(f: Box<Fn()>) { f() }
fn twice(f: fn()) { f(); f() }
fn thrice<F: Fn()>(f: F) { f(); f(); f() }
// Inline definition of anonymous functions. Examples:
// l!(42;)
// l!(i32 := 42)
// l!(i: i32 := i + 42)
use std::fs::File;
use std::io::{ Read, BufRead, BufReader };
fn main() {
let filename = "text.txt";
let f = BufReader::new(File::open(filename).ok().expect("Failed to open file."));
for line in f.lines() {
println!("{}", line.ok().expect("IO Error, couldn't read line.")
#![feature(test)]
/// rustc --test -C opt-level=3 fragmentation.rs
/// ./fragmentation --bench
extern crate test;
use test::{ black_box, Bencher };
use std::iter::repeat;
use std::borrow::Cow::{ self, Owned, Borrowed };
@tilpner
tilpner / Results
Last active August 29, 2015 14:23
This may or may not test allocation cost correctly.
Running target/release/fragmentation-044547b832409c71
running 4 tests
test bench_cows_best_case ... bench: 15 ns/iter (+/- 1)
test bench_cows_worst_case ... bench: 150 ns/iter (+/- 11)
test bench_fragmented ... bench: 133 ns/iter (+/- 2)
test bench_reduced_fragmentation ... bench: 41 ns/iter (+/- 2)
test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured