Skip to content

Instantly share code, notes, and snippets.

Thomas Shaddox baddox

Block or report user

Report or block baddox

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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}"
@baddox
baddox / kippt_to_pinboard.rb
Last active Aug 29, 2015
Pull bookmarks from Kippt API, upload via Pinboard API
View kippt_to_pinboard.rb
# Instructions
# install required packages by running:
# gem install json typhoeus awesome_print
# Download this .rb into a new directory on your PC (called something like "pinboard" or whatever)
# Fill out KIPPT_USERNAME, KIPPT_API_TOKEN, and PINBOARD_AUTH_TOKEN (below) by changing xxx to the real value.
# Run the script by running
View gist:730475fc6dba15eeb28a
### Keybase proof
I hereby claim:
* I am baddox on github.
* I am shaddox (https://keybase.io/shaddox) on keybase.
* I have a public key whose fingerprint is 326A 3C60 FFEE 147E 9611 6560 413A 661B 220C B38D
To claim this, I am signing this object:
@baddox
baddox / lol.rb
Created Jun 2, 2014
Some Ruby lols
View lol.rb
a = [1,2,3]
# => [1, 2, 3]
enum = a.map!
# => #<Enumerator: [1, 2, 3]:map!>
enum.map(&:to_s)
# => ["1", "2", "3"]
a
You can’t perform that action at this time.