Skip to content

Instantly share code, notes, and snippets.

View kandros's full-sized avatar
:bowtie:
o.o

Jaga Santagostino kandros

:bowtie:
o.o
View GitHub Profile
@kandros
kandros / redux-is-smarter-than-you-think.md
Created April 14, 2017 14:48 — forked from armw4/redux-is-smarter-than-you-think.md
Optimizing your react components via redux....shouldComponentUpdate for free and more...

The Beginning

Yes...it's true...redux is smart....smarter than you even know. It really does want to help you. It strives to be sane and easy to reason about. With that being said, redux gives you optimizations for free that you probably were completely unaware of.

connect()

connect is the most important thing in redux land IMO. This is where you tie the not between redux and your underlying components. You usually take state and propogate it down your component hiearchy in the form of props. From there, presentational

@kandros
kandros / data.js
Created February 16, 2017 20:29 — forked from ryanflorence/data.js
// routes.js
const routes = [
{
path: '/',
component: Home,
exact: true
},
{
path: '/gists',
component: Gists
@kandros
kandros / foo.js
Created January 29, 2017 21:41 — forked from ryanflorence/foo.js
const addAccountToTransactions = (txs, accounts) => (
txs.map(tx => (
// add the relationship
{
...tx,
account: accounts[tx.accountKey]
}
))
)
@kandros
kandros / Ref.js
Created January 29, 2017 21:41 — forked from ryanflorence/Ref.js
import React, { PropTypes, Component } from 'react'
import { getRef, listToArray } from '../utils/firebase'
import { ErrorMessage, Loading } from '../Theme'
/*
```js
<Ref path="/somewhere">
{({ error, loaded, value }) => (
// `value` is an object w/ keys
@kandros
kandros / mongoose-findOrCreate.js
Created October 9, 2016 23:05 — forked from niksumeiko/mongoose-findOrCreate.js
Mongoose schema static `findOrCreate` method in ES6/7 async/await syntax
import mongoose from 'mongoose';
let schema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
password: { type: String, required: true }
});
schema.statics.findOrCreate = async (conditions, opt_attr) => {
let document = await User.findOne(conditions);
@kandros
kandros / code.js
Last active August 11, 2016 20:34
testing the obvious
function fetchAllProjects() {
return dispatch => {
console.log('1')
dispatch(xxx())
dispatch({ type: 'REQUEST_ALL_PROJECTS' });
console.log('2')
ProjectsApi.getAllProjects()
.then(projects => {
dispatch({ type: 'SUCCESS_ALL_PROJECTS', projects: fromJS(projects) });
})
@kandros
kandros / elixir_timer_interval.exs
Created July 31, 2016 17:13
Set an interval in elixir-lang using erlang timer module
:timer.apply_interval(1000, IO, :puts, ["weeeee"]) # millisends, module, function as atom, list of arguments
function validateID (id) {
//"If ID Document Type is 'Identity Card' then Document Number should be in format XXXDDDDDD (three letters and six digits). To verify the correctness letters
//should be changed to numbers using follwing table (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
//10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35). Each from received 9 numbers should be multiplied by corresponding
//number from the following list (7, 3, 1, 9, 7, 3, 1, 7, 3). After adding results division by 10 should be equal to 0."
if (id.length === 0) {
return false;
}
@kandros
kandros / pesel_validation.js
Created September 10, 2015 09:07
Javascript validatio of pesel
function validatePesel (pesel) {
// PESEL:
// 11 digits numbers. Last digit is control digit verified against expression for the first 10 digits. Exp: (1*a + 3*b + 7*c + 9*d + 1*e + 3*f + 7*g + 9*h + 1*i + 3*j) last digit of the result is substracted from 10 and compared with the control digit.
var reg = /^\d{11}$/;
if (!reg.test(pesel)) {
return false;
}
var dig = (""+pesel).split("");