Skip to content

Instantly share code, notes, and snippets.

View matthiasak's full-sized avatar
📘
@hashicorp Terraform 💯 expression engine builds dep-trees of values

Matt Keas matthiasak

📘
@hashicorp Terraform 💯 expression engine builds dep-trees of values
  • Google
  • Houston, TX
View GitHub Profile
@matthiasak
matthiasak / react-iso.js
Created May 10, 2016 16:12
react-iso.js
import polyfill from "babel-polyfill"
const cluster = require('cluster')
import _router from 'koa-router'
const router = _router()
// middleware
import stat from 'koa-serve-static'
import conditional from 'koa-conditional-get'
import bodyParser from 'koa-bodyparser'
// simple fn that returns a map node
const node = (val=undefined) => {
let result = {}
if(val) result.val = val
return result
}
// hash fn
const hash = str => {
if(typeof str !== 'string') str = JSON.stringify(str)
@matthiasak
matthiasak / diy-routing.js
Last active March 28, 2016 16:51
Copy the following code into https://matthiasak.github.io/arbiter-frame/#// to see it run
const router = (routes, fn=(a,b)=>a(b)) => {
let current = null
const listen = () => {
window.addEventListener('hashchange', () => {
trigger(window.location.hashname.slice(1))
})
}
const trigger = path => {
@matthiasak
matthiasak / lazy sequences.js
Created March 25, 2016 19:54
lazy sequences with generators
const flatten = (...a) =>
a.reduce((a,v) => {
if(v instanceof Array)
return [...a, ...flatten(...v)]
return a.concat(v)
}, [])
const iter = (...a) =>
wrap(function*(){
let b = flatten(a)
@matthiasak
matthiasak / languages-that-compile-to-js.md
Created October 15, 2015 13:12
Languages that compile to JS (from CoffeeScript wiki)

CoffeeScript Family (& Friends)

Family (share genes with CoffeeScript)
  • Coco A CoffeeScript dialect that aims to be more radical and practical, also acts as a test bed for features that get imported in CoffeeScript.
    • LiveScript is a fork of Coco that is much more compatible with CoffeeScript, more functional, and with more features.
  • IcedCoffeeScript A CoffeeScript dialect that adds support for await and defer keywords which simplify async control flow.

Thanx! I got #1 to work, and pushed the changes, would u be able to let me know if this was what you had in mind, or did i overcomplicate it? I wrote a new function to accomplish this task, lines 167-201.

It looks fine :-)

Also, I can't figure out how to reuse functions when prototypes are invloved. example/ addItemTmpl(), i rewrote on lines 189 and 94 because wasnt sure how to call a prototype fn within a prototype fn, if that's possible?

You can write:

EtsyClient.prototype.addItemTmpl = function(listing) {
    $.get('./templates/item.tmpl').then(function(myTemplateHTML) {

http://glacial-inlet-3098.herokuapp.com/

my biggest questions right now:

  1. how to get the right listing when you click on one of the cards on page 1. see line 48

Here's what you had originally:

$('body').on('click', '.card', function() {
@matthiasak
matthiasak / day08
Created September 30, 2014 18:10
day08-HOU-TIY-FEE-Sept2014
/**
* 1. create a new repo on Github,
* 2. add this script file to your index.html and run it in the browser to get the output
* 3. debug and see the console.log() messages in the chrome dev tools
*/
/**
* PART 1
*

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@matthiasak
matthiasak / Inclusion-Exclusion Combinatorics
Created April 11, 2014 06:29
Combinatorics with constraints
function factorial(n){
return (n < 2) ? 1 : n * factorial(n-1);
}
function C(n,k){
return factorial(n) / (factorial(k) * factorial(n-k));
}
function maxPossibleConfigurations(a, b, c, n){
var args= [].slice.call(arguments);