Skip to content

Instantly share code, notes, and snippets.

View jamesattard's full-sized avatar

James A. jamesattard

View GitHub Profile
export const fetchUser = () => async dispatch => {
const res = await axios.get("/api/current_user");
dispatch({ type: FETCH_USER, payload: res });
};
export const fetchUser = () => {
return function(dispatch) {
axios
.get("/api/current_user")
.then(res => dispatch({ type: FETCH_USER, payload: res }));
};
};
import axios from 'axios';
const ROOT_URL = 'http://localhost:3090';
export function signinUser({ email, password }, callback) {
return function(dispatch) {
axios.post(`${ROOT_URL}/signin`, { email, password })
// If request is good...
.then(response => {
class Signin extends Component {
handleFormSubmit({ email, password }) {
this.props.signinUser({ email, password }, () => {
this.props.history.push('/feature');
});
}
...
render() {
@jamesattard
jamesattard / redux_connect.js
Created October 1, 2017 12:13
Connecting Redux states and actions to a component
function mapStateToProps({ products }) {
return { products };
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ fetchProducts }, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(ProductList);
@jamesattard
jamesattard / timeseries_binning.py
Created August 30, 2017 07:45
Pandas binning over timeseries
from datetime import datetime
from datetime import date
import numpy as np
import pandas as pd
data = {
'date': ['2014-05-01', '2014-05-01', '2014-05-02', '2014-05-02', '2014-05-02', '2014-05-03', '2014-05-03', '2014-05-04', '2014-05-04', '2014-05-08'],
'score': [34, 25, 26, 15, 15, 14, 26, 25, 62, 41]
}
$ docker inspect containerid
...
"Mounts": [
{
"Type": "bind",
"Source": "/var/mysql",
"Destination": "/mysql_data",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
# Restore from Docker repo
$ docker run mysql
# Restore from Docker tarball
$ docker load -i mysql.tar
$ docker images # To confirm that it has been loaded locally
$ docker run mysql
# First get ID of running container
$ docker ps
CONTAINER ID ...
5776d1849024 ...
# Next we take a snapshot of the docker container by first pausing (-p) the container
$ docker commit -p 5776d1849024 mysql
e09f9ac65c8b3...
# The commit arg saves the entire snapshot as a docker image with a name mysql:
# Backup database Globals
su - postgres -c "pg_dumpall -g --file=/tmp/globals.sql;"
# Backup all databases
su - postgres -c 'psql -At -c "SELECT datname FROM pg_database WHERE NOT datistemplate"' | \
while read f;
do su - postgres -c "pg_dump --format=c --file=/tmp/$f.sqlc $f";
done;