Skip to content

Instantly share code, notes, and snippets.

View bangedorrunt's full-sized avatar

bangedorrunt ヽ(ヅ)ノ bangedorrunt

View GitHub Profile
@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) {
@bangedorrunt
bangedorrunt / es6_restructure.js
Last active November 15, 2015 05:50
ES6 Restructure Pattern
// Taken from: http://es-discourse.com/t/partial-default-arguments/120/7
var defaults = {
options: {
remove: true,
enable: false,
instance: {}
},
log: {
warn: true,