Skip to content

Instantly share code, notes, and snippets.

View Matsukii's full-sized avatar

まてす Matsukii

View GitHub Profile
@Matsukii
Matsukii / NumChecks.js
Last active January 23, 2022 16:46
Number things OOP'ed
/**
* @description A class to check numbers
* LICENSE: MIT
new NumChecks(Number(prompt("give me a number"))).isEqual(Number(prompt("Now give me another number"))) ? alert("Equal") : alert("Not equal");
*/
class NumChecks{
operations = {
"+": (a, b) => a + b,
"-": (a, b) => a - b,
@Matsukii
Matsukii / conditionalLog.js
Created August 25, 2021 17:18
Check if debug is enabled then print the arguments , if you set the first parameter as log, error or warn, it use the console.<type>
/**
* @description Check if debug is enabled then print the arguments
* if you set the first parameter as log, error or warn, it use
* the console.<type>
*
* @param {...any} args things to print on console
*
* @example log("test: ", 1) // test: 1
* @example log("error", new Error("Error")) // error Error: Error...
* @example log("warn", "warning") // warn warning
@Matsukii
Matsukii / usb_hid_keys.h
Created March 20, 2021 20:54 — forked from MightyPork/usb_hid_keys.h
USB HID Keyboard scan codes
/**
* USB HID Keyboard scan codes as per USB spec 1.11
* plus some additional codes
*
* Created by MightyPork, 2016
* Public domain
*
* Adapted from:
* https://source.android.com/devices/input/keyboard-devices.html
*/
@Matsukii
Matsukii / key-codes.json
Created January 6, 2021 17:59 — forked from codingcarpenter/key-codes.js
JavaScript KeyCodes in a JSON file.
{
"0": 48,
"1": 49,
"2": 50,
"3": 51,
"4": 52,
"5": 53,
"6": 54,
"7": 55,
"8": 56,
@Matsukii
Matsukii / dateBuilder.js
Last active December 4, 2020 23:09
build a date from string with format; example: buildDate('%mo%/%d% %h%:%min%') -> 'Dec/4 20:00'
/**
* @description date builder, build a date string by passing the format
* @param {String} format date format to create
* @param {Number} timestamp date timestamp
* @see https://jsbench.me/j6kiav1wop other versions and benchmark
* @example buildDate('%mo%/%d% %h%:%min%') -> 'Dec/4 20:00'
*/
buildDate = (format = '*', timestamp = Date.now()) => {
if(!format || format == "*" || format == " "){
return new Date(timestamp);
@Matsukii
Matsukii / GI_chars.json
Last active November 4, 2020 22:08
Genshin Impact chars
[{"id":"le216","name":"Amber","stars":4,"element":"6","avatar":"","talent":"3","drop":{"monster":"1","talentBoss":"2"},"worldLoot":"10"},{"id":"bxsk9","name":"Barbara","stars":"4","element":"5","avatar":"","talent":"3","drop":{"monster":"4","talentBoss":"3"},"worldLoot":"7"},{"id":"td785f","name":"Beidou","stars":"4","element":"3","avatar":"","talent":"0","drop":{"monster":"6","talentBoss":"2"},"worldLoot":"6"},{"id":"yv2q3","name":"Bennet","stars":"4","element":"6","avatar":"","talent":5,"drop":{"monster":"6","talentBoss":"1"},"worldLoot":"14"},{"id":"14kp3j","name":"Chongyun","stars":"4","element":"1","avatar":"","talent":"1","drop":{"monster":"2","talentBoss":"2"},"worldLoot":2},{"id":"hpyuu","name":"Diluc","stars":"5","element":"6","avatar":"","talent":"4","drop":{"monster":"0","talentBoss":"1"},"worldLoot":"10"},{"id":"kca5y","name":"Diona","stars":"-1","element":"1","avatar":"","talent":"3","drop":{"monster":"1","talentBoss":"-1"},"worldLoot":"0"},{"id":"sftna","name":"Fischl","stars":"4","element":"3",
@Matsukii
Matsukii / hmsToSeconds.js
Last active January 23, 2022 16:45
Convertion from HH:MM:SS to seconds - inspired by this answer https://stackoverflow.com/a/9640417
/**
* @description convert hms string to seconds
* @see performance test with jsBench: https://jsbench.me/rckgfk8iv7
* @license MIT
*
* @param {String} str HH:MM:SS
* @example str = '01:00:10' return 3610
* @returns {Number} time as seconds
*/
const hmsToSeconds = (str) => {
@Matsukii
Matsukii / ArrayLastItem.min.js
Created September 12, 2020 20:48
A array prototype function to get/set the last item of an array (minified ver.)
/**
* @description get last item of an array or set the value of the last item
* @author Matsukii
* @license MIT
* @returns last item of an array
*/
Array.prototype.lastItem = function(set=undefined){let i=this.length-1;if(set){if(typeof set==="object"){this[i]={...this.lastItem(),...set}}else{this[i]=set}}return this[i]}
@Matsukii
Matsukii / regex-array-constructor.js
Created July 30, 2020 19:20
Construct an RegExp with items from prvided array, can be used to create an regex to test if have specific it. I used this some time ago and not remember if took some part from somewhere, so if i used something let me know
/**
* @description construct an RegExp with items from prvided array,
* can be used to create an regex to test if have specific item
*
* @param {Array<*>} items array of items to add as regex option
* @param {String} flags regex flags
* @returns {RegExp} RegExp
* @example construct(["foo", "bar"], "gi").test("foo") -> true
*/
function construct(items, flags = 'gi'){
@Matsukii
Matsukii / randomMessages.js
Last active December 11, 2019 19:50
a simple class to get random messages from array, used in http://presnt.in
/**
* @author Matsukii
* @Description get a random text pharse from array
*/
class loadingMessages {
msgs = [
'Loading',
'Opening inventory...',
'Looking for your history',
'Link start!',