Skip to content

Instantly share code, notes, and snippets.

View TheRolfFR's full-sized avatar
💼
Working

TheRolf TheRolfFR

💼
Working
View GitHub Profile
@TheRolfFR
TheRolfFR / gist:93b2332da3312db1bdc6b843383f6120
Created April 20, 2020 11:10
📊 Weekly development breakdown
See more at [https://github.com/matchai/waka-box](https://github.com/matchai/waka-box)
@TheRolfFR
TheRolfFR / ByteStringer.java
Created September 20, 2021 15:36
Java bytes to string helper
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class ByteStringer {
private static final String[] BYTES_UNITS = new String[] {"B", "KB", "MB", "GB", "TB"};
public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
@TheRolfFR
TheRolfFR / ElementRemove.js
Last active October 3, 2021 11:42
Simply remove the element
/**
* Simply remove the element
* @author TheRolf
*/
Element.prototype.remove = function() {
this.parentElement.removeChild(this)
}
@TheRolfFR
TheRolfFR / NodeListRemove.js
Created October 3, 2021 11:42
Removes all elements from a NodeList. This NodeList is generally a document element query result.
/**
* Removes all elements from a NodeList.
* This NodeList is generally a document element query result.
* @author TheRolf
*/
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i])
}
@TheRolfFR
TheRolfFR / TimeoutPromise.js
Last active November 25, 2021 16:21
Resolves promise after certain period of time in ms
/**
* Resolves promise after certain period of time in ms
* @author TheRolf
* @param {Number} timeout delay in ms
*/
const TimeoutPromise = function(timeout) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, timeout);
@TheRolfFR
TheRolfFR / ElementAppendHTML.js
Last active January 26, 2022 10:28
Creates html from string and appends it to current element
/**
* Creates html from string and appends it to current element
* @author TheRolf
* @param {String} str html string to append
*/
Element.prototype.appendHTML = function(str) {
var div = document.createElement('div')
div.innerHTML = str
while (div.children.length > 0) {
@TheRolfFR
TheRolfFR / number_to_roman_numeral.py
Created February 14, 2022 17:01
Number to roman numeral converter
romlist = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
numlist = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
number = int(input("Enter integer > 0: "))
rn = []
numlist_index = 0
# a number should
while number > 0:
@TheRolfFR
TheRolfFR / wordle.py
Created February 17, 2022 21:44
Mini offline wordle with Python and rich library
import random
from rich.console import Console
from rich.panel import Panel
console = Console()
pathway = "wordlepy.txt"
def unused(letter):
return "[white on #2c3032]" + letter + "[/]"
@TheRolfFR
TheRolfFR / string_extensions.js
Created September 19, 2022 08:03
JS String extension with codes and chars
/**
* Gives char codes of the string
* @author TheRolf
*/
String.prototype.codes = function() {
return this.split('').map(c => {
let code = c.charCodeAt(0);
return code;
}).flat()
}
@TheRolfFR
TheRolfFR / xml_ie_format.js
Created September 22, 2022 15:23
XML ie format
let value;
let spaces;
spaces = 0;
console.log(value.split('\n').filter(f => f.trim().length !== 0).map(cur => {
if(cur.startsWith('-')) spaces ++;
else if(cur.startsWith('</')) spaces --;
else if(cur.startsWith('<')) spaces++;
let sp = '';