Skip to content

Instantly share code, notes, and snippets.

View joshwcomeau's full-sized avatar

Joshua Comeau joshwcomeau

View GitHub Profile
@joshwcomeau
joshwcomeau / gist:49dc6a7e7246437dd09e
Last active August 29, 2015 14:16
Chrome Extension Resources
@joshwcomeau
joshwcomeau / AnimalAndDog.js
Last active February 2, 2016 04:11
An example of concatenative inheritance
var animal = {
position: [0,0],
species: "mammal",
move: function(distance, axis) {
axis === 'x'
? this.position[0] += distance
: this.position[1] += distance;
}
}
@joshwcomeau
joshwcomeau / DogOutput.js
Last active August 29, 2015 14:19
Concatenative Inheritance merge output
console.log(dog);
// would return:
{
position: [0,0],
move: function(distance, axis) { ... },
species: "canine",
bark: function() { ... }
}
@joshwcomeau
joshwcomeau / ApplicationController.js
Created April 25, 2015 19:35
Application Controller
window.reqKitControllers.application = {
// Fetch an array of 'Emotion' objects from the server.
// Returns a promise.
fetchEmotions: function() {
return $.ajax(window.reqKitConstants.ApiEmotionIndex, {
method: 'GET',
contentType: "application/json",
headers: {
'Authorization': window.reqKitConstants.ApiKey
}
// Cat Index Controller
window.reqKitControllers.catIndex = _.extend({}, window.reqKitControllers.application, {
emotionSelector: "#select-emotion",
initialize: function() {
this.populateEmotionsSelect(this.emotionSelector, " ", true);
}
});
// Cat New Controller
@joshwcomeau
joshwcomeau / RequestKitten.js
Last active August 29, 2015 14:20
Requesting Kittens like mad!
$.ajax("http://requestkittens.com/cats", {
data: {
emotion: "grumpy",
imageSize: "full",
numOfResults: 10
},
headers: {
'Authorization': <your API key here>
}
});
@joshwcomeau
joshwcomeau / CatsIndexResponse.json
Last active August 29, 2015 14:20
cats Index response
{
"_items": [
{
"id": "553fff884c7f7f44fa6b7fe7",
"url": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-b469c2c29d887b46d9019839d9a70df4/full.jpg",
"emotion": "happy",
"source": {
"owner": "we-lovecats.tumblr.com",
"url": "http://40.media.tumblr.com/bdebb1aaa241e3faeb70233145c0cd87/tumblr_n6t7upX1LR1rouu9to1_400.jpg"
}
@joshwcomeau
joshwcomeau / EmotionsIndexResponse.json
Created April 27, 2015 18:19
emotions Index respose
{
"_items": [
{
"_id": "553ba848e4b0bde7020ac65d",
"name": "sad"
},
{
"_id": "553ba851e4b0bde7020ac65e",
"name": "happy"
},
@joshwcomeau
joshwcomeau / CatsShowResponse.json
Created April 27, 2015 18:27
CatsShowResponse
{
"_id": "553d327e594a1b5f1b13f198",
"url": {
"thumb": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/thumb.jpg",
"small": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/small.jpg",
"medium": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/medium.jpg",
"full": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/full.jpg"
},
"emotion": [
{
@joshwcomeau
joshwcomeau / redux_react.js
Created December 11, 2015 12:29
Really basic Redux + React example
"use strict";
const connect = ReactRedux.connect;
const Provider = ReactRedux.Provider;
// REDUCER
const defaultState = { count: 0 };
const appReducer = (state = defaultState, action) => {
switch ( action.type ) {
case 'increment':
return _.extend({}, state, { count: state.count+1 });