Skip to content

Instantly share code, notes, and snippets.

View Nixinova's full-sized avatar

Nixinova

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / escape-regex.ts
Created September 9, 2021 04:41
Regex escape function
export default const escapeRegex = (str: string): string => str.replace(/[.*+?^/${}()|[\]\\]/g, '\\$&');
@Nixinova
Nixinova / wtf.js
Created September 20, 2021 00:09
The worst thing in JavaScript
var arr = []
if (arr == !arr) throw 'wtf'
@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 / graphing.r
Created October 1, 2021 21:17
Preferred prime minister polling, New Zealand
# In RStudio, Ctrl+A then Run
library(ggplot2)
library(dplyr)
library(svglite)
setwd("xxxxx") # replace with own working directory
# Read data
csvData <- read.csv("poll-data.csv")