Skip to content

Instantly share code, notes, and snippets.

View mwq27's full-sized avatar

Marques Woodson mwq27

  • Project44
  • Chicago
View GitHub Profile
import eventTracking from './events';
import { createStore, combineReducers, applyMiddleware } from 'redux';
const trackEvent = (properties, state) => {
ReactGA.event(properties); // Track event to google analytics
// Here we can get extra data from our state to attach to the event.
const bigQueryRecord = createRecord(buildRecordParam(properties, state));
postBigQueryEvent(bigQueryRecord); // Track event to BigQuery
};
const events = {
'AUTH/LOGIN_SUCCESS': {
category: 'auth',
action: 'login',
eventDataOne: 'user.name',
},
'AUTH/INVALID_LOGIN_ATTEMPT': {
category: 'auth',
action: 'invalid login attempt',
eventDataOne: 'user.email',
const trackingMiddleware = (store: Store<any>) => (next: Dispatch<any>) => (action: Action) => {
if (action.type === '@@router/LOCATION_CHANGE') {
const nextPage = `${action.payload.pathname}${action.payload.search}`;
trackPage(nextPage, store.getState());
}
return next(action);
};
function trackPage(page: string, state: any) {
ReactGA.set({
const translator = {
"Hello": "Hola"
};
function spanish(strings, ...values) {
return strings.reduce(function(str, val, idx) {
return str + (idx > 0 ? translator[values[idx - 1]] : '') + val;
}, '');
}
function foo(strings, ...values) {
return strings.reduce(function(str, val, idx) {
/*
We do the 'idx > 0 ? values[idx - 1]' part because of the starting point in the accumlator ('').
That will be the first section of the string.
*/
return str + (idx > 0 ? values[idx - 1] : '') + val
}, '');
}
const name = 'Marques';
function foo(strings, ...values) {
console.log("Strings - ", strings);
console.log("Values - ", values);
}
const name = 'marques';
foo`My name is ${name}.`;
// Strings - ["My name is ", "."]
// Values - ["marques"]
@mwq27
mwq27 / gist:7aa2822c248389bc4243
Last active August 29, 2015 14:18
Dynamic tabs
import {
Component,
Template,
For,
If,
bootstrap,
Parent,
DynamicComponent} from 'angular2/angular2';
import MovieFactory from './services/movieFactory';
@mwq27
mwq27 / gist:8346934be9a6451ae01d
Created February 3, 2015 18:06
Example of ES6 generator and a call to the nodejs Stripe API
var jobs = {
generatorCC(chargeId, amount) {
stripe.charges.capture(chargeId, {amount}, function(err, charge) {
if (err) {
it.throw(err);
}
it.next(charge);
}.bind(this));
},