Skip to content

Instantly share code, notes, and snippets.

View raivatshah's full-sized avatar
💻
Hacking...

Raivat Shah raivatshah

💻
Hacking...
View GitHub Profile
assert(
speed >= 0,
"Speed should be non-negative!"
)
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
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
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
@raivatshah
raivatshah / OutlineBot.py
Created July 3, 2019 10:30
Simple Telegram Bot to automate the process of obtaining Outline.com links.
"""
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
@raivatshah
raivatshah / john.json
Last active June 1, 2019 03:10
A sample JSON file for storing a person's information
{
"first name":"John",
"last name":"Appleseed",
"age":30,
"house":{
"address":{
"house no":"D12",
"street":"College Ave East",
"city":"Singapore"
},
@raivatshah
raivatshah / sentiment_analyser.py
Created March 30, 2019 15:39
A python script to do sentiment analysis
"""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]
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()
@raivatshah
raivatshah / pa13.js
Last active November 15, 2018 03:58
PA2013 Answers
//2A
function is_odd(i) {
if (i % 2 === 0) {
return false;
} else {
return true;
}
}
//Test cases
@raivatshah
raivatshah / mceans.js
Last active November 14, 2018 08:15
MCE Ans
//Questions from Avenger Ken.
//5.1 Math Floor - modify / operator to round down the answer. parse_and_evaluate("5/2;"); returns 2 and not 2.5
//Simple: Modify Built in operator of MCE (lines 728 to 750)
const builtin_functions = list(
pair("pair", pair ),
pair("head", head ),
pair("tail", tail ),