Skip to content

Instantly share code, notes, and snippets.

View davidbgk's full-sized avatar
🚪
Let’s escape GAFAM+ when/while we can!

David Larlet davidbgk

🚪
Let’s escape GAFAM+ when/while we can!
View GitHub Profile
@davidbgk
davidbgk / dimoc.md
Last active August 29, 2015 14:15 — forked from jamesgpearce/dimoc.md

TLDR: a React component should either manage its own state, or expose a callback so that its parent can. But never both.

Sometimes our first impulse is for a component to entirely manage its own state. Consider this simple theater seating picker that has a letter for a row, and a number for a seat. Clicking the buttons to increment each value is hardly the height of user-interface design, but never mind - that's how it works:

/* @flow */
var React = require('react');

var Letter: React.ReactClass = React.createClass({
  getInitialState: function(): any {

return {i: 0};

// declaration
function foo (n) { return n + 1; }
// expression
// note, fat arrow functions have very different meaning (usually what I want, though)
var foo = function (n) { return n + 1; };
var foo = (n) => { return n + 1; };
var foo = n => n + 1;
// object methods

Coming from this post, the solution is very simple and doesn't need jQuery.

This is the function that will disable multiple submits to any form that has such attribute

function disableMultipleSubmits() { // by Andrea Giammarchi - WTFPL
  Array.prototype.forEach.call(
    document.querySelectorAll('form[disablemultiplesubmits]'),
    function (form) {
      form.addEventListener('submit', this, true);

Tiny Content Framework

About the Project

This is a tiny content strategy framework focused on goals, messages, and branding. This is not a checklist. Use what you need and scrap the rest. Rewrite it or add to it. These topics should help you get to the bottom of things with clients and other people you work with.

Contribute

There’s more to come, and I’d love to hear what you think. Give me feedback on Twitter (@nicoleslaw) or by email (nicole@nicolefenton.com). We all benefit from sharing our ideas and creating standards. Onward.

@davidbgk
davidbgk / bling.js
Last active August 29, 2015 14:23 — forked from paulirish/bling.js
/* bling.js */
window.$ = document.querySelectorAll.bind(document)
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn)
}
NodeList.prototype.__proto__ = Array.prototype
sudo apt-get -y install python-virtualenv libxslt1-dev libxml2-dev python-virtualenv-tools
export VERSION=`date +"%Y.%m.%d"`.$BUILD_NUMBER
mkdir -p build/usr/share/python
virtualenv build/usr/share/python/sentry
build/usr/share/python/sentry/bin/pip install -U pip wheel distribute
build/usr/share/python/sentry/bin/pip uninstall -y distribute
build/usr/share/python/sentry/bin/pip install sentry[mysql] dj-database-url hiredis dj-redis-url django-redis-cache
@davidbgk
davidbgk / current_page_middleware.py
Created April 28, 2010 16:20
Django: Current Page Middleware
"""
Current Page Middleware.
This module provides a middleware that implements a mechanism to
highlight a link pointing to the current URL.
Thanks @davidbgk and @samueladam for improvements & optimizations
"""
import re
@davidbgk
davidbgk / classinstancemethod
Created April 30, 2010 07:21 — forked from ianb/Lightning talk
when you want to use both a classmethod and the function with a class instance
# classinstancemethod, when you want to use both a classmethod and the function with a class instance
## Descriptors
## Anything with __get__ and optionally __set__:
class classinstancemethod(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, type=None):
@davidbgk
davidbgk / gist:805600
Created February 1, 2011 08:46 — forked from adamcharnock/gist:389875
Double metaphone
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed
@davidbgk
davidbgk / data-uri.py
Created July 26, 2011 13:24 — forked from jsocol/data-uri.py
Give an image, get a data-uri
#!/usr/bin/env python
"""Command line script to convert a file, usually an image, into a data URI
for use on the web."""
import base64
import mimetypes
import os
import sys