Skip to content

Instantly share code, notes, and snippets.

View cderwin's full-sized avatar

Cameron Derwin cderwin

View GitHub Profile
def get_youtube_url(artist, song):
r = requests.get('https://www.youtube.com/results', params={'search_query': '{} {} official music video'.format(artist, song)})
soup = BeautifulSoup(r.text)
videos = soup.findAll('a', {'class': 'yt-uix-tile-link'})
while not videos[0]['href'].startswith('/'):
videos = videos[1:]
return 'https://www.youtube.com/' + videos[0]['href']
@cderwin
cderwin / test.cpp
Last active June 25, 2017 20:06
c++ references
#include <iostream>
int main() {
int a = 0;
int b = 7;
int& aRef = a;
int& bRef = b;
aRef = bRef;
std::cout << a << " " << b << std::endl;
@cderwin
cderwin / close_subscription.py
Created September 26, 2016 19:14
How to close a subscription and return it back to a pool with asyncio_redis
class MessageIterator:
'''
Async iterator for messages received.
Only necessary as a separate class since async generators won't be introduced until 3.6
'''
def __init__(self, redis_conn, channel_name):
self.redis_conn = redis_conn # redis_conn can also be a pool, they have the same api
self.channel_name = channel_name
self.subscriber = None
Aggregate (cost=40095.76..40095.77 rows=1 width=0)
-> Hash Join (cost=16470.62..40095.40 rows=145 width=0)
Hash Cond: ((c.tract_id)::text = (((g.state)::text || (g.county)::text) || (g.tract)::text))
-> Hash Join (cost=47.98..23660.40 rows=10 width=52)
Hash Cond: ((t.geoid)::text = (c.tract_id)::text)
-> Seq Scan on tract t (cost=0.00..23334.33 rows=74133 width=12)
-> Hash (cost=47.85..47.85 rows=10 width=40)
-> Seq Scan on tractcache c (cost=0.00..47.85 rows=10 width=40)
Filter: ((metro_id)::text = '348'::text)
-> Hash (cost=16386.46..16386.46 rows=2895 width=56)