This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |