Skip to content

Instantly share code, notes, and snippets.

View abohannon's full-sized avatar

Adam Bohannon abohannon

View GitHub Profile
@abohannon
abohannon / tictactoeconstanttime.js
Created December 23, 2018 18:08
TicTacToe game of any size that determines a winner in O(1)
class TicTacToe {
constructor(size) {
this.size = size
this.center = Math.floor(this.size / 2)
this.state = {
board: [],
score: [],
move: 0,
}
class StackSet {
constructor(maxSize) {
if (arguments.length < 1) {
throw new Error ('Woops, maxSize is required!')
}
this.stacks = [[]]
this.maxSize = maxSize
}
const INITIAL_STATE = {};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case ACTION_TYPE: {
const newState = {};
return {...state, ...newState};
}
default:
return state;
@abohannon
abohannon / README-Template.md
Created December 29, 2017 03:42 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@abohannon
abohannon / PrivateRoute.js
Created December 22, 2017 19:23
React/Redux Auth with Private Route Component
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
const PrivateRoute = ({ component: Component, authed, ...rest }) => (
<Route
{...rest}
render={props => (
authed
? <Component {...props} />
: <Redirect to="/login" />
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const routes = require('./routes');
app.use(bodyParser.json());
app.use(express.static(`${__dirname}/public`));
routes(app);
@abohannon
abohannon / Atom Sync
Last active September 30, 2017 17:58 — forked from bdegannes/Atom Sync
automatic update by http://atom.io/packages/sync-settings
// Atom Sync Settings
@abohannon
abohannon / index.js
Last active August 20, 2017 04:52
Gist for leaderboard react app
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import registerServiceWorker from './registerServiceWorker';
import axios from 'axios';
class Board extends React.Component {
constructor(props) {
super(props);
@abohannon
abohannon / eloquent-javascript-exercises.js
Last active July 20, 2017 23:52
Eloquent Javascript Exercise Solutions
// My answers to the exercises in Eloquent Javascript
// Looping a triangle
var myStr = '';
for (var i = 1; i < 7; i++){
console.log(myStr += "#");
}
[
{
"quote": "I will be the greatest jobs president that God ever created.",
"author": "Donald Trump",
"index": 1},
{
"quote": "When Mexico sends its people, they're not sending their best. They're sending people that have lots of problems...they're bringing drugs, they're bringing crime. They're rapists.",
"author": "Donald Trump",
"index": 2
}, {