Skip to content

Instantly share code, notes, and snippets.

View obswork's full-sized avatar
🤙

Obssa Bizuwork obswork

🤙
View GitHub Profile
@obswork
obswork / unicode_csv.py
Created December 8, 2017 18:35 — forked from hvtuananh/unicode_csv.py
Python Unicode CSV Reader/Writer (fix writerow problem in Python docs)
#http://docs.python.org/2.7/library/csv.html
import csv, codecs, cStringIO
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
<p>“I am an optimist who worries a lot,” Madeleine Albright said Monday night when asked about the future of democracy. It’s a quotable phrase, but the former secretary of state is serious—both about her belief in the power of democracy and the fact that today, there’s substantial reason to worry about it.</p>
<p>In a wide-ranging conversation with <em>The Atlantic</em>’s editor-in-chief Jeffrey Goldberg in Washington, Albright spoke about the 20th-century history of fascism that she details in her new book, <em>Fascism: A Warning. </em>Albright, whose family was driven out of Czechoslovakia twice (once during World War II, and again by the Communist regime in 1948), discovered late in life that 26 members of her family were murdered in the Holocaust. This personal history, as well as Albright’s long career as a diplomat and politician, have helped inform her understanding of fascism—both what it is and what it’s not.</p>
<p>Albright, who served as secretary of state in the Clinton administration from 1997
@obswork
obswork / gist:2cb8e4c5b790c28abeedb40c45218aca
Created December 31, 2018 17:40
extract your "Top 100 Songs 2018" (spotify)
"""Prerequisites:
(1) You'll first need to open up the developer console in e.g. Chrome (cmd-shift-c)
(2) Locate the div element with id "main" (should be relatively easy to find as it's the main enclosing div in the body)
(3) Copy all the inner html of that div (easy way- right-click and select "Edit as HTML", then copy normally)
(4) Save that to a file somewhere (e.g. /tmp/tracklist.html)
(5) Open up a python shell (preferably iPython!) and execute the following
"""
import lxml.html
@obswork
obswork / gist:9ae85785098d60edf4be6ac308d172d0
Created December 31, 2018 18:10
extract songs from a spotify playlist
"""Steps:
(1) You'll first need to open up the developer console in e.g. Chrome (cmd-shift-c)
(2) Locate the div element with id "main" (should be relatively easy to find as it's the main enclosing div in the body)
(3) Copy all the inner html of that div (easy way- right-click and select "Edit as HTML", then copy normally)
(4) Save that to a file somewhere (e.g. /tmp/tracklist.html)
(5) Open up a python shell (preferably iPython!) and paste the function below into it
(6) Call the function passing in the path to the file from step 4
(7) profit
"""
@obswork
obswork / gist:211a826a80991781abbd22fcc4ffc516
Created March 2, 2019 15:49
search&replace double-quoted http(s) url with single-quoted url (elisp regexp)
s/\"\(http[s]*:\/\/.+?\)\"/\'\1\'/g
Hi mom
..and other people