Skip to content

Instantly share code, notes, and snippets.

View graingerkid's full-sized avatar

graingerkid graingerkid

View GitHub Profile
@graingerkid
graingerkid / Google_cache_date_extractor.py
Last active August 29, 2015 14:19
Google Cache Date Regex
import re
data = source_code_of_cached_page
google_cache_data = re.findall(r"""[A-Z][a-z]{2}\s[0-9]+,\s[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A-Z]{3}""", data) or re.findall(r"""[0-9]+\s[A-Z][a-z]{2},\s[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A-Z]{3}""", data)
@graingerkid
graingerkid / url_splitter.py
Last active August 29, 2015 14:20
Simple helper function bringing together two different libraries for extracting a URLs components. In-putted URLs are somewhat validated, this is simply against a users adding example.com instead of http://example.com, the former will result in both parsers being incorrect. The results are then simply returned into a named tuple for easy extract…
# -*- coding: utf-8 -*-
# pip install tldextract
import tldextract
# standard lib
from urlparse import urlparse
from collections import namedtuple
@graingerkid
graingerkid / working_with_csv.py
Created May 5, 2015 16:04
Basic example of working with a CSV file.
# -*- coding: utf-8 -*-
'''
Basic example of working with a CSV file.
'''
import csv
import collections
lis = []
with open("file.csv") as f:
@graingerkid
graingerkid / to_unicode.py
Created May 5, 2015 20:44
Function to always return unicode
# -*- coding: utf-8 -*-
def to_unicode(unicode_or_str):
'''Function to always return unicode
'''
if isinstance(unicode_or_str, str):
value = unicode_or_str.decode('utf-8')
else:
value = unicode_or_str
return value
@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
@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 / 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 / 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.

>>> 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 / 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)