Skip to content

Instantly share code, notes, and snippets.

View tallpeak's full-sized avatar

Aaron William West tallpeak

View GitHub Profile
# give.a.dollar.jl
# from tc:
# http://primepuzzle.com/not.just.tiny.c/give.a.dollar.try.tc?fbclid=IwAR2p5YBQgJJDY3-g3lN3rRHw7v7cA0VB0BcNWv4dHybH-XCCgxQQIrbF6sY
# ref: https://www.facebook.com/groups/299317782048/posts/10160467717107049/
# give.a.dollar.tc - lrb
# tc give.a.dollar.tc -r "give(lim,sd)"
using Random
using Printf
// give.a.dollar.rs, from julia, from tiny-c:
// http://primepuzzle.com/not.just.tiny.c/give.a.dollar.try.tc?fbclid=IwAR2p5YBQgJJDY3-g3lN3rRHw7v7cA0VB0BcNWv4dHybH-XCCgxQQIrbF6sY
// ref: https://www.facebook.com/groups/299317782048/posts/10160467717107049/
use std::io;
use rand::prelude::*;
use timed::timed; //https://y2kappa.github.io/blog/posts/timing-your-function-execution/
fn gn() -> i32 {
let mut input = String::new();
match io::stdin().read_line(&mut input) {
#include "postgres.h"
#include <string.h>
#include "fmgr.h"
#include "utils/geo_decls.h"
PG_MODULE_MAGIC;
/* by value */
PG_FUNCTION_INFO_V1(upc_checkdigit);
Datum
@tallpeak
tallpeak / charfreq.c
Last active March 6, 2023 02:42
Character frequency
#include <stdio.h>
#include <string.h>
//maybe works on posix not working for me on windows (S_ISCHR not defined)
//https://comp.os.os2.programmer.porting.narkive.com/s5n0plkf/how-to-set-stdin-stdout-stderr-to-binary-mode
// #include <io.h> // setmode()
// #include <fcntl.h> // O_BINARY
// #include <stdio.h> // FILE, fileno()
// #include <sys/stat.h> // struct stat, fstat(), S_ISCHR()
// static inline void set_bin_mode(FILE *stream)
@tallpeak
tallpeak / charfreq.asm
Last active March 7, 2023 19:11
Character Frequency from stdin -- flat assembler version
format PE64 CONSOLE
entry start
include 'C:\util\fasmw17330\INCLUDE\WIN64a.INC'
section '.data' data readable writeable
;freq dq 256 dup(0) ; why waste 2kb in exe?
;freq equ rbp-8*256 ;stack allocation
define freq rbp-8*256 ;same as equ
header1 db "Top hex digits are the second digit of the character value", 10, "Left-side hex numbers are the first digit of the character value", 10, "numbers in the table are the frequency of each character found in stdin.", 10, 0
@tallpeak
tallpeak / sieve_win64.asm
Last active March 7, 2023 19:09
After slight help from chatGPT, it took me some time to get this working, and using VirtualAlloc rather than a static buffer
format PE64 CONSOLE
entry main
include 'C:\util\fasmw17330\INCLUDE\WIN64a.INC'
include 'C:\util\fasmw17330\INCLUDE\API\KERNEL32.INC'
;section '.data' data readable writeable
; primes dq 2
;sieve db 1000000 dup 1
define sieve r13
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
@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];
@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
// 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!