Skip to content

Instantly share code, notes, and snippets.

@jackcallister
jackcallister / base_controller.rb
Created April 29, 2014 12:13
API Base Controller
class API::BaseController < ApplicationController
respond_to :json
before_action :set_default_format, :assert_valid_format!, :authenticate_from_token!, :authenticate_client!
protected
def authenticate_from_token!
token = request.headers['X-Authentication-Token']
id = request.headers['X-Authentication-Id']
App.Router.map ->
@resource 'schedules', ->
@resource 'schedule', { path: '/:schedule_id' }, ->
@resource 'events'
App.EventsRoute = Ember.Route.extend
model: ->
@modelFor('schedule').get('events')
App.Schedule = DS.Model.extend
@jackcallister
jackcallister / avatar.rb
Created August 24, 2014 03:36
Default avatars
require 'net/http'
class Avatar
attr_accessor :email, :response
def initialize(email)
@email = email
end
def self.default_urls
@jackcallister
jackcallister / gist:599a5de9eefbc41bc33f
Created November 7, 2014 03:41
Webpack Component Config
module.exports = {
entry: './example/main.js',
output: {
filename: './build/bundle.js'
},
module: {
loaders: [
{test: /\.js$/, loader: 'jsx-loader'}
]
}
// 1. Components load for the first time.
// 2. An action causes the node to be removed.
// 1. Element will enter the DOM
componentWillEnter: function(callback) {
callback();
console.log('will enter');
},
// // 1. Element is now in the DOM
@jackcallister
jackcallister / index.html
Created December 25, 2014 09:14
React JS quick start guide // source http://jsbin.com/rohin
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-with-addons-0.12.0.js"></script>
<meta charset="utf-8">
<title>React JS quick start guide</title>
<style id="jsbin-css">
body {
margin: 0;
background: #E8E8E8;
@jackcallister
jackcallister / package.json
Created February 10, 2015 05:58
Run parallel tasks
"scripts": {
"start": "npm run webpack & npm run serve",
"webpack": "webpack -w",
"serve": "cd example && python -m SimpleHTTPServer"
}
@jackcallister
jackcallister / react.js
Created February 13, 2015 01:43
React Object
var React = {
Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
only: onlyChild
},
Component: ReactComponent,
DOM: ReactDOM,
// WebUtils
WebUtils = {
fetchMe: function(opts) {
return new Promise(function(resolve, reject) {
request.get(`${SOUNDCLOUD_URL}/me`)
.query(opts)
.end((err, res) => { me: res.body });
}
});
}
import 'babel/polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router';
import { reduxRouteComponent, routerStateReducer } from 'redux-react-router';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import BrowserHistory from 'react-router/lib/BrowserHistory';
import routes from '../shared/components/routes';
import * as reducers from '../shared/reducers/index';