Skip to content

Instantly share code, notes, and snippets.

View jrjames83's full-sized avatar

Jeff James jrjames83

View GitHub Profile
@jrjames83
jrjames83 / master_view.sql
Created August 12, 2016 18:22
the initial join of the db orders and ga orders
-- 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,
@jrjames83
jrjames83 / video2.sql
Created November 25, 2016 19:09
Dvd Rental Tutorial 2 PG
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
@jrjames83
jrjames83 / dates.sql
Created November 25, 2016 21:20
DVD Rental - Dates
-- 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)
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
@jrjames83
jrjames83 / python_type_checker.py
Last active December 28, 2016 03:41
Example of a function + lambda to enforce type checking on attr init and settr operations
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):
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
@jrjames83
jrjames83 / pybites3.py
Last active January 23, 2017 16:14
frequencies and text similarity use stdlib SequenceMatcher
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")
# 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'
@jrjames83
jrjames83 / nat_lang_twtr.md
Created February 27, 2017 00:06
Python Twitter / Tweepy, Plus Sklearn Count Vectorizer Detailed Walk Through and TextBlob Sentiment Analysis
import tweepy
import requests
import pandas as pd
import json
@jrjames83
jrjames83 / time_between_mousemoves.html
Created February 28, 2017 04:37
getting time between mouse movements with javascript
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Draggable elements</title>
</script>
</head>