Skip to content

Instantly share code, notes, and snippets.

View reducer_magic.js
// Switch
const applicationReducer = (state, action) => {
switch (action.type) {
case "FETCH_PACKAGES/START":
case "FETCH_DEPENDENCIES/START":
return {
...state,
fetch_count: state.fetch_count + 1
};
View bigtest.js
it("should create new state when an action is namespaced", async () => {
// Types
const ACCUMULATOR = "ACCUMULATOR";
const ADD = "ADD";
const SUBTRACT = "SUBTRACT";
const MULTIPLY = "MULTIPLY";
// Action creators
function add(value) {
return createAction(namespace(ACCUMULATOR, ADD), value);
@RobinMalfait
RobinMalfait / benefits.md
Last active Nov 16, 2017
Brilliant or bananas: deterministic classNames
View benefits.md
  1. Determenistic classNames
  2. No context switching, the styles are in the same file as the component
  3. Allows for easy deletability (if that's a word), in pure CSS files you can have the problem that you don't (always) know if you can uberhaupt delete the css or not
  4. We still allow for nested styles like:
import { Button } from './Button';
const Accordion = styled.div`
  // We don't need to know which class `.Button` uses, in pure css we _do_ need to know which one
  ${Button} {
View Example.js
const output = {
_: ["a", "b"],
foo: "bar",
baz: true
};
const sgray = ({ _, ...input }) =>
[
..._,
...Object.keys(input).reduce((acc, key) => {
@RobinMalfait
RobinMalfait / Switch.js
Created Nov 15, 2017
classNames util example
View Switch.js
const classNames = (...classes) => classes.filter(Boolean).join(' ');
// No need to default to an empty string as className
function Switch({on, className, ...props}) {
return (
<div className="toggle">
<input
className="toggle-input"
type="checkbox"
/>
View y-combinator.js
/**
* The Y-Combinator
*/
const y = fn => (f => f(f))(f => fn(x => f(f)(x)));
const factorial = y(fac => n => {
return n < 2 ? 1 : n * fac(n - 1);
});
const fibonacci = y(fib => n => {
View dimens.xml
<dimen name="text_spacing">4dp</dimen>
<dimen name="small_text">12sp</dimen>
View NN_1499862320857.json
{
"inodes": 4,
"hnodes": 16,
"onodes": 2,
"wih": {
"rows": 16,
"cols": 4,
"matrix": [
[
-1.1898033052663801,
View NN_1499861736186.json
{
"inodes": 4,
"hnodes": 16,
"onodes": 2,
"wih": {
"rows": 16,
"cols": 4,
"matrix": [
[
-0.5788905302255863,
View NN.json
{
"inodes": 4,
"hnodes": 16,
"onodes": 2,
"wih": {
"rows": 16,
"cols": 4,
"matrix": [
[
-0.023081422145953902,