Skip to content

Instantly share code, notes, and snippets.

@tomatau
tomatau / App.js
Last active December 2, 2017 21:19
SSR React Router Redux Suggestion
import { Switch, Route } from 'react-router'
import { replace } from 'react-router-redux'
@connect(null, { replace })
class PrivateRoute extends React.Component {
componentWillMount() {
this.props.replace('/foo')
}
render() {
@tomatau
tomatau / sort.js
Created March 26, 2017 15:01
Sort Arrays
import assert from 'assert'
const sortByAge = (source) => source.sort((itemA, itemB) => itemA.age - itemB.age)
const ob = (age) => ({ name: ''+age, age })
assert.deepEqual(
sortByAge([ ob(1), ob(6), ob(2), ob(5), ob(3), ob(4) ]),
[ ob(1), ob(2), ob(3), ob(4), ob(5), ob(6) ]
)
@tomatau
tomatau / flatten.js
Last active March 26, 2017 12:49
Array Flatten
const flatten = (source) => {
const length = source.length
let i = 0
let flattened = []
for (; i < length; i++) {
// recursive call could reach stack limit
flattened = flattened.concat(
!Array.isArray(source[i]) ? source[i] : flatten(source[i])
)
#!/usr/bin/python
import pandas as pd
import statsmodels.api as sm
import math
import matplotlib.pyplot as plt
import numpy as np
loansData = pd.read_csv('loansData_clean.csv')
loansData['IR_TF'] = loansData['Interest.Rate'] < 12
import pandas as pd
import matplotlib.pyplot as plt
loansData = pd.read_csv(
'https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv'
)
loansData['Interest.Rate'] = loansData['Interest.Rate'].map(
lambda x: float(x.rstrip('%'))
)
loansData['Loan.Length'] = loansData['Loan.Length'].map(
@tomatau
tomatau / chi_squared.py
Last active August 29, 2015 14:25
Thinkful Unit 2 Lesson 2.3
from scipy import stats
# import matplotlib.pyplot as plt
import pandas as pd
import collections
loansData = pd.read_csv(
'https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv'
)
loansData.dropna(inplace=True)
freq = collections.Counter(loansData['Open.CREDIT.Lines'])
@tomatau
tomatau / prob_lending_club.py
Created July 14, 2015 20:57
tf-ds-u2-lesson2.2
#!/usr/bin/python
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as stats
# read the data
loansData = pd.read_csv(
'https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv'
)
@tomatau
tomatau / clickable-list-props.js
Created March 26, 2015 19:31
Reusable Components
propTypes: {
onClickItem: React.PropTypes.func.isRequired,
inputs: React.PropTypes.arrayOf(
React.PropTypes.shape({
text: React.PropTypes.node
})
)
},
getDefaultProps(){
@tomatau
tomatau / MyClickableList.js
Created March 26, 2015 19:27
Reversing Data Flow
let ClickableList = React.createClass({
render(){
let { inputs, onClickItem } = this.props;
return (
<ul>
{inputs.map((input,i)=>
<li key={i} onClick={onClickItem.bind(null, input)}>
{input}
</li>
)}
@tomatau
tomatau / MyForm.js
Last active August 29, 2015 14:17
Component Refs
let MyForm = React.createClass({
render(){
return (
<form onSubmit={this.handleSubmit}>
<input type="text" ref='my-input' />
</form>
)
},
handleSubmit(event){
event.preventDefault()