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 / 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);

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 / 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
*

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() {

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) {
// 1. Write a class to support the following code:
function Person(name){
this.name = name;
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
@matthiasak
matthiasak / gist:3005030
Created June 27, 2012 15:59
Socket io and Express
var express = require('express'),
app = express.createServer(),
io = require('socket.io'),
sio,
_ = require('underscore');
// Configuration
app.configure(function() {
app.set('views', __dirname + '/views');
// text coords
texts.push({x: Building.width/2, y:Building.length/2, obj: {name:Building.name}, attr:{'font-size':'15px'} });
texts.push({x: Building.width/2, y:Building.length, obj: _.find(Building.surfaces, function(el){ return el.swa; }), attr:{'font-size':'10px'} });
texts.push({x: 0, y:Building.length/2, obj: _.find(Building.surfaces, function(el){ return el.ewb; }), attr:{'font-size':'10px', rotate:-90} });
texts.push({x: Building.width/2, y:0, obj: _.find(Building.surfaces, function(el){ return el.swc; }), attr:{'font-size':'10px'} });
texts.push({x: Building.width, y:Building.length/2, obj: _.find(Building.surfaces, function(el){ return el.ewd; }), attr:{'font-size':'10px', rotate:90} });
/// later used in
@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 / 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 => {