Skip to content

Instantly share code, notes, and snippets.

View bwindels's full-sized avatar

Bruno Windels bwindels

View GitHub Profile
@bwindels
bwindels / gist:be9c6f89135cd574ae56
Created November 28, 2014 14:51
Generics for higher order functions
function map<I,O>(array:I[], mapper:(value:I) => O) : O[] {
var result:O[] = [];
var index = 0;
for(;index < array.length; ++index) {
result.push(mapper(array[index]));
}
return result;
}
function reduce<I,O>(array:I[], reducer:(reduced:O, value:I) => O, initialValue: O) : O {
@bwindels
bwindels / imagediff.html
Last active October 14, 2015 13:32
Tool to visualise difference between multiple images
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8"/>
<style>
body {
font-family: Helvetica, Arial;
font-size: 12px;
}
@bwindels
bwindels / bitwise-not.rs
Last active April 8, 2016 13:18
Rust snippets
fn main() {
let a = 0b10010001u8;
let b = !a;
println!("{:08b}", a);
println!("{:08b}", b);
}
@bwindels
bwindels / 10_linux.patch
Created October 5, 2016 20:58
coreboot support for fedora grub config file script
*** 10_linux.orig 2016-10-05 22:46:49.564011135 +0200
--- 10_linux 2016-10-05 22:43:03.187055937 +0200
***************
*** 85,98 ****
--- 85,101 ----
version="$2"
type="$3"
args="$4"
+ bios_vendor=$(dmesg | grep -oP 'BIOS vendor:\s*\K([^;]+)')
sixteenbit=""

#Steps to update libreboot on my x200

For desired libreboot release, download:

  • libreboot rom for x200 with 8mb of flash
  • libreboot util

Flash new libreboot release

  • boot kernel once with params nopat iomem=relaxed so flashrom can mmap /dev/mem
  • cp .rom file for ukqwerty with vesafb to libreboot.rom
pub trait WakeupChannel : Drop {
fn wakeup(&self)
}
pub trait WakeupBuilder {
fn create(callback: Fn<()>) -> WakeupChannel
}
mod apple {

#Things to do after installing linux on x200 laptop

Low level tuning

@bwindels
bwindels / deserializer.rs
Last active September 28, 2017 15:39
Rust JSON parser with FieldRef
struct Foo<'a> {
age: u32,
name: &'a str,
}
pub enum FieldRef<'a, 'b: 'a> {
Str(&'a mut &'b str),
UInt32(&'a mut u32),
}
use std::cell::{RefCell, RefMut, BorrowMutError};
enum Event {
Click,
Close,
Keystroke
}
trait Child<'a> {
fn handle_event(&'a mut self, event: Event, ctx: &'a RefCell<u64>) -> u64;
@bwindels
bwindels / no-di-container.md
Last active December 12, 2017 12:54
Why is a DI container a bad idea?
  • Compile time errors become runtime errors (in case of circular dependencies, ...)
  • You can't have async initialization
  • It's encourages a style I don't like: instead of initialization in a parent class method, most people just call ctor where you then have to do work. Think parent.createChildWithConfigFile("foo.ini") vs new Child("foo.ini") <- now you have to do I/O in your ctor.
  • It's way harder to understand in what order things get initialized
  • It's so easy to write it out by hand
  • It encourages you to make a very wide and flat tree/graph because it's so easy to just add one more dependency.
  • hides dependencies between projects. E.g. what dependencies are needed by storage? Stuff can be added from anywhere.
  • all dependency relations become hidden in this big grab-bag, there is no "this module needs this interfaces and exports these", the bootstrapper for a module just adds stuff to the container it's passed in, but you have no idea what it takes out of the container to created those values.