Skip to content

Instantly share code, notes, and snippets.

requirejs.config({
baseUrl: '/js',
paths: {
'backbone': 'lib/backbone',
'underscore': 'lib/underscore',
'jquery': 'lib/jquery',
'hbs': 'lib/require-handlebars-plugin/hbs',
'templates': '../templates'
}
});
@dlmanning
dlmanning / node-forecast-proxy.js
Last active August 29, 2015 13:57
simple api proxy that queues requests when cached data is out of date.
var request = require('request');
var moment = require('moment');
var http = require('http');
var colors = require('colors');
var latLong = "45.5330,-122.6894";
var apiKey = "a75c248d7b83806b66b281dd33e96e36";
var url = 'https://api.forecast.io/forecast';
url += '/' + apiKey + '/' + latLong;
var { Transform } = require('stream'); // use require for non-ES6 Node modules
class MyStream extends Transform {
constructor (options) {
super({
lowWaterMark: 0,
encoding: 'utf8'
});
}
@dlmanning
dlmanning / vanishing-closure.js
Created January 22, 2015 04:06
The mysterious case of the vanishing outer closure
zip();
zap();
zoom();
function zip () {
var a = 1;
(function () {
// v8 will remove the outer closure
debugger;
@dlmanning
dlmanning / index.html
Last active August 29, 2015 14:15
d3 minimap with draggable minimap window
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>minimap</title>
<style>
#ref {
display: none;
}
</style>
@dlmanning
dlmanning / app-working.jsx
Last active August 29, 2015 14:19
react-svg-flexbox
import React from 'react';
import { FlexContext, FlexBox } from 'flex';
const { Component } = React;
class Container extends Component {
render () {
console.log('Rendering Container');
return (
<g>
@dlmanning
dlmanning / webpack.config.js
Created May 9, 2015 17:20
My webpack config
const path = require('path');
module.exports = {
entry: './main.js',
output: {
publicPath: '/assets',
filename: 'bundle.js'
},
@dlmanning
dlmanning / classy.js
Last active August 29, 2015 14:21
classy and convenient
class Foo extends Bar () {
constructor () {
super();
this.bar = 'fubar';
}
}
export function FooFactory (...args) {
return new Foo(...args);
}
@dlmanning
dlmanning / does-not-work.jsx
Last active August 29, 2015 14:23
Why doesn't the spread operator work in JSX?
import { default as React, Component } from 'react';
function makeElements () {
return [
<h1>Hello</h1>,
<h1>World,</h1>,
<h1>How</h1>,
<h1>are</h1>,
<h1>you?</h1>
]
@dlmanning
dlmanning / makeConnector.js
Last active November 20, 2015 22:33
Connect higher-order component from internal closure.
export function makeConnector (store) {
return function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
// same stuff
return function wrapWithConnect(WrappedComponent) {
return class Connect extends Component {
// same stuff
constructor(props) {
super(props)
this.store = props.store || store
// same stuff