Skip to content

Instantly share code, notes, and snippets.

View tomprogers's full-sized avatar

Tom Rogers tomprogers

  • Minneapolis, MN
View GitHub Profile
@tomprogers
tomprogers / item-property-tallies.js
Created August 24, 2016 18:00
algorithm for counting the names and datatypes of properties of a set of (hopefully) similarly-shaped object
// before running this, define ITEMS as an array of objects whose props you wish to examine
items.reduce((tallies, asset) => {
Object
.keys(asset)
.forEach((prop) => {
if(tallies.hasOwnProperty(`${prop} (${typeof asset[prop]})`)) {
console.log(`has ${prop} (${typeof asset[prop]})`);
tallies[`${prop} (${typeof asset[prop]})`] += 1;
@tomprogers
tomprogers / react-native-list-view-clone-args.js
Created May 20, 2016 20:10
An explanation of the structures and interpretations of the arguments to cloneWithRowsAndSections
// somewhere, you had to set this up
const LVDS = new ListView.DataSource({
getSectionHeaderData: (blob, sectionId) => blob.sectionData[sectionId],
getRowData: (blob, sectionId, rowId) => blob.rowData[rowId]
});
// ... and then you had to feed data into it with this:
let newListData = LVDS.cloneWithRowsAndSections(blob, sectionIds, rowIdsBySection)
// but what do blob, sectionIds, and rowIdsBySection look like, and how are they used internally by ListView?
@tomprogers
tomprogers / react-native-list-view-eg.js
Last active May 20, 2016 19:30
Example code showing how to work with react-native's ListView, with sticky headers and lots of explanatory comments
// NOTE: I'm using a few ES6 features, like Arrow Functions and default argument values
// Hopefully they don't trip you up while reading this.
import React, { Component, ListView } from 'react-native';
import Moment from 'moment'; // only needed for my example
// I reuse this configuration everywhere. As a rule, each component creates just one of them,
// and since changing the dataset doesn't require mutating this object, I define it as a const.
//