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
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}`;
@darighost
darighost / insert.md
Last active May 26, 2023 00:24
Selection sort in Scratch (bored at McDonald's)

I'm teaching kids Scratch, which means I need to learn it!

This program asks for a list of numbers, then prints the sorted result.

Screen Shot 2023-05-25 at 12 48 36

Eg if we give it the numbers 1488, 9001, 666, 777, and 13, and 12, it gives us:

Screen Shot 2023-05-25 at 12 59 27

@darighost
darighost / remove_bad_str.py
Last active May 1, 2023 16:33
Helping Huad understand how to use Python to remove accidentally repeated chars from a file
# re is the regular expressions library
# which facilitates our search for, and
# replacement of, strings!
import re
# This is the string we want to remove
bad_text = '#'
# Regular expressions are too deep to explain here.
# Look up a tutorial on regexes if you're curious!
@darighost
darighost / tor_crawl_skeleton.py
Created April 29, 2023 15:35
Skeleton for Tor crawler (for Eamon)
import requests
import re
# This script assumes you already have Tor installed and running
# Snagged from StackOverflow, haven't tested it!
def get_tor_session():
session = requests.session()
# My Tor daemon is on port 9150
# On your computer, it's more likely 9050
@darighost
darighost / reversed_pairs.py
Created March 20, 2023 16:13
Helping my daughter with a codewars problem
def reversed_pairs(wordlist):
if len(wordlist) == 0:
return []
word = wordlist[0]
other_words = wordlist[1:]
pair = []
for w in other_words:
if word[::-1] == w:
@darighost
darighost / count_money.py
Created December 31, 2022 04:51
Script to automate the process of figuring out how long til I'm Top Rated Plus on Upwork
with open('money.txt') as money_file:
raw_lines = money_file.readlines()
total = 0
for line in raw_lines:
if '$' in line:
money = float(line.split()[-1][1:])
total += float(money)
print('Remaining money til TOP RATED PLUS: ', 10_000 - total)
@darighost
darighost / calculate_payment.py
Created December 17, 2022 16:36
Script to figure out how much a contract on Upwork must pay to come out to a certain real total for the freelancer
from itertools import chain, repeat
def is_floatable(num):
try:
float(num)
return True
except ValueError:
return False
# based on this glorious StackOverflow post: https://stackoverflow.com/a/56081775
@darighost
darighost / camel.py
Created November 20, 2022 22:51
Quick one liner I used to make a long title camel case
' '.join([i[0].upper() + i[1:] for i in s.split()])
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC3ycW/AXmNXYAN/DgBG8R9Gwjdax0Dus5Nszx539/ZEZ6a+qwhXEoR0LI1b1NCW7zhwmaNlhj0GPBIP75nURGcnjTPr/pxvS/6MViqFogRHw60PiCmIrwgE5DoAnw7qWlJoqtP2755zs//ewfnK3sajndNiVxU8yMEctmiHG+8EXipsP/5uvX5kas0gC8c91GBbcMcT23MQxzcNuk/vZHMk1KSI36rLJ63LstvzmqVxU6CHbVW4neJzXo78jk3zdpqTybC+l+A73PpJOetAf4LOWT+/hKDRJg/cTbZnAaqQdAY2ymSnaLXagnE/hPnxq9e8yPQzQWy3UvKZyrv/y13lB0RjhCpVSVws4dIem+9eHEHgyvgTVa6DfTePKJPSauLxdRwONb8WE1OMuxn/RcKMAliWkab0wIWsALIGcJYAff+T0UzmsM3s6Y92RobwrY/w1RmDyN6H1045liaePD+JnI3XTe+8awRUn/BM+Q6ZOJ8M6538DaDjxiCymIDYLk= eliana@192.168.1.5