Skip to content

Instantly share code, notes, and snippets.

View Nixinova's full-sized avatar

Nixinova

View GitHub Profile
@Nixinova
Nixinova / info.md
Last active February 6, 2022 02:07
Things you may need when developing a FabricMC mod

This is a list of things I had to figure out on my own in Fabric due to the lack of online documentation.

Removing items from a player's inventory.

Don't use player.inventory.remove!

//signature:
int net.minecraft.entity.player.PlayerInventory.remove(Predicate<ItemStack> shouldRemove, int maxCount, Inventory craftingInventory)

Note the craftingInventory parameter: I have no idea how to get the player's crafting inventory, and passing null makes the command throw.

@Nixinova
Nixinova / github-map-tokens.jsonc
Last active August 15, 2021 03:40
GitHub CSS theme classes mapped to tmLanguage token names
// source: https://github.com/aschoettler/misc-stuff/blob/349b824d321f15286f6af3478bc52a1eeaa10770/github-light.map.json
{
"comment": "pl-c",
"punctuation.definition.comment": "pl-c",
"string.comment": "pl-c",
"constant": "pl-c1",
"entity.name.constant": "pl-c1",
"markup.raw": "pl-c1",
"meta.diff.header": "pl-c1",
"meta.module-reference": "pl-c1",
@Nixinova
Nixinova / bookmarklet.js
Last active September 21, 2021 06:48
GitHub Lightshow syntax highlighting improver bookmarklet. Makes testing and previewing tmLanguage files much easier
javascript:(()=>{
/*
save this as a bookmark
run on https://github-lightshow.herokuapp.com
*/
document.head.innerHTML += `<style>
.code{background-color:#fff;color:#333;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:12px}
[class*="pl-"] {color: white !important;}
@Nixinova
Nixinova / encode.js
Created August 5, 2021 22:09
Convert string to ASCII
function encode(Type, str) {
const encodedString = str.split('').map(c => c.charCodeAt(0));
return Type.from(encodedString);
}
encode(Int8Array, 'abcdef');
@Nixinova
Nixinova / collatz.js
Last active August 3, 2021 04:39
Collatz conjecture iterator
function test(n) {
let list = [];
function iterate(n) {
list.push(n);
return n <= 1 ? 1 : iterate(n % 2 === 0 ? n / 2 : 3 * n + 1);
}
iterate(n);
return list;
}
@Nixinova
Nixinova / mojira-search.js
Last active July 10, 2021 22:53
Mojira search query dumper: fetch all comment data from a Mojira search
// run in console window on bugs.mojang.com/404
const SEARCH = 'https://bugs.mojang.com/rest/api/2/search?jql='
const encode = encodeURIComponent
let dumpedData = [];
const getData = () => console.log(JSON.stringify(dumpedData))
async function fetchComments({ query, max = 1000 }) {
let count = 0, batch = 1;
dumpedData.push({ _meta: { query, max } })
@Nixinova
Nixinova / regex-flatten.js
Last active July 10, 2021 07:51
Convert regex free-spacing mode (`(?x)`) to normal regex
function flatten(str) {
return str.replace(/\r?\n|^\s+|\s+#\s.+$/gm, '').replace('(?x)', '')
}
@Nixinova
Nixinova / less-jquery.js
Last active July 10, 2021 20:42
Less-jQuery: a jQuery drop-in replacement
window.jQuery = elem => new jQueryClass(elem);
window.$ = window.jQuery;
class jQueryClass {
constructor(selector) {
if (selector instanceof jQueryClass) return selector;
else if (selector instanceof Function) $(document).ready(selector);
else if (selector instanceof NodeList) this.elements = selector;
else if (selector instanceof HTMLElement) this.elements = [selector];
else if (Object.is(selector, document)) this.elements = [document];
@Nixinova
Nixinova / obfus.js
Last active May 10, 2022 09:50
JavaScript obfuscation
function encode(string) {
const isolate = v => `[${v}][+[]]`;
const ZERO = isolate(`+[]`);
const ONE = isolate(`+!![]`);
const count = n => ('+' + ONE).repeat(n);
const toString = str => isolate(`${str}+[]`);
const FALSE = toString(toString(`!!${ZERO}`));
const TRUE = toString(toString(`!${ZERO}`));
const NAN = toString(isolate(`+[![]]`));
const UNDEFINED = toString(isolate(``));
@Nixinova
Nixinova / refpass.js
Created June 18, 2021 22:30
JavaScript: pass-by-reference demonstration
let a = [1]
let b = a
b.push(2)
console.log(a) // [1,2]