Skip to content

Instantly share code, notes, and snippets.

View treyhunner's full-sized avatar
🐍
💖

Trey Hunner treyhunner

🐍
💖
View GitHub Profile
@treyhunner
treyhunner / findccalbums.py
Last active March 19, 2019 00:07
Scour music subreddits for Creative Commons-licensed music on Bandcamp, SoundCloud, and Vimeo
"""Print CC-licensed music from the last month"""
import json
import requests
banned_strings = [
"blemmed.com",
"cuterthanpie.com",
"youtu",
@treyhunner
treyhunner / example.py
Last active August 29, 2015 14:07
Explanation of how variable names work in Python
def change_variable(x):
x = 100
a = 3
print(a)
change_variable(a)
print(a)
b = [1, 2]
@treyhunner
treyhunner / example.py
Created January 13, 2015 00:37
Dict splat packing/unpacking creates new dict
>>> inputs = {'a': 1, 'b': 2}
>>> def my_func(**kwargs):
... kwargs.update({'a': 3, 'c': 4})
...
>>> my_func(**inputs)
>>> inputs
{'a': 1, 'b': 2}
### Keybase proof
I hereby claim:
* I am treyhunner on github.
* I am treyhunner (https://keybase.io/treyhunner) on keybase.
* I have a public key whose fingerprint is 169A BEE4 05D0 E198 27FA 2F2F EA67 7E9F CDAD EA27
To claim this, I am signing this object:
@treyhunner
treyhunner / dabblet.css
Created January 30, 2015 02:01 — forked from LeaVerou/dabblet.css
Simple folded corners
/**
* Simple folded corners
*/
div {
background: yellowgreen; /* fallback */
background: linear-gradient(45deg, rgba(0,0,0,.4) 50%, transparent 0) 100% 0 / 25px 25px no-repeat,
linear-gradient(-135deg, transparent 18px, yellowgreen 0) 0 / auto; /* ceil(25/sqrt(2)) = 18 */
padding: 1em;
@treyhunner
treyhunner / readme.md
Created March 19, 2015 16:12
Front-end Code Playgrounds
@treyhunner
treyhunner / restaurants.md
Last active August 29, 2015 14:17
Some of my favorite restaurants

Japanese

[Kula Sushi][]

  • Uber-modern gamified conveyor belt sushi
  • Eat 100% nigiri. It's really cheap there. Rolls are just okay.

[Chopstix][] (katsu and curries)

  • Katsu Don
@treyhunner
treyhunner / after.js
Created April 22, 2015 02:40
example used to demonstrate promise chaining during 2015-04-21 SDJS BYOP night
var something = goGetSomething();
var anotherThing = goGetAnotherThing();
Promise.all([
something,
anotherThing
]).then(function() {
return doAnotherThing();
}).then(function() {
return lastThing();
@treyhunner
treyhunner / time_count_functions.py
Last active September 18, 2023 20:21
Test performance of different counting functions in Python
"""
Test performance of these counting methods:
- count_if_else: Set to 1 if not yet seen and increment otherwise
- count_if: Set to 0 if not yet seen, then increment regardless of containment
- count_exception: Attempt to increment and set to 1 if KeyError caught
- count_setdefault: Set default value to 0, then increment
- count_fromkeys: Create dict with necessary keys set to 0, then increment each
- count_set_and_comprehension: Create dict of items and counts using a set
- count_defaultdict: Increment count, automatically setting unseen values to 0
@treyhunner
treyhunner / doubled_numbers.md
Created February 7, 2016 19:21
List comprehensions lightning talk code copy-pasting examples

If we have a for loop that converts one list to another list using a transformation for each element:

doubled_numbers = []
for n in numbers:
    doubled_numbers.append(n * 2)

We can make that into a list comprehension by copy-pasting the assignment, the append value, and the for clause: