Skip to content

Instantly share code, notes, and snippets.

View timbuckley's full-sized avatar

Tim Buckley timbuckley

  • Aline
  • NYC
View GitHub Profile
@timbuckley
timbuckley / EmployeeList.js
Created December 19, 2016 03:43
Helping ppl on the internet
export class EmployeeList extends React.Component {
state = {
employees: [],
isLoading: true
}
componentDidMount() {
if (localStorage.token) {
this.loadEmployeesData()
}
@timbuckley
timbuckley / how-effective-sampling-is.py
Last active June 4, 2017 23:01
Simulates doing a thousand polls at a 1.5k sample size from a population of 256 million. Most any poll was off was by 4.5%, while average variance was just 1.19%.
import random
american_adult_population = int(245e6)
# Warning: This array is HUGE!
# The array is just the numbers from 0 to 245,000,000
usa_array = range(american_adult_population)
actual_average = float(american_adult_population / 2)
sample_amount = 1500
import qualified Data.Map as M (Map, empty, insertWith, toList)
import Data.Foldable
import Data.List
example_csv = "rest1,item1\nrest1,item2\nrest3,item1\nrest3,item2\nrest2,item3\nrest1,item5\nrest2,item2"
csvToDict :: String -> M.Map String [String]
csvToDict = foldToDict . map splitOnComma . lines
where
splitOnComma = words . map (\c -> if c == ',' then ' ' else c)
@timbuckley
timbuckley / hangman-no-types-w-arrow.hs
Last active August 7, 2018 19:25
Solving Hangman in Haskell
module HangmanGuesser (main) where
import Data.List (intersect, nub, sort)
import Data.Char (toLower)
import Data.Tuple (swap)
import Data.Map as M (Map, fromListWith, toList)
main = do
corpus <- readFile "web2"
@timbuckley
timbuckley / schema.js
Created December 20, 2017 16:00
Example schema setup of normalizr
import { Schema, arrayOf } from 'normalizr'
let userSchema = new Schema('user', options)
let nbhdSchema = new Schema('nbhd', options)
let itemSchema = new Schema('item', options)
let commentSchema = new Schema('comment', options)
let nbhdsSchema = arrayOf(nbhdSchema)
userSchema.define({
nbhds: nbhdsSchema
@timbuckley
timbuckley / basic-fizzbuzz-haskell.hs
Last active December 21, 2017 20:07
Comparing fizzbuzz implementations in Haskell and JavaScript
fizzes = cycle ["", "", "Fizz"]
buzzes = cycle ["", "", "", "", "Buzz"]
fbs = zipWith (++) fizzes buzzes
nums = map show [1..]
fizzbuzz n = take n (zipWith max nums fbs)
-- Usage:
-- fizzbuzz 3
-- -> ["1", "2", "Fizz"]
@timbuckley
timbuckley / sequelize-migration-file-generator.js
Created August 18, 2020 19:22 — forked from agodin3z/sequelize-migration-file-generator.js
Creates migration files for existing sequelize models
#!/usr/bin/env node
const fs = require('fs');
const models = require('../models');
for (const model in models) {
const tableName = models[model].tableName;
let defaultValue = '';
let onUpdate = '';
import React from 'react';
function Spenses({ items }) {
function deleteItem({ id, amount }) {
// Delete the item.
}
return (
<>
{items.map((item, index) => (