import tweepy
import requests
import pandas as pd
import json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- View: master_view | |
| -- DROP VIEW master_view; | |
| CREATE OR REPLACE VIEW master_view AS | |
| SELECT ga.trans_id, | |
| ga.source_medium, | |
| ga.campaign, | |
| od.country, | |
| od.first_mo_sales, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT p.customer_id, c.first_name, | |
| SUM(p.amount)::money, COUNT(*), | |
| SUM(p.amount)/COUNT(*) as AVG_RENTAL_VALUE | |
| FROM payment p LEFT JOIN customer c ON p.customer_id = c.customer_id | |
| WHERE p.customer_id > 300 AND c.first_name like '%b%' | |
| GROUP BY 1,2 | |
| HAVING COUNT(*) > 20 -- having is when you filter on aggregates, is a where clause for aggregates | |
| ORDER BY 4 DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- SELECT p.*, | |
| -- p.payment_date::date, | |
| -- extract(year from p.payment_date), | |
| -- extract(month from p.payment_date), | |
| -- extract(day from p.payment_date) | |
| -- | |
| -- FROM payment p | |
| -- | |
| -- WHERE extract(month from p.payment_date) IN (1,2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def draw_lines(img, lines, color=[255, 0, 0], thickness=5): | |
| """ | |
| NOTE: this is the function you might want to use as a starting point once you want to | |
| average/extrapolate the line segments you detect to map out the full | |
| extent of the lane (going from the result shown in raw-lines-example.mp4 | |
| to that shown in P1_example.mp4). | |
| Think about things like separating line segments by their | |
| slope ((y2-y1)/(x2-x1)) to decide which segments are part of the left | |
| line vs. the right line. Then, you can average the position of each of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def typed_property(name, expected_type): | |
| private_name = '_' + name | |
| @property | |
| def prop(self): | |
| return getattr(self, private_name) | |
| @prop.setter | |
| def prop(self, value): | |
| if not isinstance(value, expected_type): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple, defaultdict | |
| import random | |
| import itertools | |
| Letter = namedtuple('Letter', 'name amount value') | |
| scrabble_scores = [(1, "E A O I N R T L S U"), (2, "D G"), (3, "B C M P"), | |
| (4, "F H V W Y"), (5, "K"), (8, "J X"), (10, "Q Z")] | |
| LETTER_SCORES = {letter.lower(): score for score, letters in scrabble_scores |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import Counter, defaultdict | |
| from itertools import product | |
| from difflib import SequenceMatcher | |
| import requests | |
| from bs4 import BeautifulSoup | |
| from nltk.corpus import wordnet as wn | |
| page = requests.get("http://pybit.es/feeds/all.rss.xml") | |
| soup = BeautifulSoup(page.text, "lxml") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Multiple yield statements | |
| def gen_up_to(limit): | |
| n = 0 | |
| while n <= limit: | |
| if n % 2 <= 0: | |
| yield (n, "even") | |
| if n % 2 > 0: | |
| yield (n, "odd") | |
| n += 1 | |
| yield 'All Done' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
| <title>Draggable elements</title> | |
| </script> | |
| </head> | |