Skip to content

Instantly share code, notes, and snippets.

View kawa-kokosowa's full-sized avatar
🌴
On vacation

Kawa Kokosawa kawa-kokosowa

🌴
On vacation
View GitHub Profile
@kawa-kokosowa
kawa-kokosowa / astversion.py
Last active November 16, 2015 23:18
Retreive __version__ from a package's __init__.py, without executing or using regular expressions.
"""Demo the ability to use Abstract Syntax Trees to
retrieve the value of __version__ from a package's
__init__.py, without executing __init__.py or using
regular expressions.
Works in Python 2 and Python 3.
See Also:
* https://greentreesnakes.readthedocs.org/en/latest/tofrom.html
* http://eli.thegreenplace.net/2009/11/28/python-internals-working-with-python-asts/
@kawa-kokosowa
kawa-kokosowa / model.html
Last active December 4, 2015 19:21
Hackday Challenge
<html>
<head>
<style>
.wowimsocool {
display: block;
width: 632px;
height: 836px;
background: #000;
background-image: linear-gradient(to right, rgba(255, 0, 0, 255), rgba(255, 0, 0, 255)),
linear-gradient(to right, rgba(0, 255, 0, 255), rgba(0, 255, 0, 255)),
@kawa-kokosowa
kawa-kokosowa / sync-youtube.sh
Last active March 3, 2016 17:22
Sync music on YouTube to Local Drive with youtube-dl
#!/bin/zsh
# Sync a youtube playlist as mp3
#
# Requires youtube-dl: brew install youtube-dl
#
# Max quality.
youtube-dl -o "/Users/lillianlemmer/Music/Youtube/%(title)s.%(ext)s" \
--extract-audio --audio-format mp3 --audio-quality 0 \
--download-archive ~/.cache/youtube-dl/archive -q \
@kawa-kokosowa
kawa-kokosowa / card_combos.py
Last active November 24, 2017 00:22
find combinations of two playing cards when summed equal that value
"""Find all the combinations of two cards being added
to equal a range of values 2-26, because 2 is the lowest
value that has a combination, and 26 is the highest value
which has a combination.
King 13
Queen 12
Jack 11
Ace 1
@kawa-kokosowa
kawa-kokosowa / jaccard_similarity.py
Last active November 25, 2017 23:42
Jaccard Similarity Function in Python 3 (builtins only)
"""Jaccard similarity of two sets using builtin Python 3 only."""
import doctest
def jaccard_similarity(x: set, y: set) -> float:
"""Get the Jaccard similarity of two sets.
Example:
>>> jaccard_similarity({1,2,3,4}, {2,3,5,7})
@kawa-kokosowa
kawa-kokosowa / jaccard_similarity_bags.py
Created November 23, 2017 11:01
Jaccard Similarity of Bags (python3; builtin only)
"""Jaccard Similarity of Bags
Using artificial restriciton of using only builtin Python 3 only.
"""
import doctest
def multiset_intersection_cardinality(x: list, y: list) -> int:
@kawa-kokosowa
kawa-kokosowa / python-style-nuance.md
Last active December 20, 2017 23:58
Lily's Python Style: The particularities I've learned over the years

Lily's Nuanced Python Style

This style guide elaborates on pycode-style.

Syntax

When to use quotes...

  • ''' is for string values.
  • """ is for docstrings.
@kawa-kokosowa
kawa-kokosowa / loopback.sh
Created June 24, 2018 15:01
Allows you to output sound based on the line-in
#!/bin/sh
pactl load-module module-loopback latency_msec=1