Skip to content

Instantly share code, notes, and snippets.

@harshai
harshai / restful.js
Created May 8, 2017 18:32 — forked from BinaryMuse/restful.js
Express API with Async/Await
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {
// atom settings
@harshai
harshai / 1-react-websockets-reflux.md
Last active August 29, 2015 14:25 — forked from danawoodman/1-react-websockets-reflux.md
Using WebSockets with Reflux and React

WebSockets + Reflux + React

Using WebSockets, React and Reflux together can be a beautiful thing, but the intial setup can be a bit of a pain. The below examples attempt to offer one (arguably enjoyable) way to use these tools together.

Overview

This trifect works well if you think of things like so:

  1. Reflux Store: The store fetches, updates and persists data. A store can be a list of items or a single item. Most of the times you reach for this.state in react should instead live within stores. Stores can listen to other stores as well as to events being fired.
  2. Reflux Actions: Actions are triggered by components when the component wants to change the state of the store. A store listens to actions and can listen to more than one set of actions.
@harshai
harshai / SassMeister-input.scss
Created November 6, 2014 03:57
Generated by SassMeister.com.
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
/* Alias */
$active-tile-background-color: #4C9CEA;
$inactive-tile-background-color: #FFF;
$active-text-color: #FFF;
@harshai
harshai / chaining
Last active August 29, 2015 13:56
Demonstrating functional aspects of JavaScript
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var sumOfEvenSquares = numbers.filter(function(num){
return num % 2 == 0;
}).map(function(evenNum){
return evenNum * evenNum;
}).reduce(function(prev, next){
return prev + next;
}, 0);