Skip to content

Instantly share code, notes, and snippets.

@kolodny
kolodny / handling auth in redux
Last active August 26, 2015 20:37 — forked from mattiamanzati/handling auth in redux
Auth handling in redux.
Before reading:
This is a soft auth check. Auth check should always be done server side, if not, your rest api are not checking correctly for auth.
1. Auth is in the store.
You need to setup constants for AUTH_SET_TOKEN and AUTH_LOGOUT,
then create the action creators authSetToken(token) and authLogout() action creators.
Then setup a reducer that when AUTH_SET_TOKEN is dispatched, sets the internal state to {token: token},
and when logout is dispatched, clears it.
Now setup a utility function isLoggedIn(state) function, that only checks in state.auth.token exists, this is a soft check.
@kolodny
kolodny / LICENSE.txt
Last active August 27, 2015 18:12 — forked from xem/LICENSE.txt
Challenge: Executing more than 140 JS characters in a tweet!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
import React, { PropTypes } from 'react';
import { inputItem, label } from './styles';
export default React.createClass({
propTypes: {
handleLogin: PropTypes.func.isRequired,
},
handleLogin(e) {
e.preventDefault();
+ BRANCH_TO_CHECKOUT='__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
+ echo BRANCH_TO_CHECKOUT = '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
BRANCH_TO_CHECKOUT = __sync__0b3465aa338b5fdadc1b67eef7a079e53881de76
+ '[' '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76' == '' ']'
+ echo we need to checkout '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
we need to checkout __sync__0b3465aa338b5fdadc1b67eef7a079e53881de76
+ git fetch
+ git checkout '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76'
error: pathspec '__sync__0b3465aa338b5fdadc1b67eef7a079e53881de76' did not match
any file(s) known to git.
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});
@kolodny
kolodny / run.js
Last active August 29, 2015 14:03
Simple koa like function
function run(gen) {
step();
function step(value) {
var result = gen.next(value);
if (result.value instanceof Promise) {
result.value.then(step);
} else if (result.value instanceof Array) {
Promise.all(result.value).then(step);

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

#!/usr/bin/env bash
if [ "$2,$3" == "message," ]
then
new_msg=$(echo -n "$(git rev-parse --abbrev-ref HEAD): " | cat - $1)
echo $new_msg > $1
fi
@kolodny
kolodny / list.md
Last active August 29, 2015 14:05
@kolodny
kolodny / repl.js
Last active August 29, 2015 14:05
var logged;
var logPre;
var returned;
var $0;
var p = prompt('Enter expression to evaluate');
do {
try {
logged = [];
returned = $0 = eval(p);
try {