Skip to content

Instantly share code, notes, and snippets.

Array.prototype.sortBy = (function() {
const sorters = {
string: (a, b) => a < b ? -1 : (a > b ? 1 : 0),
number: (a, b) => a - b,
};
return function(prop) {
const type = typeof this[0][prop] || 'string';
return this.sort((a, b) => sorters[type](a[prop], b[prop]));
};
})();
@phunanon
phunanon / disboard-dashboard-bump-reminder.js
Last active April 8, 2021 13:17
Beeps for every minute you haven't bumped a Disboard server
// ==UserScript==
// @name Bump reminder
// @version 0.3
// @match https://disboard.org/dashboard/servers
// ==/UserScript==
(function() {
setTimeout(() => {
const buttons = [...document.querySelectorAll("[data-origin-text='Bump']")];
if (buttons.filter(b => b.innerText.toLowerCase() == "bump").length) {
@phunanon
phunanon / calc.py
Last active April 22, 2019 20:19
Simple GTK+ Python calculator, traditional one-num-carry, extensible operators
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Calculator:
def __init__ (self):
self.carry = 0
self.ops = {
'=': (lambda x, y: self.carry),