Skip to content

Instantly share code, notes, and snippets.

Avatar
🎒
Studying

TheRolf TheRolfFR

🎒
Studying
View GitHub Profile
@TheRolfFR
TheRolfFR / TimeoutPromise.js
Last active Nov 25, 2021
Resolves promise after certain period of time in ms
View TimeoutPromise.js
/**
* 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 Oct 26, 2021
Minecraft version array sorter for js
View MinecraftVersionSorter.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 MinecraftSorter = (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 / NodeListRemove.js
Created Oct 3, 2021
Removes all elements from a NodeList. This NodeList is generally a document element query result.
View NodeListRemove.js
/**
* 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 / ElementRemove.js
Last active Oct 3, 2021
Simply remove the element
View ElementRemove.js
/**
* Simply remove the element
* @author TheRolf
*/
Element.prototype.remove = function() {
this.parentElement.removeChild(this)
}
@TheRolfFR
TheRolfFR / ElementAppendHTML.js
Last active Oct 3, 2021
Creates html from string and appends it to current element
View ElementAppendHTML.js
/**
* 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 / ByteStringer.java
Created Sep 20, 2021
Java bytes to string helper
View ByteStringer.java
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 / gist:93b2332da3312db1bdc6b843383f6120
Created Apr 20, 2020
📊 Weekly development breakdown
View gist:93b2332da3312db1bdc6b843383f6120
See more at [https://github.com/matchai/waka-box](https://github.com/matchai/waka-box)