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
let items = [
{category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football"},
{category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball"},
{category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball"},
{category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch"},
{category: "Electronics", price: "$399.99", stocked: false, name: "iPhone 5"},
{category: "Electronics", price: "$199.99", stocked: true, name: "Nexus 7"}
]
const app = () => {
@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)
// 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 / 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');
// 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"

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