This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/usr/bin/env python | |
-*- coding: utf-8 -*- | |
import os.path | |
import sys | |
import json | |
try: | |
import apiai | |
except ImportError: | |
sys.path.append( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import xml.etree.ElementTree | |
def getJobs(url): | |
r = requests.get(url) | |
e = xml.etree.ElementTree.fromstring(r.text) | |
return e | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verifying that "reach2ashish.id" is my Blockstack ID. https://onename.com/reach2ashish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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={} |