Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
AndrewRayCode / gist:b4ac61b6d301e30d37e9
Last active August 29, 2015 14:17
Better React ClassSet
// Lets you call classSet with strings *and* objects
// Usage: classSet({a: true, b: false}, 'class1', null, 'class2'); class="a class1 class2"
function classSet() {
var classes = [],
arg, x, key;
for( x = 0; x < arguments.length; x++ ) {
arg = arguments[ x ];
if( typeof arg === 'object' ) {
componentDidMount: function() {
UserStore.on( 'change', this.onStoreChange );
},
componentWillUnmount: function() {
UserStore.off( 'change', this.onStoreChange );
@AndrewRayCode
AndrewRayCode / gist:caef6fc3991823fced0f
Last active August 29, 2015 14:20
NodeJS convert CSV to JSON object with headers
var csv = require('csv');
csv.parse(fs.readFileSync('./csv_with_headers.csv'), function(err, data) {
// Store the headers row
var headers = data[0];
// Remove the headers row
data.shift();
var objects = _.map(data, function(csvRow) {
LINE 1: ...T JOIN likes ON shaders"."id = likes"."shader_id" where "pub...
^
}).catch(function( error ) {
var errorPosition = Number(error.position),
msg = error.toString(),
query = msg.replace(/^.+: | - .+?$/g, ''),
sqlMsg = msg.replace(/^.+ - /g, ''),
context = 50,
leftTruncate = Math.max( errorPosition - context, 0 );
console.error( query + ';' );
console.error( error.severity + ': ' + sqlMsg );
/**
* What is it:
* Require an image relative to a base image folder and include @2x if it's a retina screen.
* Works with webpack and only requires one image path (as opposed to react-retina-image,
* which requires specifying both regular and @2x paths). Depends on npm package 'is-retina'
* and node's 'path'
* Usage:
* import requireRetina from './require_retina.js'; // this file
* <img src={requireRetina('your_image.png')} />
*/
let entities = {
\' ': { 'entity': '&nbsp;', 'number': '&#32;', 'description': 'Space' }
}
@AndrewRayCode
AndrewRayCode / gist:8ab6bfa5e82138881bfc
Last active August 29, 2015 14:24
See which parts of facebook.com are in React
setInterval(function() {
Array.prototype.slice.call(document.querySelectorAll('[data-reactid]')).forEach(function(element) {
element.style.background = 'rgba(255,0,0,0.1)';
});
}, 500);
hasParent( child, parent ) {
let node = child.parentNode;
while( node != null ) {
if( node === parent ) {
return true;
}
node = node.parentNode;
}
return false;
}
/* vertex */
uniform mat4 modelMatrix;
varying mat4 matrix;
...
void main() {
vPosition = position;
matrix = modelMatrix;
/* fragment */