Skip to content

Instantly share code, notes, and snippets.

Greg Babiars gbabiars

Block or report user

Report or block gbabiars

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View events.js
// In JSX, callback can get passed directly as part of api
<MyComponent onSomething={handler} />
// With events, there is a disconnect between the event publisher and the consumer of the event
// Some parent, but could be multiple, hard to follow
let myComponent = this.querySelector('my-component');
myComponent.addEventListener('something', handler);
gbabiars / ghost-to-gatsby.js
Created May 20, 2017
A script to migrate posts from Ghost's exported json to Gatsby
View ghost-to-gatsby.js
const fs = require('fs');
const path = require('path');
const moment = require('moment');
const json = require('./greg-babiarss-blog.ghost.2017-05-13.json');
.filter(p => p.status === 'published')
.forEach(({title, slug, published_at: published, markdown}) => {
const date = moment(published).format('YYYY-MM-DD');
const content =
View redux-with-rxjs.js
const createStore = (reducer, initialState) => {
let dispatcher$ = new Rx.Subject();
let state$ = new Rx.BehaviorSubject(initialState);
dispatcher$.scan(reducer, state$.getValue()).subscribe(state$);
return {
dispatch(action) {
gbabiars / Scores.js
Created Dec 20, 2015
Basic example of RxJS and React
View Scores.js
import React from 'react';
import axios from 'axios';
import Rx from 'rxjs';
export default class App extends React.Component {
constructor(props) {
this.state = {
scores: []
gbabiars / Ember Data Camelcase serializer
Created Aug 11, 2013
An example of the overrides needed to use camel case routes and json.
View Ember Data Camelcase serializer
App.Serializer = DS.RESTSerializer.extend({
keyForAttributeName: function(type, name) {
return name;
keyForBelongsTo: function(type, name) {
var key = this.keyForAttributeName(type, name);
if (this.embeddedType(type, name)) {
return key;
gbabiars / Grunt Proxy Server
Last active Sep 6, 2016
Grunt Connect Server with Proxies
View Grunt Proxy Server
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
module.exports = function(grunt) {
watch: {
all: {
files: ['Gruntfile.js']
connect: {
gbabiars / Qunit Sinon cache test
Created Jul 11, 2013
An example of how to unit test caching within a function that only makes one
View Qunit Sinon cache test
test('calling myFunc twice with the same url should only make one request to that url', function() {
var fakeServer = sinon.fakeServer.create(), // initialize fake server
myModule = myModule(), // whatever you need to do to instantiate your system under test
url = '/user/12',
callback = function() {}; // does nothing
fakeServer.autoRespond = true; // make sure the fake response is sent after every request
fakeServer.respondWith('GET', url,
[200, { 'Content-Type': 'application/json' }, '[{ "id": 12, "name": "John Doe" }]']); // define your fake response that the url will send
gbabiars / Extend With Mixin
Last active Dec 19, 2015
Examples of how to create Backbone view classes with mixins.
View Extend With Mixin
var mixin1, mixin2, mixinArray;
mixin1 = {
something: function() {
return 'something';
mixin2 = {
another: function() {
View dabblet.css
.board { width: 500px; height: 500px; background-color: #ff6a00 }
You can’t perform that action at this time.