Skip to content

Instantly share code, notes, and snippets.

View Bibliofile's full-sized avatar

Bibliofile Bibliofile

View GitHub Profile
@Bibliofile
Bibliofile / post.js
Created December 8, 2019 22:26
Assorted servers 2019
// @ts-check
/**
* @typedef Server
* @property {string} name
* @property {string} link
* @property {string} owner
* @property {boolean?} expert
* @property {'Survival' | 'Custom'} type
* @property {'cloud' | 'mac'} host
@Bibliofile
Bibliofile / table_output.h
Created September 20, 2019 17:20
C++ header only library to output tabular data without output size calculations cluttering output code.
#ifndef TABLE_OUTPUT_H
#define TABLE_OUTPUT_H
#include <iostream>
#include <iomanip>
// Helper to output tabular data without repeating calculations everywhere.
template<unsigned TSize>
class TableOutput {
public:
@Bibliofile
Bibliofile / enet.d.ts
Created April 25, 2019 02:24
Enet TypeScript types
import { EventEmitter } from "events";
import { on } from "cluster";
export interface PlainAddress {
address: string | number
port: string | number
}
export class Address {
constructor(address: Address | PlainAddress)
@Bibliofile
Bibliofile / emojis.js
Created March 7, 2019 20:08
Emoji extension for BHMB
// Emoji list taken from emojis npm package
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@bhmb/bot')) :
typeof define === 'function' && define.amd ? define(['@bhmb/bot'], factory) :
(factory(global['@bhmb/bot']));
}(this, (function (bot) { 'use strict';
const MessageBot = bot.MessageBot
const emojis = {
@Bibliofile
Bibliofile / notes.md
Last active May 30, 2020 00:29
Getting a discourse user api key

This was quite painful, so I'm writing it down for next time.

  1. Create a private key.
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
  1. Get the public key
window['@bhmb/bot'].MessageBot.registerExtension('bibliofile/nav-names', (ex, world) => {
const create = (...cls) => {
const el = document.createElement('div')
el.classList.add(...cls)
return el
}
const bar = document.querySelector('.navbar.is-primary')
const menu = bar.appendChild(create('navbar-menu'))
const end = menu.appendChild(create('navbar-end'))
@Bibliofile
Bibliofile / split.lua
Created February 4, 2019 05:29
Split string
--[[
Splits a string `source` by `delim`. If `delim` is not specified, will split `source` by whitespace.
Pass a truthy value for `pattern` to allow patterns to be used when splitting the string.
Returns a table with all values.
]]--
function split(source, delim, pattern)
if not delim then delim, pattern = '%s+', true end
local result = {}
local search_start = 1
while true do
@Bibliofile
Bibliofile / scroll.js
Last active July 26, 2019 23:07
Always scroll down
window['@bhmb/bot'].MessageBot.registerExtension('bibliofile/scroll-down', ex => {
console.log('Will always scroll down')
const list = document.querySelector('#console .chat')
const observer = new MutationObserver(() => {
setTimeout(() => list.scrollTop = list.scrollHeight, 100)
})
observer.observe(list, { childList: true, subtree: true })
ex.remove = () => observer.disconnect()
# Paste this into https://omrelli.ug/nearley-playground/
main -> expression {% id %}
expression ->
mult_term {% id %}
| expression _ ("+"|"-") _ mult_term {% d => d[2][0] === '+' ? d[0] + d[4] : d[0] - d[4] %}
mult_term ->
exp_term {% id %}
@Bibliofile
Bibliofile / addon.js
Last active December 7, 2018 18:09
Dice!
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@bhmb/bot')) :
typeof define === 'function' && define.amd ? define(['@bhmb/bot'], factory) :
(factory(global['@bhmb/bot']));
}(this, (function(bot) {
'use strict';
const MessageBot = bot.MessageBot
function random(max) {
return Math.floor(Math.random() * max) + 1;