Skip to content

Instantly share code, notes, and snippets.

@liammclennan
liammclennan / gist:9455524
Created March 9, 2014 22:10
React mixin that warns if a propTypes key is missing
define('validation', [], function() {
return {
allPropsSpecifiedMixing: {
componentDidMount: function() {
var unspecifiedPropKeys = _.difference(
_.keys(this.props),
_.keys(this.type.propTypes || {}).concat('ref'));
if (unspecifiedPropKeys.length) {
console.warn('Component ' +
@rmcafee
rmcafee / hash_extend.rb
Created May 19, 2009 18:18
Extend Ruby Hash with Useful Methods
class Hash
def except(*blacklist)
{}.tap do |h|
(keys - blacklist).each { |k| h[k] = self[k] }
end
end
def only(*whitelist)
{}.tap do |h|
(keys & whitelist).each { |k| h[k] = self[k] }
@max-mapper
max-mapper / readme.md
Created September 28, 2011 02:01
SLEEP - syncable.org

Your API does REST, but can it SLEEP?

SLEEP (Syncable Lightweight Event Emitting Persistence) is an emerging standard for distributed data sync using HTTP and JSON. A generalized version of CouchDB's much lauded built-in replication, SLEEP extends the REST architecture to define a way in which databases can offer syncable JSON APIs that foster open data innovation by allowing developers to replicate entire databases over the net.


SLEEP comes from the Apache CouchDB project which is now widely known for it's multi-master streaming HTTP + JSON replication. This is possible in part because of the CouchDB _changes feed, which is a particular API that lets you see if there have been any changes made to the database since last time you synchronized. CouchDB can efficiently implement the _changes feed because of one subtle difference between it and most other databases: it stores a history of all changes that happen to the database, including deletes.

If you synchronize data from a remote source and then the

@fdecampredon
fdecampredon / Container.js
Last active August 27, 2017 17:04
redux-relay
import React from 'react';
import { container } from 'redux-relay';
@container({
variablesFromState: (state) => ({myVariable: state.myState})
fragments: {
Relay.QL`
viewer {

This is a response to Bill Fisher regarding experience with Flux:

@abdullin Also, can you clarify what you mean by "solution structure"? I am thinking about revising the examples soon.

Currently all flux samples (that I've seen) group files into folders based on technical similarity. For example, stores go with stores, action creators reside in the same folder shared with the other action creators.

This pattern works quite well for smaller projects. It feels especially good for the sample projects of various MVC frameworks, when you have just a bunch of controllers, models and views.

However, as we discovered on some production projects, such approach doesn't scale well. At some point you end up with dozens of technically similar files per folder and logically messy solution.

@gcanti
gcanti / flow_tlp1.md
Last active April 6, 2018 19:34
Type level programming with Flow, encoding a finite state machine
// @flow

// based on State Machines All The Way Down
// An Architecture for Dependently Typed Applications
// https://eb.host.cs.st-andrews.ac.uk/drafts/states-all-the-way.pdf
// by Edwin Brady

//
// finite state machine
@tkafka
tkafka / LICENSE.txt
Last active September 5, 2019 13:38
Drop-in replacement for ReactCSSTransitionGroup that uses velocity.js instead of CSS transforms. Add your own transitions to `transitions` hash.
The MIT License (MIT)
Copyright (c) 2014 Tomas Kafka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@thegrandpoobah
thegrandpoobah / _.retry.js
Created May 5, 2011 14:34
Retry mixin for Underscore.js
_.mixin({
// Polls condition indefinitely every N milliseconds and executes
// a function once the condition has passed.
retry: function(func, cond, wait) {
var args = slice.call(arguments, 3);
if (cond()) {
func.apply(this, args);
} else {
_.delay.apply(this, [_.retry, wait, func, cond, wait].concat(args));
}
@PixelsCommander
PixelsCommander / proposal.md
Last active April 27, 2020 13:16
Rasterization API proposal

Rasterization API

Abstract

Rasterization API defines interface for making snapshots from HTML elements.

Introduction

@dblock
dblock / git-delete-merged-branches.sh
Created June 9, 2011 21:12
Delete merged git branches.
git branch --merged | grep -v master | xargs git branch -d
git branch -r --merged | awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' | xargs git push origin --delete