Skip to content

Instantly share code, notes, and snippets.

View tallpeak's full-sized avatar

Aaron William West tallpeak

View GitHub Profile
@tallpeak
tallpeak / map_pattern_match.py
Last active November 2, 2023 00:25
structural pattern matching of a map
# Simplified example of how to handle throttling of requests returned from the Shopify API
import json
import time
# The web API (GraphQL API) returns a JSON string similar to this:
content = b'{"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}'
obj = json.loads(content) # Convert it to a Python object (a map)
# Actual code to retrieve part of the object from the full JSON from the Shopify GraphQL API:
# throttleStatus = js["extensions"]["cost"]["throttleStatus"]
# Simplified:
throttleStatus = obj["throttleStatus"]
#! /usr/bin/env python3
import re
import os
pid = int(os.popen("grep -a ^./asmttpd /proc/[0-9]*/cmdline | cut -d/ -f3") .read())
maps_file = open(f'/proc/{pid}/maps', 'r')
mem_file = open(f'/proc/{pid}/mem', 'rb', 0)
output_file = open("self.dump", 'wb')
for line in maps_file.readlines(): # for each mapped region
m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line)
if m.group(3) == 'r': # if this is a readable region
@tallpeak
tallpeak / morse.rs
Last active September 1, 2023 07:32
morse code decoder in Rust, converted from morse.py by ChatGPT 3.5, no errors!
use std::collections::HashMap;
fn main() {
let morse: Vec<&str> = vec![
" ", "-.-.--", ".-..-.", "", "...-..-", "", ".-...", ".----.", "-.--.", "-.--.-", "",
".-.-.", "--..--", "-....-", ".-.-.-", "-..-.", "-----", ".----", "..---", "...--",
"....-", ".....", "-....", "--...", "---..", "----.", "---...", "-.-.-.", "", "-...-",
"", "..--..", ".--.-.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",
"...-", ".--", "-..-", "-.--", "--..", "", "", "", "", "..--.-"
@tallpeak
tallpeak / morse.py
Created September 1, 2023 05:52
morse code decoder, converted from perl by ChatGPT
morse = [' ', '-.-.--', '.-..-.', '', '...-..-', '', '.-...', '.----.', '-.--.', '-.--.-', '',
'.-.-.', '--..--', '-....-', '.-.-.-', '-..-.', '-----', '.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..', '----.', '---...', '-.-.-.', '', '-...-',
'', '..--..', '.--.-.', '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..',
'.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-',
'...-', '.--', '-..-', '-.--', '--..', '', '', '', '', '..--.-']
ascii_value = 32
morseAscii = {}
@tallpeak
tallpeak / morse.pl
Last active September 1, 2023 05:32
morse code to ascii
# ASCII 32 to 95, where "" means undefined
@morse = (' ', '-.-.--', '.-..-.', '', '...-..-', '', '.-...', '.----.', '-.--.', '-.--.-', '',
'.-.-.', '--..--', '-....-', '.-.-.-', '-..-.', '-----', '.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..', '----.', '---...', '-.-.-.', '', '-...-',
'', '..--..', '.--.-.', '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..',
'.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-',
'...-', '.--', '-..-', '-.--', '--..', '', '', '', '', '..--.-');
$ascii = 32;
for $m(@morse) {
$ch = chr($ascii++);
function leftPad(str, len, ch) {
str = String(str);
var i=-1;
if (!ch && ch != 0) ch=' ';
len -= str.length;
while (++i<len) {
str = ch + str;
}
return str;
}
// quiz3.rs
// This quiz tests:
// - Generics
// - Traits
// An imaginary magical school has a new report card generation system written in Rust!
// Currently the system only supports creating report cards where the student's grade
// is represented numerically (e.g. 1.0 -> 5.5).
// However, the school also issues alphabetical grades (A+ -> F-) and needs
// to be able to print both types of report card!
@tallpeak
tallpeak / Get-PortsByProcess.ps1
Last active April 26, 2023 18:02
All ports for each process, with CommandLine, on PowerShell 7.x (for CommandLine support)
# https://stackoverflow.com/questions/17563411/how-to-get-command-line-info-for-a-process-in-powershell-or-c-sharp
if ($PSVersionTable.PSVersion.Major -lt 6 ) {
$TypeData = @{
TypeName = 'System.Diagnostics.Process'
MemberType = 'ScriptProperty'
MemberName = 'CommandLine'
Value = {(Get-CimInstance Win32_Process -Filter "ProcessId = $($this.Id)").CommandLine}
}
Update-TypeData @TypeData
@tallpeak
tallpeak / charfreq.rs
Last active March 9, 2023 21:51
8-bit character frequency, converted from C to Rust by ChatGPT, with minor corrections at msot.
// The result of using ChatGPT to convert my C character-frequency program to Rust
// Surprisingly, this program was correctly converted by ChatGPT!
// My only change was to the "=======" header, which it printed double-length;
// a strange mistake, but very minor.
use std::io::{self, Read};
fn main() {
let mut buffer = [0; 256];
let mut freq = [0; 256];
format PE64 CONSOLE
entry main
include 'C:\util\fasmw17330\INCLUDE\WIN64a.INC'
include 'C:\util\fasmw17330\INCLUDE\API\KERNEL32.INC'
;The sieve algorithm is a simple method to find prime numbers up to a given limit. It works by marking multiples of each prime, starting from 2, as composite numbers. One possible implementation of the sieve algorithm in x64 assembly is:
;sieve equ r13
sieve_len equ 1000
section '.text' code readable executable