Skip to content

Instantly share code, notes, and snippets.

@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),
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) {
// ==UserScript==
// @name Telegram Dark mode
// @version 0.2
// @match https://web.telegram.org/*
// ==/UserScript==
setTimeout(() => {
var styles = [
["body, .tg_head_split, .im_page_wrap, .im_dialogs_search_field, .im_record_bg",
[["backgroundColor", "#000"], ["color", "#fff"]]],
@phunanon
phunanon / ttt.ix
Last active April 26, 2022 09:59
Insitux tic-tac-toe
(function check
(let [[a _ x] [_ b] [z _ c]] board)
;Check diagonals
(when (or (= a b c) (= x b z)) (return b))
;Check horizontals and verticals
(let board+T (into board (.. map vec board)))
(when (let [w] (find (.. =) board+T)) w))
(function place n xo
(var! board (set-at [(// n 3) (rem n 3)] xo)))
(var W 80 H 25
chars ".,-~:;=!*#$@"
PI2 (* 2 PI)
speed-A .05 speed-B .05 speed-I .05 speed-J .05
a 0 b 0)
(var last-ms (time))
(function calculate-screen screen
(let prev-ms last-ms)
@phunanon
phunanon / TypedPipe.ts
Created August 9, 2022 15:01
Strongly types a pipeline of functions.
const pipe =
<Ctx, Ingress, A, B, C, Egress>(
...args:
| [(x: Ingress, ctx: Ctx) => Promise<Egress>]
| [
(x: Ingress, ctx: Ctx) => Promise<A>,
(x: A, ctx: Ctx) => Promise<Egress>
]
| [
(x: Ingress, ctx: Ctx) => Promise<A>,
@phunanon
phunanon / Insitux in Deadline.md
Last active July 6, 2023 05:24
Community-led documentation for using Insitux in the Roblox game Deadline
#Longest file name
find . -name '*.cs' | awk 'function base(f){sub(".*/", "", f); return f;} \
{print length(base($0)), $0}'| sort -nr | head -2
#Longest line
find . -name '*.cs' -print | xargs awk '{print length, $0}' | sort -nr | head -1
#Longest namespace
find . -name '*.cs' -print | xargs awk '{print length, $0}' |sort -nr | grep namespace | head -1
@phunanon
phunanon / hello.bf
Created September 7, 2023 18:35
"Hello, world!" in Brainfuck
+++++++[>++++++++++<-]>++.
<++++[>+++++++<-]>+.
+++++++..
+++.
>++++[>+++++++++++<-]>.
------------.
[-]
<<[>+>+<<-]>++++++++.>.
+++.
------.