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),
@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) {
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]));
};
})();
// ==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"]]],
#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 / discord-ur.ix
Last active October 1, 2023 21:34
Royal Game of Ur implemented for the Insitux Discord bot FaaS-ish apps
;https://insitux.repl.co/
;https://insitux.github.io/
;https://royalur.net/rules/
;https://royalur.net/dice/
(var cmds "1234567ABCDEFG")
(function roll
(times 4 #(rand-int)))
@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>,
// ==UserScript==
// @name YouTube budget
// @version 0.1.2
// @description Budgets YT time
// @author Patrick Bowen
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==