This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::collections::HashMap; | |
| fn main() { | |
| let morse: Vec<&str> = vec![ | |
| " ", "-.-.--", ".-..-.", "", "...-..-", "", ".-...", ".----.", "-.--.", "-.--.-", "", | |
| ".-.-.", "--..--", "-....-", ".-.-.-", "-..-.", "-----", ".----", "..---", "...--", | |
| "....-", ".....", "-....", "--...", "---..", "----.", "---...", "-.-.-.", "", "-...-", | |
| "", "..--..", ".--.-.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", | |
| ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", | |
| "...-", ".--", "-..-", "-.--", "--..", "", "", "", "", "..--.-" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| morse = [' ', '-.-.--', '.-..-.', '', '...-..-', '', '.-...', '.----.', '-.--.', '-.--.-', '', | |
| '.-.-.', '--..--', '-....-', '.-.-.-', '-..-.', '-----', '.----', '..---', '...--', | |
| '....-', '.....', '-....', '--...', '---..', '----.', '---...', '-.-.-.', '', '-...-', | |
| '', '..--..', '.--.-.', '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', | |
| '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', | |
| '...-', '.--', '-..-', '-.--', '--..', '', '', '', '', '..--.-'] | |
| ascii_value = 32 | |
| morseAscii = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ASCII 32 to 95, where "" means undefined | |
| @morse = (' ', '-.-.--', '.-..-.', '', '...-..-', '', '.-...', '.----.', '-.--.', '-.--.-', '', | |
| '.-.-.', '--..--', '-....-', '.-.-.-', '-..-.', '-----', '.----', '..---', '...--', | |
| '....-', '.....', '-....', '--...', '---..', '----.', '---...', '-.-.-.', '', '-...-', | |
| '', '..--..', '.--.-.', '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', | |
| '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', | |
| '...-', '.--', '-..-', '-.--', '--..', '', '', '', '', '..--.-'); | |
| $ascii = 32; | |
| for $m(@morse) { | |
| $ch = chr($ascii++); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |