Skip to content

Instantly share code, notes, and snippets.

View treyhunner's full-sized avatar
🐍
💖

Trey Hunner treyhunner

🐍
💖
View GitHub Profile
@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;
### 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 / 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}
@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 / 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 / some_file.js
Created May 24, 2014 17:58
Example of indentation correction problems
var some_variable = some_function(an_argument,
another_argument);
var soome_variable = some_function(
an_argument,
another_argument
);
@treyhunner
treyhunner / find_audiobooks.py
Last active August 29, 2015 14:01
Search for DRM-free audiobooks
#!/usr/bin/env python
"""
Search downpour.com and emusic.com for DRM-free audiobooks
Usage::
./find_audiobooks.py <title>...
File released to the public domain under CC0 license:
http://creativecommons.org/publicdomain/zero/1.0/deed
@treyhunner
treyhunner / findccmusic.py
Created May 13, 2014 17:38
Find Creative Commons Music
#!/usr/bin/env python
"""
Find Creative Commons Music
Provide names of musical artists and the script returns any relevant URLs for
FreeMusicArchive.org, Jamendo.com, and Magnatune.com.
Usage::
$ ./findccmusic.py <artist name>...
@treyhunner
treyhunner / example.py
Last active December 24, 2015 02:59
Using single-dispatch generic functions (PEP 443) to implement an extensible JSON encoder To use with Python 2.6 to 3.3, install singledispatch from PyPI.
from decimal import Decimal
from json_singledispatch import encode
@encode.register(set)
def encode_set(obj):
return encode(list(obj))
@treyhunner
treyhunner / datetime_modulo.py
Last active May 20, 2020 01:47
Python modulo support for datetime
import datetime as dt
class datetime(dt.datetime):
def __divmod__(self, delta):
seconds = int((self - dt.datetime.min).total_seconds())
remainder = dt.timedelta(
seconds=seconds % delta.total_seconds(),
microseconds=self.microsecond,
)