Skip to content

Instantly share code, notes, and snippets.

@LevelbossMike
LevelbossMike / d3.html
Created May 6, 2012 17:22
creating table from array of json with d3
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<table id="split">
<thead></thead>
<tbody></tbody>
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@afrex
afrex / Trailing Comma of Death regex
Created September 4, 2013 08:03
Use this regex in a search to retrieve trailing comma's of death within your application. This comma's will cause inconsistent behaviour in Internet Explorer browsers.
,\s*?\]|,\s+}
@jimkang
jimkang / flattenTreeDepthFirst.js
Created December 17, 2013 04:10
A function to flatten a tree, depth-first. It's an implementation of this algorithm: http://cl.ly/image/1X1i0b1v1H2d Assumes the tree is built via nodes that have a property named 'children' which is an array of other nodes.
function flattenTreeDepthFirst(rootNode) {
var nodes = [rootNode];
var childArraysQueue = [];
if (rootNode.children) {
childArraysQueue.push(rootNode.children);
}
while (childArraysQueue.length > 0) {
var children = childArraysQueue[0];
@myndzi
myndzi / gist:03eb5c42e8385470403c
Created June 21, 2014 17:22
How to use Sequelize with a UNIX domain socket
var sequelize = new Sequelize('postgres:/tmp');
var CM = sequelize.transactionManager.ConnectorManager;
sequelize.transactionManager.ConnectorManager = function (sequelize, config) {
var cm = new CM(sequelize, config);
cm.pg.defaults.database = 'database_name';
return cm;
}
sequelize.getQueryInterface().QueryGenerator
@Neilos
Neilos / README.md
Last active October 6, 2023 00:26
Bi-directional hierarchical sankey diagram

This is a demonstration of a bi-directional hierarchical sankey diagram produced in javascript, html and css using d3. (Refresh page to generate new random data)

Sankey diagrams represent flows between nodes by varying the thickness of the connecting links.

This diagram was based off of Mike Bostock's sankey diagram, but additionally incorporates bi-directionality into the flow and caters for hierarchical relationships between nodes to allow drill down into the data.

All javascript code to generate the diagram markup is contained in the app.js file, but the underlying calculations are performed using a custom plugin: bihisankey.js.

@springmeyer
springmeyer / bench.js
Created March 20, 2015 18:43
benchmark.js example: testing an async function
'use strict';
var path = require('path');
var fontnik = require('../');
var Benchmark = require('benchmark');
var opensans = path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf');
var suite = new Benchmark.Suite();
@thgaskell
thgaskell / gist:5987fccbd8473b5ef78f
Last active September 21, 2018 02:49
Introduction to Sequelize Migrations

What are Migrations

Just like how we use Git to version control source code, we use migrations to manage the state of our database schemas.

I'm not really sure what that means...

Imagine you're working on project with another developer, and you're both tasked with creating a specific part of an event planning application. Let's say you are in charge of creating the Users and your friend is going to create the Events.

Let's say you and your friend divided the work in a way so that neither of you will have to to use each other's code to finish your tasks. While you're working on your part of the application, you only really need to touch the Users table when you are working with the database.

Before you begin

Make sure that the project you are in is a node project (it has a package.json) and you have already installed and initialized sequelize (npm install --save sequelize, sequelize init). Also make sure that your config.json file has the correct credentials to connect to your database.

@ejsuncy
ejsuncy / README.md
Last active April 6, 2018 13:08
View Chrome Websocket Frames as Formatted JSON
@evanwill
evanwill / gitBash_windows.md
Last active April 26, 2024 03:58
how to add more utilities to git bash for windows, wget, make

How to add more to Git Bash on Windows

Git for Windows comes bundled with the "Git Bash" terminal which is incredibly handy for unix-like commands on a windows machine. It is missing a few standard linux utilities, but it is easy to add ones that have a windows binary available.

The basic idea is that C:\Program Files\Git\mingw64\ is your / directory according to Git Bash (note: depending on how you installed it, the directory might be different. from the start menu, right click on the Git Bash icon and open file location. It might be something like C:\Users\name\AppData\Local\Programs\Git, the mingw64 in this directory is your root. Find it by using pwd -W). If you go to that directory, you will find the typical linux root folder structure (bin, etc, lib and so on).

If you are missing a utility, such as wget, track down a binary for windows and copy the files to the corresponding directories. Sometimes the windows binary have funny prefixes, so