Skip to content

Instantly share code, notes, and snippets.

View Pzdrs's full-sized avatar

Petr Boháč Pzdrs

  • Technical University of Liberec
  • Czech Republic
  • X @pycrs_
View GitHub Profile
@Pzdrs
Pzdrs / scrape_ono.py
Created August 14, 2024 15:49
Gas prices scraper for ONO gas stations
import requests
import re
import json
content = requests.get('http://m.tank-ono.cz/en/index.php?page=cenik').content.decode('UTF-8') \
.replace('\r', '').replace('\n', '') \
.strip()
result = re.findall(
r'<div class=\"divrow2\"><div class=\"divpr\w{2}\">([A-Z\d+ ]*)</div><div class=\"divprice\">\s*(\d*)\s*<sup>\s*(\d*)\s*</sup>\s*</div><div class=\"divpriceeu\">\s*\d*\s*<sup>\s*\d*\s*</sup></div></div>',
content
@Pzdrs
Pzdrs / os_cislo_decoder.py
Created April 29, 2022 18:29
Decode osobni cisla from finek email s vysledkama z testu
import requests as requests
headers = {
"Accept": "application/json",
"Authorization": 'Basic <base64 encoded "username:password">'
}
with open("data.txt", mode='r') as data:
lines = data.readlines()
with open("translated_data.txt", mode='a', encoding='utf-8-sig') as translation:
@Pzdrs
Pzdrs / antibiotics_scheduler.java
Created March 22, 2022 20:22
antibiotics scheduler
/**
* @param args [0] - Total amount of pills - i.e. 21
* [1] - Hourly period - i.e. 8
* [2] - First dose (military standard) - i.e. 1430 => 14:30, ...
* [3] (optional) - Offset - you don't have time to wait to fit in to your schedule from the beginning,
* each dose will be delayed by this number (in minutes) - i.e. 15
*/
public static void main(String[] args) {
int firstDose = Integer.parseInt(args[2]);
int period = Integer.parseInt(args[1]);
@Pzdrs
Pzdrs / promptNumericInt.java
Created February 24, 2022 19:47
Prompt the user for and integer - validation included
/**
* Prompt the user for and integer
*
* @param message Prompt message
* @param range The range the integer is suppose to be in
* @return Validated integer
*/
public static int promptNumericInt(String message, Map.Entry<Integer, Integer> range) {
boolean error = true;
int value = 0;
@Pzdrs
Pzdrs / tryCatch.java
Created February 24, 2022 19:41
Functional approach to try catch wrapped in a do-while loop to assure an eventual execution of the supplied Runnable
/**
* Functional approach to try catch wrapped in a do-while loop to assure an eventual execution of the supplied Runnable
* @param runnable Try code
* @param onException Catch code
*/
public static void tryCatch(Runnable runnable, Runnable onException) {
boolean done = false;
do {
try {
runnable.run();
@Pzdrs
Pzdrs / readLineUntilEmpty.java
Created February 24, 2022 19:39
Prompt the user for a string until empty line is passed in
/**
* Prompt the user for a string until empty line is passed in
*
* @param consumer A consumer interface with a piece of code that is suppose to be ran on each iteration
*/
public static void readLineUntilEmpty(Consumer<String> consumer) {
String line;
do {
System.out.print("Enter a string: ");
line = Main.scanner.nextLine();
@Pzdrs
Pzdrs / bill_breaker.java
Created October 16, 2021 13:22
Bill breaker
public static Map<Integer, Integer> solve(int startingValue, int[] denominals) {
Map<Integer, Integer> map = new LinkedHashMap<>();
int remaining = startingValue;
for (int currentDenominal : denominals) {
if (currentDenominal > remaining) continue;
map.put(currentDenominal, remaining / currentDenominal);
remaining %= currentDenominal;
if (remaining == 0) break;
}
return map;