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 / MinecraftVersionSorter.js
Last active January 8, 2022 22:26
Minecraft version array sorter for js
// MinecraftVersionSorter.js 1.0 by TheRolf
// to use it, just just need to pass it as arg of the sort function for an array
// ["1.4.9","1.7","1.7.10","1.12.2","1.17.1","1.16.210","1.18"].sort(MinecraftSorter)
const MinecraftVersionSorter = (a, b) => {
const aSplit = a.split('.').map(s => parseInt(s))
const bSplit = b.split('.').map(s => parseInt(s))
if(aSplit.includes(NaN) || bSplit.includes(NaN)) {
return String(a).localeCompare(String(b)) // compare as strings
@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()
}