Skip to content

Instantly share code, notes, and snippets.

@dovreshef
dovreshef / hello-wasm.js
Created October 16, 2021 20:09 — forked from dio/hello-wasm.js
This is a simpe example on embedding wasm inside an offline single html page
// this code is from a simple add function in c:
//
// // hello.c
// int add(int a, int b) {
// return a + b;
// }
//
// compiles it with emcc (http://webassembly.org/getting-started/developers-guide/)
// $ git clone https://github.com/juj/emsdk.git
@dovreshef
dovreshef / rust-rr-pp.md
Created April 13, 2020 07:38 — forked from spacejam/rust-rr-pp.md
pretty printing rust with rr

using rust pretty printers with rr

rr is a great debugging tool. it records a trace of a program's execution, as well as the results of any syscalls it executes, so that you can "rewind" while you debug, and get deterministic forward and reverse instrumented playback. it works with rust, but by default if you try it out, it could be pretty ugly when you inspect variables.

install

steps:

  1. get the rust pretty printer python script
  2. configure gdb to automatically load it
Updating git repository `https://github.com/PistonDevelopers/rust-image.git`
Fresh svg v0.0.1 (https://github.com/jeremyletang/svg.git#9fcc2451)
Compiling image v0.0.0 (https://github.com/PistonDevelopers/rust-image.git#b12e4237)
Could not compile `image`.
--- stderr
src/image.rs:346:28: 346:30 error: only the 'static lifetime is accepted here.
src/image.rs:346 pub struct SubImage <'a, I:'a> {
^~
src/image.rs:123:25: 123:27 error: only the 'static lifetime is accepted here.
#[bench]
fn bench_from_fn(b: &mut extra::test::BenchHarness) {
do b.iter {
let v : ~[uint] = vec::from_fn(10000000, |n| n);
if 0u == rand::random() {
printfln!("%u", v[999]);
}
}
}
@dovreshef
dovreshef / maze.rs
Created September 9, 2013 08:56
test labeled for breaks
use std::vec;
use std::rand;
use std::rand::RngUtil;
#[deriving(Clone)]
pub enum Direction {
North = 1,
South = 2,
East = 4,
use std::cast;
use std::ptr;
use std::unstable::intrinsics;
#[no_send]
#[no_freeze]
#[unsafe_no_drop_flag]
struct Tree {
parent: Option<*mut Tree>
}
use t2;
fn main() {
t2::fun();
}
struct Tree {
parent: Option<~Tree>
}
impl Tree {
fn new() -> Tree {
Tree { parent: None }
}
fn root<'r>(&'r mut self) -> &'r mut Tree {
struct Outer {
number: int
}
mod inner {
use super::*;
struct Outer {
number: int
}
mod inner {
use super::*;