Skip to content

Instantly share code, notes, and snippets.

View morganney's full-sized avatar
🌳

Morgan Ney morganney

🌳
View GitHub Profile
@morganney
morganney / generator-comprehension.js
Created August 2, 2015 22:50
Generator Comprehension Example
var it = (for (char of 'Hello World') char.codePointAt(0));
// now you can iterate over the collection of code points on-demand
console.log(it.next().value) // 72
console.log(it.next().value) // 101
@morganney
morganney / manual-iteration.js
Created August 1, 2015 18:29
Iterator Example
var objit = obj[Symbol.iterator]()
, item = objit.next()
;
while(!item.done) {
console.log(item.value);
item = objit.next();
}
@morganney
morganney / object-iteration.js
Created August 1, 2015 18:15
Object Iterator from Generator Example
'use strict';
var obj = {a: 'b'};
obj[Symbol()] = 'symbol';
obj[Symbol('foo')] = 'bar';
// use a generator to define default iterator for obj
obj[Symbol.iterator] = function* () {
var props = Object.getOwnPropertyNames(obj)
@morganney
morganney / d3-treemap-performance-entries.js
Last active August 29, 2015 14:06
D3 Treemap from Performance Entries Hierarchy
function drawD3Treemap(hierarchy) {
var treemap = d3.layout.treemap()
, color = d3.scale.category10()
, chart = d3.select('.html5')
, w = parseInt(chart.style('width'))
, h = parseInt(chart.style('height'))
, nodes = undefined
;
function altered(name) {
@morganney
morganney / resource-type-hierarchy.js
Last active August 29, 2015 14:06
A Nested JSON Hierarchy by Type from Resource Performance Entries
function getJSONResourceHierachy() {
var images = {png: 1, jpg: 1, jpeg: 1, gif: 1, tif: 1, tiff: 1, bmp: 1, ico: 1, svg: 1}
, entries = window.performance.getEntriesByType('resource')
, length = entries.length
, archy = {}
, entry = undefined
, name = undefined
, mt = undefined
;
@morganney
morganney / performance-entry.js
Created September 27, 2014 17:43
Resource Timing API Performance Entry
{
connectEnd: 318.862000000081
connectStart: 318.862000000081
domainLookupEnd: 318.862000000081
domainLookupStart: 318.862000000081
duration: 53.30899999989924
entryType: "resource"
fetchStart: 318.862000000081
initiatorType: "link"
name: "http://www.foobar.com/blog/wp-content/themes/foobar/style.css"
@morganney
morganney / socoapi-reverse-proxy-config.apacheconf
Last active August 29, 2015 14:00
Example of an Apache reverse proxy configuration for socoapi
NameVirtualHost *:80
<VirtualHost *:80>
ServerName myapp
DocumentRoot /path/to/myapp/doc/root
ProxyPreserveHost On
ProxyPass /socoapi http://127.0.0.1:3535
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ProxyPassReverse /socoapi http://127.0.0.1:3535
@morganney
morganney / socoapi-response.json
Last active May 30, 2016 20:46
Sample response from socoapi API
{
"facebook" : 1434,
"google" : 517,
"pinterest": 160,
"url" : "http//www.foobar.baz/?q1=v1&q2=v2"
}
@morganney
morganney / socoapi-server.js
Created April 20, 2014 02:13
Starting the socoapi server.
// Standalone
var socoapi = require('socoapi');
socoapi.listen('3535', 3600000, function() {
console.log('socoapi listening on port 3535');
});
// Embedded
var app = require('express')()
, socoapi = require('socoapi')
@morganney
morganney / restbus-full-links-example.js
Last active August 29, 2015 13:56
Hypertext links example for a restbus API agency resource.