Skip to content

Instantly share code, notes, and snippets.

View graingerkid's full-sized avatar

graingerkid graingerkid

View GitHub Profile
@graingerkid
graingerkid / max_impressions_of_all_time.py
Created February 8, 2019 14:24
SLQ statement to select only the max values for the given date range - basically which landing pages have had their best ever month *this* month. Change MAX() to MIN() to get the biggest losers.
SELECT
t.landing_page, t.all_impressions
FROM
landing_pages_client_v3 AS t
JOIN
(
SELECT
landing_page,
MAX(all_impressions) AS max_all_impressions
FROM landing_pages_client_v3
@graingerkid
graingerkid / max_impressions_of_all_time.py
Created February 8, 2019 14:24
SLQ statement to select only the max values for the given date range - basically which landing pages have had their best ever month *this* month.
SELECT
t.landing_page, t.all_impressions
FROM
landing_pages_client_v3 AS t
JOIN
(
SELECT
landing_page,
MAX(all_impressions) AS max_all_impressions
FROM landing_pages_client_v3
@graingerkid
graingerkid / max_impressions_of_all_time.py
Created February 8, 2019 14:24
SLQ statement to select only the max values for the given date range - basically which landing pages have had their best ever month *this* month.
SELECT
t.landing_page, t.all_impressions
FROM
landing_pages_client_v3 AS t
JOIN
(
SELECT
landing_page,
MAX(all_impressions) AS max_all_impressions
FROM landing_pages_client_v3
@graingerkid
graingerkid / example.py
Created April 26, 2017 06:56 — forked from wolever/example.py
A persistent Queue implementation in Python which focuses on durability over throughput
from pqueue import PersistentQueue
q1 = PersistentQueue("/tmp/queue_storage_dir")
q1.put("1")
q1.put("2")
q1.put("3")
q1.close()
q2 = PersistentQueue("/tmp/queue_storage_dir")
while not q2.empty():
@graingerkid
graingerkid / example.py
Created March 30, 2017 13:13
filter tweets which contain words
from twython import Twython # pip install twython
import time # standard lib
''' Go to https://apps.twitter.com/ to register your app to get your api keys '''
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
>>> import requests
>>> import time
>>> import webbrowser
>>> while True:
... r=requests.get('https://www.example.co.uk/')
... if r.status_code == 200:
... webbrowser.open('https://www.example.co.uk/')
... else:
... pass
... time.sleep(10)
@graingerkid
graingerkid / git-feature-workflow.md
Created June 24, 2016 21:01 — forked from blackfalcon/git-feature-workflow.md
Git basics - a general workflow

There are many Git workflows out there, I heavily suggest also reading the atlassian.com [Git Workflow][article] article as there is more detail then presented here.

The two prevailing workflows are [Gitflow][gitflow] and [feature branches][feature]. IMHO, being more of a subscriber to continuous integration, I feel that the feature branch workflow is better suited.

When using Bash in the command line, it leaves a bit to be desired when it comes to awareness of state. I would suggest following these instructions on [setting up GIT Bash autocompletion][git-auto].

Basic branching

When working with a centralized workflow the concepts are simple, master represented the official history and is always deployable. With each now scope of work, aka feature, the developer is to create a new branch. For clarity, make sure to use descriptive names like transaction-fail-message or github-oauth for your branches.

@graingerkid
graingerkid / log_file_parser.py
Last active August 29, 2015 14:23
Parses a server log file
def read_log(log):
'''
Returns generator from log files - typically gb of data.
This allows a better performance due to memory issues of
returning the entire file.
'''
with open(log) as f:
# opens log file
for i in f:
yield i
@graingerkid
graingerkid / generator_split.py
Created June 18, 2015 10:55
Helper function to split a generator into a specified size.
def last_50(generator, n):
'''
Takes a generator object and returns
a specified number (n) into a list.
'''
counter = 0
results = []
for i in generator:
if counter == n:
break
@graingerkid
graingerkid / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console