Skip to content

Instantly share code, notes, and snippets.

View AndrewIngram's full-sized avatar
🦊
Being foxy

Andy Ingram AndrewIngram

🦊
Being foxy
View GitHub Profile
function cx(classNames, namespace, theme) {
var classes;
var bemClasses = [];
if (typeof classNames == 'object') {
classes = Object.keys(classNames).filter(function(className) {
return classNames[className];
});
} else {
classes = classNames;
var namespace = 'mediacat'
function cx(classNames, options) {
var classes;
var states;
var bemClasses = [];
var baseClassName;
var stateClassName;
if (typeof classNames == 'object') {
@AndrewIngram
AndrewIngram / gist:5c79a3e99ccd20245613
Created December 11, 2014 00:24
Django Rest Framework field for reading a serializer but writing a primary key
class RichPrimaryKeyRelatedField(serializers.RelatedField):
def __init__(self, serializer, *args, **kwargs):
self.many = kwargs.get('many', False)
self.serializer = serializer
super(RichPrimaryKeyRelatedField, self).__init__(*args, **kwargs)
def to_internal_value(self, data):
try:
return self.get_queryset().get(pk=data)
export class Counter extends React.Component {
static get propTypes() {
return {
initialCount: React.PropTypes.number
};
}
static get defaultProps() {
return {
initialCount: 1
import React from 'react';
import shallowEqual from 'react/lib/shallowEqual';
class PureRenderComponent extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
}
import React from 'react';
import shallowEqual from 'react/lib/shallowEqual';
class PureRenderComponent extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
}
# Instead of this:
from django.http import Http404
from django.http.response import (
Http404, HttpResponse, HttpResponseNotAllowed, StreamingHttpResponse,
cookie
)
# Do this:
@AndrewIngram
AndrewIngram / gist:89a8a524a5b421677d15
Last active August 29, 2015 14:14
Sample ES6 module
"use strict"
import $ from 'jquery'; // 3rd-party imports
import Backbone from 'backbone';
import React from 'react/addons';
import BaseClase from 'ofs/utils/BaseClass'; // 1st-party imports
import doStuff from './doStuff'; // Relative imports
import React from 'react';
import DefaultEventPluginOrder from 'react/lib/DefaultEventPluginOrder';
import EventPluginHub from 'react/lib/EventPluginHub';
import EventPluginRegistry from 'react/lib/EventPluginRegistry';
import keyOf from 'react/lib/keyOf';
import ResponderEventPlugin from './ResponderEventPlugin';
import SwipeEventPlugin from './SwipeEventPlugin';
import React from 'react';
import DefaultEventPluginOrder from 'react/lib/DefaultEventPluginOrder';
import EventPluginHub from 'react/lib/EventPluginHub';
import EventPluginRegistry from 'react/lib/EventPluginRegistry';
import keyOf from 'react/lib/keyOf';
import ResponderEventPlugin from './ResponderEventPlugin';
import SwipeEventPlugin from './SwipeEventPlugin';