Skip to content

Instantly share code, notes, and snippets.

View samiriff's full-sized avatar
🎯
Focusing

Samir Sheriff samiriff

🎯
Focusing
View GitHub Profile
---- Create Pods, Services and Config Maps
kubectl create -f https://gist.github.com/samiriff/6798254d00b7f42592edbb4311b717fb/raw/ea8a318972896074912457de6716d545d91e9a2b/pgdb-config-map.yml
kubectl create -f https://gist.github.com/samiriff/6798254d00b7f42592edbb4311b717fb/raw/ea8a318972896074912457de6716d545d91e9a2b/web-svc.yml
kubectl create -f https://gist.github.com/samiriff/6798254d00b7f42592edbb4311b717fb/raw/ea8a318972896074912457de6716d545d91e9a2b/pgdb-svc.yml
kubectl create -f https://gist.github.com/samiriff/6798254d00b7f42592edbb4311b717fb/raw/ea8a318972896074912457de6716d545d91e9a2b/web-pod.yml
kubectl create -f https://gist.github.com/samiriff/6798254d00b7f42592edbb4311b717fb/raw/ea8a318972896074912457de6716d545d91e9a2b/pgdb-pod.yml
---- Create default HTTP backend
kubectl create -f https://gist.github.com/samiriff/6798254d00b7f42592edbb4311b717fb/raw/76cb0baddd0fbbea0a82b8dad7bd5e848f0f85bc/default-http-backend
This file has been truncated, but you can view the full file.
{
"swagger": "2.0",
"schemes": [
"https",
"http"
],
"host": "ec2.amazonaws.com",
"basePath": "/",
"x-hasEquivalentPaths": true,
"info": {
def startsWithDate(s):
pattern = '^([0-2][0-9]|(3)[0-1])(\/)(((0)[0-9])|((1)[0-2]))(\/)(\d{2}|\d{4}), ([0-9][0-9]):([0-9][0-9]) -'
result = re.match(pattern, s)
if result:
return True
return False
def startsWithAuthor(s):
patterns = [
'([\w]+):', # First Name
'([\w]+[\s]+[\w]+):', # First Name + Last Name
'([\w]+[\s]+[\w]+[\s]+[\w]+):', # First Name + Middle Name + Last Name
'([+]\d{2} \d{5} \d{5}):', # Mobile Number (India)
'([+]\d{2} \d{3} \d{3} \d{4}):', # Mobile Number (US)
'([+]\d{2} \d{4} \d{7})' # Mobile Number (Europe)
]
pattern = '^' + '|'.join(patterns)
def getDataPoint(line):
# line = 18/06/17, 22:47 - Loki: Why do you have 2 numbers, Banner?
splitLine = line.split(' - ') # splitLine = ['18/06/17, 22:47', 'Loki: Why do you have 2 numbers, Banner?']
dateTime = splitLine[0] # dateTime = '18/06/17, 22:47'
date, time = dateTime.split(', ') # date = '18/06/17'; time = '22:47'
message = ' '.join(splitLine[1:]) # message = 'Loki: Why do you have 2 numbers, Banner?'
parsedData = [] # List to keep track of data so it can be used by a Pandas dataframe
conversationPath = './whatsappcollection/whatsapp_avengers.txt'
with open(conversationPath, encoding="utf-8") as fp:
fp.readline() # Skipping first line of the file (usually contains information about end-to-end encryption)
messageBuffer = [] # Buffer to capture intermediate output for multi-line messages
date, time, author = None, None, None # Intermediate variables to keep track of the current message being processed
while True:
line = fp.readline()
df = pd.DataFrame(parsedData, columns=['Date', 'Time', 'Author', 'Message'])
df.head()
df.describe()
author_value_counts = df['Author'].value_counts() # Number of messages per author
top_10_author_value_counts = author_value_counts.head(10) # Number of messages per author for the top 10 most active authors
top_10_author_value_counts.plot.barh() # Plot a bar chart using pandas built-in plotting apis
null_authors_df = df[df['Author'].isnull()]
null_authors_df.head()