Skip to content

Instantly share code, notes, and snippets.

View lennyerik's full-sized avatar

lennyerik

  • L1 Cache
View GitHub Profile
@lennyerik
lennyerik / decrypt_affine.py
Last active October 24, 2022 09:50
Decryption of ASCII text
s = 'NTHELY'
a = 15
b = 3
n = 26
# Modular multiplicative inverse of a
a_inv = pow(a, -1, n)
for c in s:
index = ord(c) - 65
@lennyerik
lennyerik / tetris_theme.tscript
Created November 2, 2022 21:14
Plays the Tetris theme in the TScript programming language
var frequency = [
659.25511, 493.8833, 523.25113, 587.32954, 523.25113, 493.8833, 440.0, 440.0,
523.25113, 659.25511, 587.32954, 523.25113, 493.8833, 523.25113, 587.32954,
659.25511, 523.25113, 440.0, 440.0, 440.0, 493.8833, 523.25113, 587.32954,
698.45646, 880.0, 783.99087, 698.45646, 659.25511, 523.25113, 659.25511,
587.32954, 523.25113, 493.8833, 493.8833, 523.25113, 587.32954, 659.25511,
523.25113, 440.0, 440.0
];
var duration = [
406.250, 203.125, 203.125, 406.250, 203.125, 203.125, 406.250, 203.125,
@lennyerik
lennyerik / download.py
Created December 28, 2022 13:32
Download CurseForge modpack without client
import requests
import json
import os
j = json.loads(open('manifest.json', 'r').read())
files = j['files']
for i, f in enumerate(files):
url = f['downloadUrl']
path = 'mods/' + url.split('/')[-1]
@lennyerik
lennyerik / async_decorator.py
Last active April 20, 2023 09:42
Django sync decorator for async views
from functools import wraps
from inspect import iscoroutine
from asgiref.sync import sync_to_async
def async_decorator(sync_decorator):
def _decorator(view_func):
@wraps(view_func)
async def _wrapper(*args, **kwargs):
result = await sync_to_async(sync_decorator(view_func))(*args, **kwargs)
if iscoroutine(result):
@lennyerik
lennyerik / Brainfuck.r
Last active April 27, 2023 23:20
Minimal Brainfuck interpreter in R
library(DescTools)
progstr <- ">++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+."
prog <- unlist(strsplit(progstr, ""))
cells <- rep(0, times=30)
pointer <- 1
charIdx <- 1
loopIdxs <- list()
while (charIdx <= length(prog)) {
@lennyerik
lennyerik / __clang_cuda_texture_intrinsics.h.patch
Created May 8, 2023 17:55
Patch for clang to Support CUDA 12.1
index 3c0f002..83f0c85 100644
--- a/usr/lib/clang/15.0.7/include/__clang_cuda_texture_intrinsics.h.bak
+++ b/usr/lib/clang/15.0.7/include/__clang_cuda_texture_intrinsics.h
@@ -693,7 +693,7 @@ __device__ static void __tex_fetch(__T *__ptr, __HandleT __handle,
template <class __op, class __DataT, class __RetT, int __TexT, class... __Args>
__device__ static void
__tex_fetch(__DataT *, __RetT *__ptr,
- texture<__DataT, __TexT, cudaReadModeNormalizedFloat> __handle,
+ cudaTextureObject_t __handle,
__Args... __args) {
@lennyerik
lennyerik / activity_indicators.rs
Created August 7, 2023 13:32
Terminal Activity Indicators
use std::io::{self, Write};
use std::thread::sleep;
use std::time::Duration;
fn main() {
let mut monkeys = ['🙈', '🙊', '🙉'].iter().cycle();
let mut smileys = ['🙂', '🙃'].iter().cycle();
let mut wheels = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
.iter()
.cycle();
@lennyerik
lennyerik / string_split.cpp
Created November 10, 2023 14:09
A generic string splitting iterator in C++20
#include <iostream>
#include <iterator>
#include <cstring>
template<typename T>
concept HasLengthMethod = requires(T t) {
{ t.length() } -> std::same_as<std::size_t>;
};
template<typename T>
@lennyerik
lennyerik / insults.patch
Created November 10, 2023 17:29
A patch for the Rust compiler (release 1.73.0) to throw insults at you with every suggestion
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 0cae06881b1..f9551bccde0 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -262,11 +262,11 @@ pub trait Emitter: Translate {
let msg = if substitution.is_empty() || sugg.style.hide_inline() {
// This substitution is only removal OR we explicitly don't want to show the
// code inline (`hide_inline`). Therefore, we don't show the substitution.
- format!("help: {msg}")
+ format!("help: {msg}, you idiot")