Skip to content

Instantly share code, notes, and snippets.

View Lokno's full-sized avatar

Jonathan Decker Lokno

View GitHub Profile
@Lokno
Lokno / strings.cpp
Last active August 28, 2022 10:08
Some methods of printing multiline strings in C++
#include <iostream>
#include <string>
using namespace std;
int main()
{
// you could cascade operators
cout << "+---------+" << endl
<< "| |" << endl
@Lokno
Lokno / sthread.h
Last active July 24, 2022 04:47
Single Header Library for Simple Cross-Platform Threading
// Single Header Library for Simple Cross-Platform Threading
// Author: Lokno Decker
//
// sthread_handle handle;
// STHREAD_CREATE(handle, Func, &argument );
// STHREAD_JOIN(handle);
// STHREAD_DESTROY(handle);
//
// STHREAD_RETVAL Func( void* pArguments )
// {
@Lokno
Lokno / camera.c
Last active July 20, 2022 21:44
Lines 7-24 was generated by OpenAI's davinci-codex using Lines 1-6. Lines 27-33 were generated with only Lines 25-26
// I have a plane of size A,B in 3D space. I have a camera, which is pointed dead-on at the plane. The camera is mapping the plane into a window of size X,Y.
// How far Z should the camera be away from the plane for the *entire* plane to be visible?
//
// Find the minimum distance where the entire plane is in view
float get_distance( float plane_width, float plane_height, float fov )
{
float half_width = plane_width / 2.0f;
float half_height = plane_height / 2.0f;
float half_fov = fov / 2.0f;
@Lokno
Lokno / b2s.js
Created December 1, 2021 14:22
Binary to character string in Javascript
function b2s(s) {
var b = s.replace(/[\s\t\n\r]/g, '').match(/.{1,8}/g)
var o = "";
for (i = 0; i < b.length; i++) o += String.fromCharCode(parseInt(b[i], 2));
return o;
}
@Lokno
Lokno / pairs.py
Last active November 21, 2021 23:14
Short python 3 script for randomly generating giftees for a gift exchange between 2 or more people.
from random import shuffle
from sys import argv
from pathlib import Path
names = []
if len(argv) == 2:
file_path = Path(argv[1])
if not file_path.exists():
print(f'File not found: {argv[1]:s}')
@Lokno
Lokno / archiver.py
Last active October 25, 2021 22:38
Lightweight file archiver. Store and compare files.
# Archiver
#
# Lightweight file archiver. Store and compare files.
# File names, include their extensions, are used identification, not the full file path.
#
# Default archive directory in 'default_directory' variable below. To change the
# archive directory, edit archiver_config.ini in your home directory.
#
# archiver.py [-h] [--diff] [--list] [--meta] [--remove] [--file_name [FILE_NAME]] [--modified [MODIFIED]] file_path
#
@Lokno
Lokno / getBounds.c
Created August 31, 2021 19:02
Parallel C code for finding the min and max bounds of a function of the form float f(float,float)
#include <stdio.h>
#include <pthread.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "xoshiro128plus.c"
#include "splitmix64.c"
@Lokno
Lokno / histogram.py
Last active August 30, 2021 23:20
Prints a histogram of a binary file to file. Never stores the entire file in memory.
# Written with the aid of OpenAI Codex
# Implements a histogram and draws each bar with proportional number of '*'
#
# Example Usage:
#
# data = []
# for i in range(0,10):
# data.append(random.uniform(-3.4, 6.7))
# minVal = min(data)
@Lokno
Lokno / fill_numbers.ahk
Last active August 25, 2021 16:08
Autohotkey script that fills a number sequence 0-n into a text editor vertically. The user is prompted for the range n.
; Author: Lokno Decker
; 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 / 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