Skip to content

Instantly share code, notes, and snippets.

View bwindels's full-sized avatar

Bruno Windels bwindels

  • Brest region, France
View GitHub Profile
@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.
@bwindels
bwindels / ui-libs-custom-data-sources.md
Last active June 9, 2020 08:17
Custom Data Sources in UI libraries

Custom Data Sources in UI libraries

Lists

Implement a custom data source

@bwindels
bwindels / base64.rs
Created February 20, 2018 22:28
In-place base64 decoder
fn main() {
const ENCODED : &'static [u8] = b"aGVsbG8gd29ybGQ=";
//const ENCODED : &'static [u8] = b"aGVlbGxvIHdvcmxk";
let mut encoded = [0u8; 16];
assert_eq!(ENCODED.len(), encoded.len());
for i in 0..ENCODED.len() {
encoded[i] = ENCODED[i];
}
let decoded = base64_decode(encoded.as_mut()).unwrap();

How Rx Scheduling works

Given a chain of Rx operators, you can run certain parts of the chain on a different scheduler. SubscribeOn sets the initial scheduler of the chain, and when you call ObserveOn, the rest of the chain starts running on that scheduler, until you call ObserveOn again. You can call SubscribeOn at any point, and calling it multiple times makes little sense. ObserveOn applies to the rest of the chain from there on, so calling it multiple times makes a lot of sense. Nice diagram: http://reactivex.io/documentation/scheduler.html

Observable.From(...) ----------\
    v                          |
   Map                         |-- runs on threadpool
    v                          |
  Filter ----------------------/
    v
ObserveOn(UIScheduler)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function runWorker() {
function createMessage(n) {
return {
"foo": "bar",
"body": "hello world " + n,
"date": Date.now()
@bwindels
bwindels / extract-root-certs.js
Created June 1, 2018 22:48
Extract root certs from mozilla csv file
//get file from https://ccadb-public.secure.force.com/mozilla/IncludedCACertificateReportPEMCSV
const parse = require('csv-parse');
const fs = require('fs');
let data = fs.readFileSync(process.argv[2], {encoding: 'utf8'});
parse(data, {}, (err, lines) => {
lines.forEach(line => {
let name = line[0];
name = name.substr(0, 15);
let pem = line[28];
pem = pem.substr(1, pem.length - 2);
@bwindels
bwindels / counted_msg.js
Created August 1, 2018 08:37
Insert 10 counted messages anywhere
//use as: sh -c 'sleep 0.3; xdotool type "$(node counted_msg.js)"; xdotool key KP_Enter'
const fs = require('fs');
const counterPath = '/home/bwindels/Temp/counter';
function getCounter() {
const str = fs.readFileSync(counterPath, 'utf8');
return parseInt(str, 10);
}
function setCounter(n) {
fs.writeFileSync(counterPath, n.toString(), {flag: 'w'});
@bwindels
bwindels / splitter.html
Last active August 16, 2018 17:29
html splitter with flexbox and injectable distribution algorithm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
body {
padding: 0;
margin: 0;
}
@bwindels
bwindels / borrowed_or_owned_string_struct.rs
Created August 29, 2018 12:04
rust struct that works for both String and &str members
struct Event<S> {
id: S
}
impl<T: AsRef<str>> Event<T> {
fn print(&self) {
println!("event({})", self.id.as_ref());
}
}
<html>
<body>
<script>
function asPromise(req) {
return new Promise((resolve, reject) => {
req.onerror = (e) => reject(e.target.error);
req.onsuccess = (e) => resolve(e.target.result);
});
}