Skip to content

Instantly share code, notes, and snippets.

View dymk's full-sized avatar

Dylan Knutson dymk

  • Microsoft
  • PNW
View GitHub Profile
@dymk
dymk / keybase.md
Last active February 9, 2016 00:27

Keybase proof

I hereby claim:

  • I am dymk on github.
  • I am dymk (https://keybase.io/dymk) on keybase.
  • I have a public key ASAFTHCjQAvzt4vE7x0p1hggQkZ05gWFFkT0E4AEVmw2ugo

To claim this, I am signing this object:

@dymk
dymk / jumptest.c
Last active August 29, 2015 14:15
Basic implementation of exceptions and scope guards in C using POSIX setjmp/longjmp
#include <setjmp.h>
#include <stdio.h>
#include <jumptests.h>
static jmp_buf *last_buf = NULL;
static jmp_buf *scope_buf = NULL;
void second() {
printf("--> enter second\n");
throw(1);
@dymk
dymk / gist:5847769
Last active December 18, 2015 21:29
/// Maps coefficient location to a weight bucket
/// Initialized with a self executing lambda, a-la Javascript
shared float[ImageArea] WeightBins = (() {
float[ImageArea] tmp;
foreach(i; 0..ImageHeight) {
foreach(j; 0..ImageWidth) {
tmp[(i * ImageHeight) + j] = min(max(i, j), 5);
}
}
return tmp;
@dymk
dymk / haar.rs
Created May 4, 2013 20:19
Haar 1D and Haar 2D implementations for Rust.
use core::vec;
pub fn haar2d<T : NumCast>(in_mat: ~[~[T]]) -> ~[~[float]] {
let in_mat_rows = in_mat.len();
// Initialize a vector n items long with the value 0
//Perform on each row
let mut in_mat = do vec::map_consume(in_mat) |vec| {
haar1d(vec)
@dymk
dymk / test.rs
Last active December 16, 2015 14:38
trait Newable {
fn new() -> Self;
}
struct Foo(int);
impl Newable for Foo {
fn new() -> Foo {
return Foo(1);
}
}
fn exportPixels(&self) -> ~[RGB] {
//Determine the size of the vector we need to allocate
let mut pixel_buffer = vec::with_capacity::<self::RGB>(self.numPixels());
unsafe {
let buffer_ptr = vec::raw::to_ptr(pixel_buffer);
wand_extern::MagickExportImagePixels(buffer_ptr);
vec::raw::set_len::<RGB>(pixel_buffer, self.numPixels());
}
pixel_buffer
}
struct Circle { radius: int }
trait Shape {}
impl Shape for Circle {}
fn main() {
//Doesn't crash if 'all' is immutable:
// let all: ~[~Shape] = ~[~Circle{radius: 2} as ~Shape];
//Doesn't crash if 'all' is mutable:
// let mut all: ~[~Shape] = ~[~Circle{radius: 2} as ~Shape];
C:\lib>rustc --test my_lib.rs
test_my_lib.rs:1:4: 1:11 error: failed to resolve import: my_lib
test_my_lib.rs:1 use my_lib;
^~~~~~~
error: failed to resolve imports
error: aborting due to 2 previous errors
use types::{MyType, MyOtherType};
mod types;
lib\wand_extern.rs:5:12: 5:26 error: unresolved name
lib\wand_extern.rs:5 use types::{MagickWandPtr, ImagePtr};
^~~~~~~~~~~~~~
lib\wand_extern.rs:5:12: 5:26 error: failed to resolve import: types::MagickWandPtr
lib\wand_extern.rs:5 use types::{MagickWandPtr, ImagePtr};
^~~~~~~~~~~~~~
lib\wand_extern.rs:5:27: 5:36 error: unresolved name
lib\wand_extern.rs:5 use types::{MagickWandPtr, ImagePtr};
^~~~~~~~~
lib\wand_extern.rs:5:27: 5:36 error: failed to resolve import: types::ImagePtr