Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Decker Lokno

View GitHub Profile
@Lokno
Lokno / eval_clipboard.py
Created Jan 23, 2023
Executes the contents of the clipboard as Python and returns the result to the clipboard
View eval_clipboard.py
# Executes the contents of the clipboard as Python and returns the result to the clipboard
# Uses eval() if single-line and uses compile() and exec() if multi-line
# Will attempt to handle a limited number of NameError exceptions
# Obvious at your own risk and know what you're doing caveats
import pyperclip
import traceback
import contextlib
import sys
import re
@Lokno
Lokno / ocr_shortcut.ahk
Last active Jan 13, 2023
AutoHotKey script to add a keyboard shortcut to process a region of the screen using OCR and copy the result into the clipboard
View ocr_shortcut.ahk
; AutoHotKey script to add a keyboard shortcut to select a region of the screen,
; run OCR on that region, and paste the result in the clipboard.
; Set to look for English text, see line 24
; Shortcut default is ctrl+shift+alt+i, see line 20
; Press esc when selecting to close, or right-click system tray icon
; Modified script from OP of this forum post:
; https://www.autohotkey.com/boards/viewtopic.php?p=314654#p314654
@Lokno
Lokno / webclipboard.py
Last active Jan 9, 2023
Cross-platform python script that maintains an encrypted copy of your clipboard at a user-specified remote location
View webclipboard.py
# Cross-platform python script that maintains an encrypted copy of your clipboard
# at a user-specified remote location. Complete with tkinter GUI set-up.
#
# Author: Lokno Decker
#
# Usage: webclipboard.py copy|paste [--reset] [--show-config]
# Options:
# copy : encrypts the contents of the current clipboard to file
# and uploads this file to a user-specified remote server.
# paste : downloads the clipboard file from a user-specified
@Lokno
Lokno / webp_begone.py
Last active Sep 9, 2022
Python 3 script that replaces every webp on your desktop with a PNG. Requires Google's dwebp decoder (https://developers.google.com/speed/webp/docs/dwebp)
View webp_begone.py
# Webp-Begone
#
# Iterates over all the files ending in ".webp" on the Desktop and converts
# them to PNG files using the Google utiltiy dwebp
# Alteratively a different directory path can be specified at the cmdline
# Install dwebp and add it to your path
# https://developers.google.com/speed/webp/docs/dwebp
# https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html
@Lokno
Lokno / connect_to_switch.py
Last active Jan 27, 2023
Python 3 Script for automatically connecting a PC to hotspot created by the Nintendo Switch to serve media to a smart device
View connect_to_switch.py
# Python 3 Script for automatically connecting a PC to the temporary hotspot
# created by the Nintendo Switch to serve media to a smartphone
#
# How to Set Up the hotspot transfer from the Nintendo Switch:
# 1. From the HOME Menu select Album, then select a screenshot or video capture.
# 2. Select Sharing and Editing, then select Send to Smartphone.
# 3. Select Only This One or Send a Batch.
# 4. A screen with a QR code will appear with the encoded SSID and password.
# This is where the script will take over.
#
@Lokno
Lokno / b2s.js
Created Dec 1, 2021
Binary to character string in Javascript
View b2s.js
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 / archiver.py
Last active Oct 25, 2021
Lightweight file archiver. Store and compare files.
View archiver.py
# 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 / camera.c
Last active Jul 20, 2022
Lines 7-24 was generated by OpenAI's davinci-codex using Lines 1-6. Lines 27-33 were generated with only Lines 25-26
View camera.c
// 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 / getBounds.c
Created Aug 31, 2021
Parallel C code for finding the min and max bounds of a function of the form float f(float,float)
View getBounds.c
#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 Aug 30, 2021
Prints a histogram of a binary file to file. Never stores the entire file in memory.
View histogram.py
# 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)