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 / segments_gist.py
Last active April 29, 2019 20:41
This python code gets all of the segments of an iterable (excluding dicts) that are a specific length. For example, if you called the function with the value [1, 2, 3, 4, 5] for the list and 3 for the length, the function would return [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
def segments(list, length):
"""
Gets every possible segment of a specific length from a list
[1, 2, 3, 4]
length = 2
->
[[1, 2], [2, 3], [3, 4]]
"""
all_segments = []
@BenMaydan
BenMaydan / mspaint.py
Created May 12, 2019 20:40
This is a microsoft paint clone. Enjoy!
import tkinter as tk
import tkinter.ttk as ttk
#from tkinter import LEFT, RIGHT, UP, BOTTOM
from tkinter import *
from tkinter.colorchooser import *
import tkinter.messagebox
from tkinter.filedialog import *
import pickle
public static void print (String to_print) {
System.out.println(to_print);
}
private static void input (String to_print) {
Scanner scanner = new Scanner (System.in);
System.out.print(to_print);
String name = scanner.next(); // Get what the user types.
}
@BenMaydan
BenMaydan / Event Queue
Created May 25, 2019 18:52
Handles events given to the event queue in a linear sequential pattern
import threading
import multiprocessing
import itertools
import datetime
import time
import sys
import os
import copy
@BenMaydan
BenMaydan / Calculator
Last active June 2, 2019 05:54
Basic text calculator for now. Hopefully will become a GUI in the future and support more advanced mathematical operations
#FUTURE IMPORTS GO HERE
#
#
def remove_char(expression, character):
"""
Returns a new string with all of a specific character removed
@BenMaydan
BenMaydan / Number indexing
Last active June 4, 2019 19:03
Index a number. Unfortunately, not a method. This function returns a new indexed number
def nindex(number, idx, idx2=None):
if idx2 == None:
idx2 = idx + 1
return int(str(number)[idx:idx2])
@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
@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 / 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 / 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):