Skip to content

Instantly share code, notes, and snippets.

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

Raivat Shah raivatshah

💻
Hacking...
View GitHub Profile
@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
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 / 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 / avenger questions.js
Last active November 14, 2018 09:39
Questions from Avenger Tiffany of CS1101S at NUS SoC
//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).