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
""" | |
Simple Telegram Bot to automate the process of obtaining Outline.com links. | |
Created by Raivat Shah in 2019. | |
""" | |
# Imports | |
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | |
import logging | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys |
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
assert( | |
speed >= 0, | |
"Speed should be non-negative!" | |
) |
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 get_speed(final, init, time_taken): | |
speed = (final - init) / time_taken # simple equation could return negative value if init > final. | |
assert speed >= 0, "Speed can't be negative" # will raise an AssertionError exception if speed is less than 0. | |
return speed |
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 get_speed(final, init, time_taken): | |
speed = (final - init) / time_taken # simple equation could return negative value if init > final. | |
if speed < 0: | |
#do something eg raise exception or warn user. | |
return speed | |
print(get_speed(5, 2, 1)) # will return 3 as expected | |
print(get_speed(2, 5, 1)) # will raise AssertionError exception |
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 get_speed(final, init, time_taken): | |
speed = (final - init) / time_taken # simple equation could return negative value if init > final. | |
assert speed >= 0 # will raise an AssertionError exception if speed is less than 0. | |
return speed | |
print(get_speed(5, 2, 1)) # will return 3 as expected | |
print(get_speed(2, 5, 1)) # will raise AssertionError exception |
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
{ | |
"first name":"John", | |
"last name":"Appleseed", | |
"age":30, | |
"house":{ | |
"address":{ | |
"house no":"D12", | |
"street":"College Ave East", | |
"city":"Singapore" | |
}, |
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
"""Sentiment analyser for Data Journalism Feedback""" | |
import csv | |
from textblob import TextBlob | |
data_source = 'sentence.csv' | |
with open(data_source, 'r') as csvfile: | |
rows = csv.reader(csvfile) | |
for row in rows: | |
sentence = row[0] |
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 signal | |
import sys | |
from google.cloud import language | |
from google.api_core.exceptions import InvalidArgument | |
# create a Google Cloud Natural Languague API Python client | |
client = language.LanguageServiceClient() | |
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
//2A | |
function is_odd(i) { | |
if (i % 2 === 0) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
//Test cases |
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
//Obtain sum of array using for-loops | |
/* Thought process: this is the same as our sum for lists but in an imperative style of programming. So the idea is the same as recursion | |
Array indexes start at 0 and end at n - 1, where n is the number of elements in the array. Therefore, we start at 0 and end at n-1, where we move 1 element each time | |
*/ | |
function sumArray(arr) { | |
let sum = 0; //initialize counter at 0 because we haven't added anything yet (we usually start counting with 0 in CS). | |
NewerOlder