Skip to content

Instantly share code, notes, and snippets.

View bangedorrunt's full-sized avatar

bangedorrunt ヽ(ヅ)ノ bangedorrunt

  • Melbourne, Australia
View GitHub Profile
@bangedorrunt
bangedorrunt / using_mailboxes_in_elm.md
Created December 27, 2015 03:01 — forked from mgold/using_mailboxes_in_elm.md
Using Mailboxes in Elm: a tutorial blog post

Using Mailboxes in Elm

Max Goldstein | July 30, 2015 | Elm 0.15.1

In Elm, signals always have a data source associated with them. Window.dimensions is exactly what you think it is, and you can't send your own events on it. You can derive your own signals from these primitives using map, filter, and merge, but the timing of events is beyond your control.

This becomes a problem when you try to add UI elements. We want to be able to add checkboxes and dropdown menus, and to receive the current state of these elements as a signal. So how do we do that?

The Bad Old Days

@bangedorrunt
bangedorrunt / .spacemacs
Last active December 6, 2015 13:42
Spacemacs dotfile
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@bangedorrunt
bangedorrunt / rust_functor.rs
Last active March 3, 2020 10:05 — forked from srijs/rust-functor.rs
Rust Functor
use std::boxed::Box;
use std::option::Option;
use std::result::Result;
use Maybe::*;
#[derive(Debug, PartialEq, Eq)]
enum Maybe<T> {
Nothing,
Just(T),
}
@bangedorrunt
bangedorrunt / box_vs_ref.rs
Last active November 25, 2015 02:30
Rust tips
// Reference from: https://play.rust-lang.org/?gist=a571361967dc228330b3&version=stable
trait Shape {
fn draw(&self);
}
struct Square;
impl Shape for Square {
fn draw(&self) { println!("Square drawn."); }
}
let everythingIsDone = Rx.Observable.fromEvent(em, ‘everythingIsDone’);
let eventSource = Rx.Observable.fromEvent(em, ‘event’).takeUntil(everythingIsDone).toArray().toPromise();
@bangedorrunt
bangedorrunt / multi_by_10.js
Last active November 18, 2015 01:57
Basic recursion method
function multiBy10(n) {
// Setup a base return
if (n <= 1)
return 10
// Loop recursive here
else
return 10 + multiBy10(n-1)
}
/**
@bangedorrunt
bangedorrunt / basic_es6_generator.js
Last active November 17, 2015 01:05
First step of understanding ES6 promise-aware generator
// Provided that `request()` is a promise
function *something() {
var text1 = yield request('url1')
var text2 = yield request('url2')
var text3 = yield request('url3')
}
var it = something() // Start the something() generator
@bangedorrunt
bangedorrunt / rxjs_event_emitter.js
Created November 15, 2015 05:50
Pub Sub pattern with RxJS
// Reference from: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/howdoi/eventemitter.md
var hasOwnProp = {}.hasOwnProperty;
function createName (name) {
return '$' + name;
}
function Emitter() {
this.subjects = {};
@bangedorrunt
bangedorrunt / introrx.md
Created November 7, 2015 02:43 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@bangedorrunt
bangedorrunt / functor.js
Last active October 23, 2015 07:21
Functional JavaScript
// Functors apply a function to a wrapped value and then return a wrapped value
// Functors are chainable
// Functor::(a -> b) -> f(a) -> f(b)
class Wrapper {
constructor(val) {
console.log('Created a wrapped value ' + val);
this.val = val;
}
// Functor's `fmap` in Haskell
map(func) {