Skip to content

Instantly share code, notes, and snippets.

@cceckman
cceckman / error.log
Created February 20, 2014 07:45
Trait inheritance in Rust?
gist.rs:12:5: 16:6 error: method `add` is not a member of trait `vector<A>`
gist.rs:12 fn add(&self, rhs : &(A,A,A)) -> (A,A,A){
gist.rs:13 let (x,y,z) = *self;
gist.rs:14 let (a,b,c) = *rhs;
@cceckman
cceckman / gist:9214876
Created February 25, 2014 18:33
Method calls in Rust
trait ScreenCanvas{
fn sync(&Self) -> bool;
fn setResolution(&Self) -> bool;
}
struct screen_buffer_info{
x : uint;
}
impl ScreenCanvas for screen_buffer_info{
#include <stdio.h>
int i = 0; // Static values are initialized to 0 according to C spec, this just makes it explicit
int foo(){
i = i + 1;
return i;
}
int main(){
@cceckman
cceckman / mod.rs
Last active August 29, 2015 13:56
use self::arm1176jzf_s::gpio::pin_mode::OUTPUT;
// Compilation error: cannot import from a trait or type implementation
pub mod arm1176jzf_s;
// Defined with submodules in separate file
pub fn init() {
let p : Pin = arm1176jzf_s::gpio::Pin::get(16);
p.setMode(OUTPUT);
// setMode has a single parameter of type arm1176jzf_s::gpio::pin_mode; OUTPUT is a variant thereof
@cceckman
cceckman / foo.cpp
Created March 5, 2014 04:17
Resizing a vector.
#include <cstdio>
#include <vector>
int main(){
int new_size = 3;
@cceckman
cceckman / Makefile-onetarget
Last active August 29, 2015 13:57
Inconsistency emit bc,link
SHELL=/bin/bash
TARGET := arm-linux-noeabi
CHIP := arm926ej-s
rpi: CHIP := arm1176jzf-s
GCC_PREFIX := $(GCC_PREFIX)arm-none-eabi-
RUSTC := $(RUST_ROOT)/bin/rustc
#RUSTCFLAGS := -O --target $(TARGET) -Z no-landing-pads -Z debug-info -Z extra-debug-info --cfg $(CHIP)
@cceckman
cceckman / test.sh
Created March 18, 2014 04:42
BC output dependent on other targets
#!/bin/bash
mkdir bc
mkdir bclink
git clone git@github.com:thestinger/rust-core
rustc --emit=bc --out-dir=bc rust-core/core/lib.rs
rustc --emit=bc,link --out-dir=bclink rust-core/core/lib.rs
diff bc/core.bc bclink/core.bc
@cceckman
cceckman / minheap.cpp
Created April 7, 2014 18:33
minheap implementation
#include "minheap.h"
/* Default constructor */
minheap::minheap()
{
// Ensure that there is always an empty element at index 0
values.push_back(0);
};
void minheap::insert(int v)
@cceckman
cceckman / gist:cd171aa8ec212ca47d43
Last active August 29, 2015 14:03
Packet decoder to 10-bit samples
// For chasecaleb of #xkcd. Untested- use at your own risk!
// I took this on just as a challange, so please review / check against your own work.
#define PACKET_DATA_SZ 22
#define SAMPLE_BITS 10
typedef struct {
uint32_t timestamp;
char data[PACKET_DATA_SZ];
} sample_packet_t;
@cceckman
cceckman / 01-pv-gce.yml
Created May 22, 2017 06:58
Non-working PV
# after having run `$ gcloud compute disks create --size=2GB gce-nfs-disk`
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
labels:
app: test
spec:
capacity:
storage: 2Gi