Skip to content

Instantly share code, notes, and snippets.

View stianeklund's full-sized avatar

Stian Eklund stianeklund

View GitHub Profile
// Halt on panic
#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust#53964
extern crate panic_halt; // panic handler
use cortex_m;
use cortex_m_rt::entry;
use stm32f4xx_hal as hal;
use crate::hal::{prelude::*, stm32};
// My CPU struct
#[derive(Debug)]
pub struct Cpu {
opcode: u16,
memory: Box<[u8; 4096]>, // 0x000 - 0xFFF. 0x000 - 0x1FF for interpreter
v: [u8; 16], // 8-bit general purpose register, (V0 - VE*).
i: u16, // Index register (start at 0x200)
pc: u16, // Program Counter. Jump to 0x200 on RST
stack: [u16; 16], // Interpreter returns to value when done with subroutine
sp: u16, // Stack pointer
pub fn main() {
let path = Path::new("/home/stian/projects/rosten/tracking.json");
let display = path.display();
let mut file = match File::open(&path) {
Err(e) => panic!("unable to open {}: {}", display, e.description()),
Ok(file) => file,
};
let mut buffer = String::new();
" General settings
set nohud
set nosmoothscroll
set noautofocus " The opposite of autofocus; this setting stops
" sites from focusing on an input box when they load
set typelinkhints
let searchlimit = 30
let scrollstep = 70
let barposition = "bottom"
let hintcharacters = "ashtneoi"
@stianeklund
stianeklund / gist:de4935c2bca2e88828cd
Last active November 19, 2015 19:50
Trying to write to JSON
var data = {
"customers": [{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "20 Broadway St",
"city": "New York",
"state": "NY",
"postalCode": "10021",
@stianeklund
stianeklund / Wasavi
Last active August 29, 2015 14:26
Wasavi VIM like text editing in Chrome.
" exrc for wasavi´
set expandtab
set tabstop=2 shiftwidth=2
set autoindent
set expandtab
map [noremap] n j
map [noremap] e k
map [noremap] s h
map [noremap] t l
map [noremap] f e
@stianeklund
stianeklund / gist:d9c522e1dab612c09145
Last active December 16, 2015 08:39
cVim (colemak bindings removed)
" Settings
set nohud
set nosmoothscroll
set noautofocus " The opposite of autofocus; this setting stops
" sites from focusing on an input box when they load
set typelinkhints
let searchlimit = 30
let scrollstep = 70
let barposition = "bottom"
let locale = "no" " Current choices are 'jp' and 'uk'. This allows cVim to use sites like google.co.uk
@stianeklund
stianeklund / c2f
Last active August 29, 2015 14:02
temperature converter
# Temperature converter
# Made by Stian
#
puts "Convert from Celsius to Fahrenheit or Fahreinheit to Celsius"
puts "Please select 1 for Celsius or 2 for Fahrenheit"
selection = gets.to_i
# Conversion formulas
# °F = (°C · 9/5) + 32
# °C = (°F − 32) · 5/9