Skip to content

Instantly share code, notes, and snippets.

View Lokno's full-sized avatar

Lokno Lokno

View GitHub Profile
@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))
@Lokno
Lokno / evaluate.h
Last active October 19, 2020 01:40
evaluate() evaluates an expression passed in as a char array using the Lua scripting language
//
// evaluate() evaluates an expression passed in as a char array using the Lua scripting language
// The expression may reference a set of floating-point variables past in as an pair of
// arrays corresponding to the key, or name, of the variable and its value.
//
// Tested with Lua-5.4.0
//
// Depends on stb_ds.h from https://github.com/nothings/stb
#define STB_DS_IMPLEMENTATION
@Lokno
Lokno / text_gradient.js
Created June 8, 2020 15:09
Sets the gray scale color of each text item in a group of a given name to a smooth gradient
var layerSetText = app.activeDocument.layerSets.getByName("GROUPNAME")
for (var i=0; i<layerSetText.artLayers.length; i++) {
var col = new SolidColor();
var grayCol = new GrayColor();
grayCol.gray = i*100.0/(layerSetText.artLayers.length-1);
col.gray = grayCol;
layerSetText.artLayers[i].textItem.color = col;
}
@Lokno
Lokno / sfloat.h
Last active July 21, 2021 16:10
simple float / safe float (WIP)
// simple float / safe float (WIP)
//
// For when you want your math to be real with you
//
// drop-in replacement for a IEEE single-precision float that
// maintains a real-number
//
// Optionally define SFLOAT_ABORT_NONREAL fail on first occurance
// of a non-real number
//