Skip to content

Instantly share code, notes, and snippets.

@park-brian
park-brian / introrx.md
Created October 11, 2016 20:44 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@park-brian
park-brian / createElement
Last active May 11, 2017 03:41
createElement.js
/* Example usage:
* let el = createElement('div', {style: 'color: green'}, 'Hello world!');
* document.body.appendChild(el);
* /
export const createElement = (type, props, ...children) => {
if (type.constructor === Function)
return type(props);
@park-brian
park-brian / index.html
Last active August 29, 2017 03:07
simple redux
<!DOCTYPE html>
<html>
<head>
<script>
window.state = {counter: 0};
const listeners = [];
const reducer = (state, action) => ({
INC: {...state, counter: state.counter + 1},
@park-brian
park-brian / index.html
Last active August 29, 2017 03:06
actual redux
<!DOCTYPE html>
<html>
<body>
<span id="counter"></span>
<button id="inc">+</button>
<button id="dec">-</button>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>
<script>
const reducer = (state, action) => ({
@park-brian
park-brian / index.html
Last active August 29, 2017 19:01
d3 + google maps (continents)
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<style>
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
@park-brian
park-brian / FunctionalArray.php
Last active September 21, 2017 01:54
A simple class that wraps a PHP array in a "functional" way
<?php
/**
* A simple class that wraps a PHP array in a functional way.
*
* Example Usage:
*
* $val = (new FunctionalArray(range(1, 10)))
* ->map (function($value) { return $value * 1; })
* ->filter (function($value) { return $value > 5; })
@park-brian
park-brian / filedownloader.js
Last active August 8, 2018 20:34 — forked from DavidMah/filedownloader.js
File Download requests using jquery/POST request with psuedo ajax
// Takes a URL, param name, and data string
// Sends to the server.. The server can respond with binary data to download
jQuery.download = function(url, key, data) {
$('<form/>')
.attr('action', url)
.attr('method', 'post')
.append($('<input/>')
.attr('type', 'hidden')
.attr('name', key)
@park-brian
park-brian / index.html
Created February 15, 2018 23:39
Google Map Markers!
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
#map {
height: 100%;
}
@park-brian
park-brian / createFormObject.ts
Created June 19, 2018 17:39
Recursive FormBuilder which returns an AbstractControl
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
/**
* Creates a nested FormGroup, FormArray, or FormControl with validators
* from a given object
*/
export const createFormObject = (initial: any): AbstractControl => {
if (Array.isArray(initial)) {
// detemine if array contains ValidatorFn or ValidatorFn[]
// eg: use same syntax as formBuilder
<h1>{{ title }}</h1>
<button (click)="updateMessage()">
Click me!
</button>
<p *ngFor="let line of message">
{{ line }}
</p>