Skip to content

Instantly share code, notes, and snippets.

View aasmpro's full-sized avatar
NewLife

Ross Amiri aasmpro

NewLife
View GitHub Profile
@aasmpro
aasmpro / convert_to_int.py
Last active March 24, 2022 22:02
Python script to convert string to int without using built-in functions, and return the value with 3 fixed decimal places
import re
digits_dict = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
regex = "\s*(\+|\-)?\s*((\d)*(\.)?(\d)*)"
value = input()
result = re.search(regex, value)
sign = result.group(1) == '-' and -1 or 1
digits = result.group(2)
integer_value = 0
@aasmpro
aasmpro / todo.py
Created March 24, 2022 21:56
Simple todo app with saving data in json file
import json
import sys
class DataList:
notes = []
@staticmethod
def print(notes):
"""
@aasmpro
aasmpro / replacements.py
Created March 24, 2022 21:53
Script to add parranteses in certain positions in a line
text = input()
pairs_count = int(input())
pairs = []
for i in range(pairs_count):
pair = input().split()
pairs.append([int(i) for i in pair])
output = []
@aasmpro
aasmpro / abba.py
Created March 24, 2022 21:48
Simple abba pattern check
check = list(input())
words = input().split(" ")
passed = True
data = {}
for c, w in zip(check, words):
d = data.get(c, None)
if d and d != w:
passed = False
break
else:
@aasmpro
aasmpro / scrolling_text.py
Created March 24, 2022 21:46
Scrolling text, just like the ones you see in train stations :)
from time import sleep
def scrolling_text(text, screen_size, wait):
text = f"{' '*screen_size}{text}{' '*screen_size}"
while True:
for i in range(len(text) - screen_size):
print('\r', text[i:screen_size+i], end='', sep='', flush=True)
sleep(wait)
@aasmpro
aasmpro / numbeo.com.js
Last active March 24, 2022 21:42
A script to convert prices to another one on numbeo.com. simply just open the console, copy, paste and enter!
let currency_symbol = "IRT";
let currency_ratio = 30;
let convert = (value) => {return (parseFloat(value.replaceAll(',',''))*currency_ratio).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")};
let price_elements = document.getElementsByClassName("first_currency");
Array.prototype.map.call(price_elements, (item) => {item.innerHTML = `${convert(item.innerHTML.match(/[\d,]*[.]{0,1}[\d]+/g)[0])} ${currency_symbol}`;});
@aasmpro
aasmpro / spinner.py
Created March 24, 2022 20:51
Simple Spinner (loading animation)
from itertools import cycle
from time import sleep
def spin(data, duration=0.2, check=lambda: False):
for frame in cycle(data):
if not check():
print("\r", frame, sep="", end="", flush=True)
sleep(duration)
else:
@aasmpro
aasmpro / distance.py
Created March 24, 2022 20:50
Find distance between two geo locations
from math import sin, cos, sqrt, atan2, radians
R = 6371.0
lat1 = radians(37.876056)
lon1 = radians(-7.216644)
lat2 = radians(-41.745973)
lon2 = radians(-65.313432)
dlon = lon2 - lon1
@aasmpro
aasmpro / server.ts
Created March 24, 2022 20:48
Simple server with deno
import { listenAndServe } from "https://deno.land/std@0.60.0/http/server.ts";
class Server {
options: any = {port: 8000}
routes: any = {}
handle = (path: any, func: any) => {
this.routes[path] = func
}
@aasmpro
aasmpro / the_year_with_most_population.py
Last active March 24, 2022 22:03
Script to find the year with most population from two arrays of birth and death years
b = [1386, 1345, 1367]
d = [1398, 1390, 1387]
l = len(b)
result = 0
count = 0
for year in range(min(b), max(d) + 1):
_c = 0
for i in range(l):