Skip to content

Instantly share code, notes, and snippets.

View darighost's full-sized avatar
🦊
sh.open(you.laptop, "cool network!);

darigo darighost

🦊
sh.open(you.laptop, "cool network!);
View GitHub Profile
@darighost
darighost / qsort.hoon
Last active November 14, 2023 04:57
Quicksort in Hoon!
|= l=(list @ud)
^- (list @ud)
?: =(0 (lent l))
~
=/ pivot (snag 0 l)
=/ rest (slag 1 l)
=/ less (skim rest |=(a=@ (lte a pivot)))
=/ more (skim rest |=(a=@ (gth a pivot)))
:(weld $(l less) ~[pivot] $(l more))
@darighost
darighost / hash_map.py
Created October 17, 2023 19:51
Implementing hash maps with daughter!
class HashMap:
def __init__(self, size=10_000):
self.size = size
self.values = [None] * self.size
def _char_to_number(self, c):
return ord(c) - 97
def _hash(self, string):
result = 0
@darighost
darighost / von_nuemann_vm.ts
Created October 15, 2023 06:35
Pancho triggering my autism
const MEMORY_SIZE = 1_000_000;
type Memory = any[]
type registerName = 'stackPointer'
| 'instructionPointer'
| 'returnValue'
| 'general';
interface Processor {
halted: boolean;
@darighost
darighost / nonsense_linked_list.py
Created October 12, 2023 19:00
Daughter was mad and made a bunch of nonsense during her Python homework lol
def linked_lists(node):
next_node = None
ll = []
# loop somehow
next_node = linked_lists(node)
ll.append(next_node)
next_node = None
@darighost
darighost / urbsec.md
Created October 12, 2023 06:05
Who pwns the stars?

A proposal for app sec on Urbit

TL;DR: apps should run on moons and their access to each other's data managed by a server running on your ship.

Right now, an "app" on Urbit is more like a desktop environment. Apps have access to all of your data, and manage your interaction with your Urbit. Basically, the TempleOS security model.

But in the words of ~wicdev-wisryt, Urbit is eminently securable (X).

Other proposals have been proffered, typically requiring a VM application to run on top of Urbit, which you would run apps inside of.

@darighost
darighost / country_code_flags.py
Created October 10, 2023 06:19
Generate map of country codes -> flag emojis
import flag # https://pypi.org/project/emoji-country-flag/
import pprint
# raw table from https://www.nationsonline.org/oneworld/country_code_list.htm
raw_text="""
A
Afghanistan AF AFG 004
ALA Aland Islands AX ALA 248
Albania AL ALB 008
@darighost
darighost / netmonitor.py
Last active October 10, 2023 02:04
Script made with daughter to alert us when our internet decides to come back on (guatemala life)
import requests
import subprocess
import time
while True:
try:
req = requests.get('https://google.com')
subprocess.run('say "Internet connection has been established"', shell=True)
break
except:
@darighost
darighost / nock.py
Last active September 7, 2023 04:30
Mini Nock interpret
class BTree:
def __init__(self, l, r):
self.raw_tree = (l, r)
self.left = BTree(*l) if type(l) == tuple else l
self.right = BTree(*r) if type(r) == tuple else r
def __str__(self):
return 'BTreeNode*'
def index(self, desired_i):
@darighost
darighost / find_vowels.hoon
Last active October 23, 2023 03:11
Bunch of hoon toy problems
|= n=tape
=/ index 0
=/ found ""
=/ vowels "aeiou"
|-
?: =(index (lent vowels))
found
=/ current (trip (snag index vowels))
=/ added ?: =(~ (find current n))
""
const parseIp = (ip: string) =>
ip.split('.').map((p: string) => parseInt(p));
const greaterIp = (rawIp1: string, rawIp2: string) => {
const ip1 = parseIp(rawIp1);
const ip2 = parseIp(rawIp2);
for (const ip of [ip1, ip2]) {
if (ip.length !== 4
|| ip.some(p => p > 0 && p < 255))
return `Invalid IP: ${ip}`;