Skip to content

Instantly share code, notes, and snippets.

View PandaWhoCodes's full-sized avatar

Thomas Ashish Cherian PandaWhoCodes

View GitHub Profile
@PandaWhoCodes
PandaWhoCodes / apiai.py
Created December 21, 2016 04:48
API.AI example explaination on bluescreen.club
!/usr/bin/env python
-*- coding: utf-8 -*-
import os.path
import sys
import json
try:
import apiai
except ImportError:
sys.path.append(
import json
import urllib.request
def respond(err, res=None):
return {
'statusCode': '400' if err else '200',
'body': err.message if err else json.dumps(res),
'headers': {
'Content-Type': 'application/json',
},
@PandaWhoCodes
PandaWhoCodes / lambdaTest.py
Last active June 23, 2017 22:28
lambda handler for get operation
def lambda_handler(event, context):
return respond(False,event)
'''
OUTPUT:
{"body-json": {}, "params": {"path": {}, "querystring": {"query": "testing"}, "header": {"Accept": "*/*", "Accept-Encoding": "gzip, deflate", "CloudFront-Forwarded-Proto": "https", "CloudFront-Is-Desktop-Viewer": "true", "CloudFront-Is-Mobile-Viewer": "false", "CloudFront-Is-SmartTV-Viewer": "false", "CloudFront-Is-Tablet-Viewer": "false", "CloudFront-Viewer-Country": "IN", "Host": "id5zrbbcg9.execute-api.us-east-1.amazonaws.com", "User-Agent": "python-requests/2.13.0", "Via": "1.1 16cfccb6d55cfe3498d5cf79893ff28d.cloudfront.net (CloudFront)", "X-Amz-Cf-Id": "U5lLN85-DYbsRICgsZjP-66xS-Lhlzoybl4iRimdOqz7zoEoCv2U8g==", "X-Amzn-Trace-Id": "Root=1-594d92aa-2fd6711137f905d51f526446", "X-Forwarded-For": "210.16.84.46, 54.239.160.65", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https"}}, "stage-variables": {}, "context": {"account-id": "", "api-id": "id5zrbbcg9", "api-key": "", "authorizer-principal-id": "", "caller": "", "cognito-a
def lambda_handler(event, context):
operation = event["context"]['http-method']
if operation == "GET":
searchString = event["params"]["querystring"]["query"]
searchText = searchString.replace(" ", "+")
#formatted the search string to make sure it works with the giphy API
@PandaWhoCodes
PandaWhoCodes / SimpleLaneDetect.py
Created August 8, 2017 11:22
Lane Detection using cv2
import cv2
import numpy as np
# capturing video through webcam
cap = cv2.VideoCapture(0)
while (1):
_, img = cap.read()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
or_lower = np.array([22, 60, 200], np.uint8)
@PandaWhoCodes
PandaWhoCodes / stackoverflowJobs.py
Created September 19, 2017 17:04
Parses the jobs feed in stackOverflow and prints them
import requests
import xml.etree.ElementTree
def getJobs(url):
r = requests.get(url)
e = xml.etree.ElementTree.fromstring(r.text)
return e
@PandaWhoCodes
PandaWhoCodes / ngrams.py
Created September 21, 2017 17:35 — forked from benhoyt/ngrams.py
Print most frequent N-grams in given file
"""Print most frequent N-grams in given file.
Usage: python ngrams.py filename
Problem description: Build a tool which receives a corpus of text,
analyses it and reports the top 10 most frequent bigrams, trigrams,
four-grams (i.e. most frequently occurring two, three and four word
consecutive combinations).
NOTES
Verifying that "reach2ashish.id" is my Blockstack ID. https://onename.com/reach2ashish
import re
from collections import Counter
# Peter Norvigs spell checker
def words(text): return re.findall(r'\w+', text.lower())
WORDS = Counter(words(open('big.txt').read()))
def P(word, N=sum(WORDS.values())):
"Probability of `word`."
return WORDS[word] / N
from slackclient import SlackClient
import time
BOT_NAME = 'Bot Name'
# slack API
slack_client = SlackClient('xoxb-251653110707-')
# Your bot ID
BOT_ID='BOT ID'
AT_BOT = "<@" + BOT_ID + ">:"
EXAMPLE_COMMAND=''
# stats={}