Skip to content

Instantly share code, notes, and snippets.

View Nixinova's full-sized avatar

Nixinova

View GitHub Profile
@Nixinova
Nixinova / formatter.js
Last active June 3, 2023 23:13
VSCode Formatter Extension Example
var vscode = require("vscode")
function activate(context) {
console.log('Formatter activated') // formatting only works once activated
const formatter = vscode.languages.registerDocumentFormattingEditProvider(
'language-id', // set this to the language ID of the language to format (the bit in brackets in the vscode language menu)
{
provideDocumentFormattingEdits: function (document) {
const output = document.getText()
@Nixinova
Nixinova / Main.java
Last active January 28, 2021 22:08
An example of the bare essentials for creating a Minecraft mod, adding a block and an item.
package $PACKAGE;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.block.material.Material;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Nixinova
Nixinova / inventoryTab.txt
Last active February 7, 2021 03:28
Valid Modcrafter parameter values
# Default values for parameter 'inventoryTab'
# If the argument does not match one of the values below a custom inventory tab will be created
BREWING
BUILDING_BLOCKS
COMBAT
DECORATIONS
FOOD
HOTBAR
INVENTORY
@Nixinova
Nixinova / language_id.rb
Last active July 13, 2021 08:20
Linguist language ID generator
#!/usr/bin/env ruby
require 'digest'
language = 'InsertLangHere' # replace with full lang name
id = Digest::SHA256.hexdigest(language).to_i(16) % (2**30 - 1)
puts id
@Nixinova
Nixinova / center.css
Last active February 25, 2021 06:49
Centering in CSS
.grid {
display: grid;
place-items: center;
}
/* or */
.flex {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
@Nixinova
Nixinova / nested-css-token-flattener.ts
Last active May 27, 2021 06:23
Nested CSS Tokenizer example
let cssOutput = `
outer1 {
prop1: true;
inner {prop2: true;}
}
outer2 {
prop3: false;
}
`
@Nixinova
Nixinova / normal-date.js
Last active May 4, 2021 07:39
Date normaliser: convert a prose date to ISO
function normalise(str, outSep = ',') {
const R = String.raw
const re = str => RegExp(
str.replace(/ /g, R`\s*`).replace(/-/g, r.sep).replace(/[DMY]/g, c => r[c.toLowerCase()]),
'g'
)
const monthsL = 'January February March April May June July August September October November December'.toLowerCase().split(' ')
const monthsS = monthsL.map(month => month.substr(0, 3))
@Nixinova
Nixinova / decss.js
Last active May 11, 2021 08:10
Strip all CSS from HTML source
// Place in devtools
function decss(html) {
return html
.replace(/<link\s+rel=('|"|\s*)stylesheet.*?>/g, '')
.replace(/style=".+?"/g, '')
}
basehtml = document.getElementsByTagName('html')[0]
basehtml.innerHTML = decss(basehtml.innerHTML)
@Nixinova
Nixinova / neural-add.js
Created May 20, 2021 01:07
Neural network attempts addition
const Synaptic = require('synaptic');
const NUM_INPUTS = 2;
const HIDDEN = 1;
const NUM_OUTPUTS = 1;
const network = new Synaptic.Architect.Perceptron(
NUM_INPUTS,
HIDDEN,
NUM_OUTPUTS
);
@Nixinova
Nixinova / typed.js
Last active June 3, 2021 04:44
Simple JavaScript type checking
function _(type, val) {
if (!(val instanceof type) && (type(val) !== val))
throw new TypeError(`${JSON.stringify(val)} is not assignable to type "${type.name}"`);
return val;
}