Skip to content

Instantly share code, notes, and snippets.

View barraponto's full-sized avatar

Capi Etheriel barraponto

View GitHub Profile
import csv
def csvfix(filepath):
with open(filepath) as inputfile:
zona = 'Zona Eleitoral'
for line in inputfile:
if line.startswith('ZONA'):
zona = line
else:

Regarding ORMs

Databases provide persistence to data. When the user sends data -- let's say a new product listing -- we read the data from the request and hold it in memory while we validate it or process it in any other way. But once we send the response, it will be erased from memory, lost forever unless it is stored somewhere else.

ActiveRecord is a method to deal with data that represents something, like a a new product. We model it by listing its attributes (price, color), validate

import React, { Component } from 'react';
import './App.css';
const Header = ({newGameHandler}) => (
<div className="header">
<button form="game" type="button" onClick={newGameHandler}>New Game</button>
</div>
)
const Form = ({guessHandler}) => (
@barraponto
barraponto / idletime.js
Last active April 3, 2024 11:17
ES6+ event-based browser idle timer.
const DOCUMENT_EVENTS = [
'mousemove', 'mousedown', 'click',
'touchmove', 'touchstart', 'touchend',
'keydown', 'keypress'
];
export class IdleTimer {
constructor(onIdleTimeout, timeout) {
this.onIdleTimeout = onIdleTimeout;
this.timeout = timeout;
import React from 'react';
import axios from 'axios';
import { Redirect } from 'react-router-dom';
import { Field, reduxForm, SubmissionError } from 'redux-form';
import { required, passwordLength } from '../form-validation';
import { login } from '../actions/auth';
export const LoginForm = ({ error, handleSubmit, submitting, submitSucceeded }) =>
(submitSucceeded) ?
(<Redirect to={{ pathname: '/' }} />) :
import React from "react";
import { Route, Redirect, withRouter } from "react-router-dom";
import { connect } from "react-redux";
const PrivateRedirect = ({ location }) => (
<Redirect to={{ pathname: "/login", state: { from: location } }} />);
const PrivateRoute = ({ component, loggedIn, ...passThroughProps }) => {
const Component = loggedIn ? component : PrivateRedirect;
return <Route component={ Component } { ...passThroughProps } />;
import React from 'react';
import axios from 'axios';
import { Field, reduxForm, SubmissionError } from 'redux-form';
import { required, passwordLength, matchConfirm } from '../form-validation';
const matchPasswords = matchConfirm('password', 'confirmPassword');
export const SignupForm = ({ error, handleSubmit, submitting }) => (
<form onSubmit={ handleSubmit }>
{ error && <p>{error}</p>}
import React from "react";
import { Route, Redirect } from "react-router-dom";
import { connect } from "react-redux";
const PrivateRedirect = (props) => (
<Redirect to={{ pathname: "/login", state: { from: props.location } }} />);
const PrivateRoute = ({ component, loggedIn, ...passThroughProps }) => {
const Component = loggedIn ? component : PrivateRedirect;
return <Route component={Component} {...passThroughProps} />;
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const userSchema = new mongoose.Schema({
username: {type: String, required: true},
password: {type: String, required: true}
});
userSchema.pre('save', function(next){
if (!this.isModified('password')) { return next() };
const express = require('express');
const passport = require('passport');
const jwt = require('jsonwebtoken');
const config = require('../config');
// @FIX: no need for curly braces and return here.
const createAuthToken = user => {
return jwt.sign({user}, config.JWT_SECRET, {
subject: user.username,