Skip to content

Instantly share code, notes, and snippets.

View aholachek's full-sized avatar

Alex Holachek aholachek

View GitHub Profile
@aholachek
aholachek / launch.json
Last active July 19, 2018 15:20
Simple VSCode Node.js launch config for 1) running currently open JS file 2) running jest tests for currently open file
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch current file",
"type": "node",
"request": "launch",
"program": "${file}",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v8.4.0/bin/node"
},
export default function addAnimation(animateIn, animateOut) {
return function wrapComponent(WrappedComponent) {
return class AnimationHOC extends Component {
state = { animatingOut: false }
componentDidMount() {
if (this.props.isVisible) animateIn(this.child)
}
@aholachek
aholachek / FLIP_animation_function.js
Last active December 16, 2017 04:01
React Animation Article Examples
export function animateGroups (ListComponent) {
const items = [...ListComponent.querySelectorAll('.item')]
const oldPositionDict = items.reduce((acc, item) => {
acc[item.dataset.id] = item.getBoundingClientRect()
return acc
}, {})
return function initiateAnimation () {
const transformPositionDict = {}
// Make sure to get the new array of item elements --
// React might have destroyed and created new DOM nodes
@aholachek
aholachek / .script-compiled.js
Last active June 1, 2017 17:02
Very simple responsive map of Asia
// load the data, find the svg container in the dom,
// and call createMap
d3.json('map-data.json', function(error, data){
var svg = d3.select('svg')
createMap(svg, data)
})
// put all logic in a nice reusable function
function createMap(svg, data) {
@aholachek
aholachek / .script-compiled.js
Last active June 3, 2017 01:53
Data Brushing with Small Multiples
d3.json('./stock-data.json', function(error, data){
createChart(document.querySelector('svg'), data)
})
// ========================================================
// I like to encapsulate d3 logic in a createChart function that returns an update
// function -- this makes it easy to re-use the logic e.g. with React
// ========================================================
function createChart (svg, data, options) {
@aholachek
aholachek / .script-compiled.js
Last active May 24, 2017 07:59
Animated Grouped/Stacked Bar Transitions
/*eslint no-undef: 0*/
function createChart (svg, data) {
// //normalize data
// Object.keys(data).forEach((d)=>{
// ["0", "1", "2", "3", "4", "5", "6"].forEach(k=>{
// if (d[k] === undefined) d[k] =
// })
// })
@aholachek
aholachek / .script-compiled.js
Last active May 21, 2017 10:39
Continuous Scale Exploration
var svg = d3.select('svg')
var margin = {top: 40, right: 40, bottom: 40, left: 40}
var width = svg.attr('width') - margin.left - margin.right
var height = svg.attr('height') - margin.top - margin.bottom
var g = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
var data = d3.range(100000).map(function (n){
if (n % 1000 === 0){
return { x : n, y : n}
}
@aholachek
aholachek / sample_snippets.cson
Last active April 6, 2017 19:56
Sample snippets.cson for Atom
".source.js":
"Mocha it()":
"prefix": "it("
"body": "it('$1', () => {$2})"
"functional component":
"prefix": "functional component"
"body": """
import React, {PropTypes} from 'react'