Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Shaddox baddox

View GitHub Profile
View tiny2.csv
Flexport https://www.flexport.com San Francisco
SpaceX http://www.spacex.com Hawthorne, California
Coinbase https://www.coinbase.com/ San Francisco
InVision https://www.invisionapp.com/ New York City, New York
Carta (company) http://carta.com San Francisco
Ripple (cryptocurrency) https://ripple.com/ San Francisco
Calm (company) https://www.calm.com/ San Francisco
WeWork https://www.wework.com/ Manhattan, New York City
View 1k-rows.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 12 columns, instead of 1. in line 6.
Series_reference,Period,Data_value,STATUS,UNITS,Subject,Group,Series_title_1,Series_title_2,Series_title_3,Series_title_4,Series_title_5
CEPQ.S2371,1996.12,899,FINAL,Index,Capital Goods Price Index - CEP,"Price Index by Item - Plant, Machinery and Equipment (Base: Sept 1999 = 1000)",Glass and glass products,,,,
CEPQ.S2371,1997.03,884,FINAL,Index,Capital Goods Price Index - CEP,"Price Index by Item - Plant, Machinery and Equipment (Base: Sept 1999 = 1000)",Glass and glass products,,,,
CEPQ.S2371,1997.06,925,FINAL,Index,Capital Goods Price Index - CEP,"Price Index by Item - Plant, Machinery and Equipment (Base: Sept 1999 = 1000)",Glass and glass products,,,,
CEPQ.S2371,1997.09,932,FINAL,Index,Capital Goods Price Index - CEP,"Price Index by Item - Plant, Machinery and Equipment (Base: Sept 1999 = 1000)",Glass and glass products,,,,
CEPQ.S2371,1997.12,929,FINAL,Index,Capital Goods Price Index - CEP,"Price Index by Item - Plant, Machinery and Equipment (Base: Sept 1999 = 1000)",Glass and glass products,,,,
CEPQ.S2
@baddox
baddox / spinner_trig.js
Created Jan 22, 2020
Some trigonometry for drawing spinning squares inside other squares
View spinner_trig.js
function generateStationarySquares(maxRad, squareCount) {
const squares = [];
for (let i = 0; i < squareCount; i++) {
// Divide maxRad by sqrt(2) i times.
const rad = maxRad / Math.pow(Math.sqrt(2), i);
// We want the outermost stationary square to be rotated 90 degrees, like a
// diamond.
const ang = i % 2 === 0 ? Math.PI / 4 : 0;
squares.push([rad, ang]);
}
@baddox
baddox / preferred_numbers.py
Created Jul 12, 2019
Preferred numbers (Python)
View preferred_numbers.py
def preferred_numbers(x, precision = 2):
"""
>>> preferred_numbers(2)
[1.0, 3.16]
>>> preferred_numbers(3)
[1.0, 2.15, 4.64]
>>> preferred_numbers(5)
[1.0, 1.58, 2.51, 3.98, 6.31]
>>> preferred_numbers(10)
[1.0, 1.26, 1.58, 2.0, 2.51, 3.16, 3.98, 5.01, 6.31, 7.94]
@baddox
baddox / custom_hook_and_render_prop.js
Last active Nov 11, 2018
React custom hook and render prop
View custom_hook_and_render_prop.js
const renderPropFromHook = useHook => {
const Component = ({ children, ...rest }) => {
return children(useHook(rest));
};
return Component;
};
// `useCount` is my custom hook with a bunch of
// complicated hook usage inside.
const useCount = ({ initial }) => {
@baddox
baddox / LikeButton.js
Last active Oct 27, 2018
React LikeButton with Recompose and Redux connect
View LikeButton.js
import React from 'react';
// The main component definition (and default explort) is a completely dumb
// component. All it knows is whether `likes` is true or false, and how and
// when to call the `setLiked` function. It doesn't know or care about where
// its two props come from.
const LikeButton = ({ liked, setLiked }) => {
return (
<button onClick={() => setLiked(!liked)} className={liked && 'liked'}>
{liked ? 'Click to unlike' : 'Click to like'}
@baddox
baddox / strftime_examples.py
Last active May 15, 2019
Python strftime examples
View strftime_examples.py
from time import strftime
from datetime import datetime
tt = datetime(2018, 4, 2).timetuple()
strftime('%b. %-d, %Y', tt)
# 'Apr. 10, 2018'
strftime('%B %-d, %Y', tt)
# 'April 10, 2018'
View css_grid_test.html
<html>
<style>
body {
margin: 0;
background-color: #111;
font-family: sans-serif;
}
.wrapper {
@baddox
baddox / preferred_numbers.rb
Created Jul 30, 2015
Preferred number generator
View preferred_numbers.rb
# https://en.wikipedia.org/wiki/Preferred_number
def preferred_numbers(x, precision=2)
root = 10 ** (1 / x.to_f)
return x.times.map {|i| (root ** i).round(precision)}
end
<<EXAMPLES
> preferred_numbers(2)
@baddox
baddox / recursive_enumerable_flatten.rb
Created Mar 31, 2015
Recursive Enumerable flatten
View recursive_enumerable_flatten.rb
# Don't do this. It's fun, but stacks will overflow.
module Enumerable
def flatten_recursive(verbose=false, level=0)
car, cdr = self[0], self[1..-1]
is_enumerable = car.is_a?(Enumerable)
if verbose
indent = " " * level
if is_enumerable
puts "Recurring on Enumerable : #{indent} #{car.inspect}"
You can’t perform that action at this time.