Skip to content

Instantly share code, notes, and snippets.

View Lokno's full-sized avatar

Lokno Lokno

View GitHub Profile
@Lokno
Lokno / fill_numbers.ahk
Last active September 27, 2024 21:34
Autohotkey script that fills a number sequence 0-n into a text editor vertically. The user is prompted for the range n.
; Author: Lokno Ketchup
; Description: Autohotkey script that fills a number sequence 0-n into
; a text editor vertically. The user is prompted for the range n.
; Default Shortcut: Ctrl+N
; return the digit count of x
CountDigits(x)
{
total := 0
Loop
@Lokno
Lokno / arduino_upload.py
Created August 10, 2021 20:16
Script that uses arduino-cli to discover a Arduino board attached to serial to compile and upload an Arduino sketch
# Script that uses arduino-cli to discover a Arduino board attached
# to serial to compile and upload an Arduino sketch
#!/usr/bin/env python3
from subprocess import check_output
import re
import sys
program_name = ''
@Lokno
Lokno / print_sheet.py
Last active August 10, 2021 20:53
Downloads a public Google Sheets spreadsheet and prints it to stdout in CSV format
# Downloads a public Google Sheets spreadsheet and prints it to stdout in CSV format
#
# NOTE: Sometimes if the format of cells are set to "Automatic" and there are mixed types in a single
# column, some values might be misinterpreted as empty. If this happens, set the format of all
# cells in that column, or even the entire table, to "Plain Text"
#
# To make a spreasheet public:
# In Google Sheets, click the Share button and then select "change to anyone with the link"
from urllib.parse import quote
@Lokno
Lokno / generate_print_func.py
Created July 30, 2021 21:52
Python3 Script that takes a file of C variable declarations and produces a C function that prints the variables to std out
import re
import sys
if len(sys.argv) != 3:
print(f' usage: {sys.argv[0]:s} <declaration file> <name>')
sys.exit(0)
array_re = re.compile( "([A-Za-z_ ]+) +([a-zA-Z0-9_]+)\[([0-9]+)\];?\n" )
value_re = re.compile( "([A-Za-z_ ]+) +([a-zA-Z0-9_]+);?\n" )
@Lokno
Lokno / curand_test.cu
Created June 17, 2021 22:27
Generates a buffer of Gaussian noise using cuRand and writes it to a binary file
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <random>
#include <limits>
#ifdef __unix__
#include <pthread.h>
#endif
@Lokno
Lokno / sthread.h
Last active September 27, 2024 21:34
Single Header Library for Simple Cross-Platform Threading
// Single Header Library for Simple Cross-Platform Threading
//
// sthread_handle handle;
// STHREAD_CREATE(handle, Func, &argument );
// STHREAD_JOIN(handle);
// STHREAD_DESTROY(handle);
//
// STHREAD_RETVAL Func( void* pArguments )
// {
// // Do Work Here
@Lokno
Lokno / add_ordinal_suffix.ahk
Created January 5, 2021 20:51
AutoHotKey script that appends the correct suffix to an ordinal number
^d::
Send {+Home}
Send ^c
Send {End}
RegExMatch(clipboard, "(\d+)$", SubPat)
StringRight, lastDigit, SubPat, 1
if( SubPat == "11" || SubPat == "12" || SubPat == "13" )
{
Send, th
}
@Lokno
Lokno / internalization_nightbot.txt
Last active January 4, 2021 22:53
Add commands to add three night bot commands for using the internalization service.
Commands for adding the Internalization Commands (copy whole line and paste into chat)
!addcom -cd=5 !perc $(eval t='nick';vs=`$(query)`;if(vs.split(' ').length>1){t=`$(1)`;vs=`$(2)`;a=`$(urlfetch http://lokno.rabbitfury.com/avg/?key=MDAwMTAwMDMwSW50ZXJuYWxpemF0aW9uOiBQRVJDJQ==&name=$(1)&user=$(user)&value=$(2))`;}else{a=`$(urlfetch http://lokno.rabbitfury.com/avg/?key=MDAwMTAwMDMwSW50ZXJuYWxpemF0aW9uOiBQRVJDJQ==&name=nick&user=$(user)&value=$(1))`;}v=Math.min(Math.max(parseInt(vs,10)|0,0),100);t=t[0].toUpperCase()+t.slice(1);`$(user) added `+v+`% to `+t+`'s Internalization`)
!commands add !perc_reset -ul=moderator -cd=5 $(eval t='nick';if(`$(query)`.length>0){t=`$(1)`;a=`$(urlfetch http://lokno.rabbitfury.com/avg/?key=MDAwMTAwMDMwSW50ZXJuYWxpemF0aW9uOiBQRVJDJQ==&name=$(1)&clear=all)`;}else{a=`$(urlfetch http://lokno.rabbitfury.com/avg/?key=MDAwMTAwMDMwSW50ZXJuYWxpemF0aW9uOiBQRVJDJQ==&name=nick&clear=all)`;}t=t[0].toUpperCase()+t.slice(1);t+`'s Internalization has been reset`)
!commands add !perc_get -ul=
@Lokno
Lokno / eval_c.py
Created December 24, 2020 01:54
Python script for evaluating single line C/C++ code
import sys,os
import subprocess
types = { 'int' : '%d',
'long' : '%ld',
'long long' : '%lld',
'float' : '%.32f',
'double' : '%.56f',
'unsigned' : '%u',
'unsigned long' : '%lu',
@Lokno
Lokno / auto_save_input_to_file.js
Created December 2, 2020 20:20
user script for https://adventofcode.com/ that automatically downloads the input for the day in the format dayDD_input.txt
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
if( document.URL.endsWith('/input') )
{
var url_sans_input = document.URL.slice(0,document.URL.lastIndexOf('/'))
var day_num = parseInt(url_sans_input.slice(url_sans_input.lastIndexOf('/')+1))