Skip to content

Instantly share code, notes, and snippets.

View CptLemming's full-sized avatar

Ashley Wilson CptLemming

View GitHub Profile
@CptLemming
CptLemming / isAssoc.php
Created April 23, 2014 13:43
Check if an array is associative
function isAssoc($arr) {
return array_keys($arr) !== range(0, count($arr) - 1);
}
# Install xapian & python bindings to a virtualenv
#
# Build dependencies are for CentOS
#
# Assumptions:
# - destination virtualenv is activated
#
# Starting point was this Vagrant box:
# - http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box
# - Also installed:
@CptLemming
CptLemming / Modal.jsx
Created January 8, 2015 18:12
React Modal - Foundation & Reflux
/** @jsx React.DOM */
var React = require('react/addons');
var Reflux = require('reflux');
var cx = React.addons.classSet;
var ModalAction = require('./ModalAction');
var ModalStore = require('./ModalStore');
var Modal = React.createClass({
@CptLemming
CptLemming / MacOSX mysql_tzinfo_to_sql workaround
Last active August 29, 2015 14:17
MacOSX mysql_tzinfo_to_sql workaround
# https://bugs.mysql.com/bug.php?id=68861
# mysql_tzinfo_to_sql creates bad data
mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/bad_tzinfo.sql
echo "SET SESSION SQL_MODE = '';" > /tmp/mysql_tzinfo_to.sql
cat /tmp/bad_tzinfo.sql >> /tmp/mysql_tzinfo_to.sql
mysql -uroot mysql < /tmp/mysql_tzinfo_to.sql
@CptLemming
CptLemming / app.jsx
Created April 14, 2015 13:12
Morearty & React Router example
/**
* This example shows using Morearty and React Router together in a single app.
*
* Both libraries expect to be the 'top-level-item' by default, which causes conflict.
* The `currentRoute` here is especially important, as this allows the components to re-render
* when the Route changes. Without this the `shouldComponentUpdate` of Morearty will
* return `false`, preventing routing.
*
* Morearty - https://github.com/moreartyjs/moreartyjs
* React Router - https://github.com/rackt/react-router
@CptLemming
CptLemming / fields.py
Created August 6, 2015 09:36
Django 1.8 comma separated email field
from django import forms
from django.core.validators import validate_email, EMPTY_VALUES
from django.utils.translation import ugettext_lazy as _
class CommaSeparatedEmailField(forms.Field):
description = _('Email addresses')
def __init__(self, *args, **kwargs):
self.token = kwargs.pop('token', ',')
@CptLemming
CptLemming / UNDO_README.md
Last active September 18, 2020 16:17
Undo command pattern in Redux

Undo command pattern in Redux

This is my attempt at at implementing undo (no redo for now) in Redux.

Middleware is used to implement a command pattern approach to undo / redo, where incoming actions are identified as Commands and added to a stack.

When the undo() action is raised the middleware halts the current action instead calling the undo method of the previous Command.

Pitfalls

  • Due to implementing via middleware, only one stack may exist for the entire application.
@CptLemming
CptLemming / docker_kill.sh
Created April 12, 2017 08:14 — forked from evanscottgray/docker_kill.sh
kill all docker containers at once...
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt