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
// 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 / 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) {
@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.
@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)