Skip to content

Instantly share code, notes, and snippets.

View BenMaydan's full-sized avatar
🏫
College Student

BenMaydan

🏫
College Student
View GitHub Profile
@BenMaydan
BenMaydan / search.py
Last active August 4, 2019 06:44
A web browser you can use with your voice. AKA search with your voice
# A digital assistant for browsing the web
# Made by Ben Maydan
# Imports go here
import speech_recognition as sr
import webbrowser
def search_for(term, transcription):
"""
@BenMaydan
BenMaydan / validation.py
Created August 2, 2019 22:43
Validates a piece of text against some booleans
class Validator:
"""
A class for validating input
"""
def __init__(self, text, booleans):
self.text = text
self.booleans = booleans
@staticmethod
def nothing(self):
@BenMaydan
BenMaydan / maximum.py
Last active July 21, 2019 17:06
A new max function for python that works on tuples
def maximum(*lists):
mapping = {sum(l):l for l in lists}
return mapping[max(mapping.keys())]
@BenMaydan
BenMaydan / instances.py
Last active July 20, 2019 02:15
isinstance but to check multiple objects
def instances(objects, objectType):
if type(objects) not in [list, set, tuple]:
frmt = (str(objects)[0:int(len(objects) / 3)]) + "..."
raise TypeError("Object {} is not a collection of elements".format(frmt))
for obj in objects:
if not isinstance(obj, objectType):
raise TypeError("Object '{}' is not of type {}".format(str(obj), objectType))
@BenMaydan
BenMaydan / URL_SHORTENER_main.py
Created July 4, 2019 23:06
URL Shortener. Same as bit.ly (I just wanted to replicate)
# URL SHORTENER
# MADE BY Ben Maydan
# REQUEST PERMISSION BEFORE USING
# Imports
import operations
class Shortener:
FILE_NAME = "URLS.pickle"
@BenMaydan
BenMaydan / string_format.py
Created June 22, 2019 16:19
String formatting. This is a copy of string.format(variable, variable1)
class String:
"""
Composite of str class made to experiment with string formatting
"""
def __init__(self, string):
self.string = string
self.new_string = string
def _hr(self, addon):
@BenMaydan
BenMaydan / string_container.py
Last active June 22, 2019 16:35
String container checking. Example of use: for a string 'Hello {Nothing Happened Here}', when the string container method is called, string.container('{', '}') the method will return 'Nothing Happened Here'
class String:
"""
Composite of str class made to experiment with string formatting
"""
def __init__(self, string):
self.string = string
self.new_string = string
def __iter__(cls):
@BenMaydan
BenMaydan / Bitcoin
Created June 13, 2019 04:51
Python program that prints current bitcoin prices.
import requests
import time
import sys
#STATIC VARIABLES
BITCOIN_URL = 'https://api.coinmarketcap.com/v1/ticker/bitcoin/'
REFRESH_SPEED = 3
ROUND = 2
@BenMaydan
BenMaydan / Polynomials
Created June 8, 2019 00:58
Currently supports adding and subtracting polynomials
import itertools
import math
class Polynomial:
"""
Polynomial class
Magic Methods:
__str__
@BenMaydan
BenMaydan / New max
Last active June 4, 2019 19:01
Get the biggest number from a list of numbers if you are only counting the first 'index'. For example, the max number of the list [50, 2, 1, 9] would return 9 and the index of 9 in the list given, but it would not return 50. Feel free to experiment with this function to fully understand it if there is any confusion.
def nmax(lst):
maxed = (int(str(lst[0])[0]), lst.index(lst[0]))
for number in lst[1:]:
if int(str(number)[0]) > maxed[0]:
maxed = (number, lst.index(number))
return maxed