Skip to content

Instantly share code, notes, and snippets.

@rfl890
rfl890 / lua-msvc-build.lua
Last active May 10, 2024 14:21
Build Lua with MSVC
-- configuration
local BUILD_AS_DLL = false
local LINK_CRT_STATIC = false
local CC = "cl.exe"
local CFLAGS = { "/nologo", "/O2", "/DLUA_COMPAT_5_3" }
if BUILD_AS_DLL then table.insert(CFLAGS, "/DLUA_BUILD_AS_DLL") end
if LINK_CRT_STATIC then table.insert(CFLAGS, "/MT") else table.insert(CFLAGS, "/MD") end
-- utils
local fmt = string.format
@rfl890
rfl890 / main.c
Created May 7, 2024 14:02
Macro Abuse 2: Electric Boogaloo
#include "wtf.h"
MAINF
PRINT("Hello, world!")
ENDMAINF
@rfl890
rfl890 / dice-roll-rdrand.c
Created April 29, 2024 18:12
Dice Roll with RDRAND
#include <stdint.h>
#include <immintrin.h>
#ifdef __GNUC__
#define LOG2(X) \
((uint32_t)(8 * sizeof(unsigned long long) - __builtin_clzll((X)) - 1))
#else
#ifdef _MSC_VER
#include <intrin.h>
inline uint32_t LOG2(uint64_t X) {
#include <stdint.h>
#ifdef __GNUC__
#define LOG2(X) \
((uint32_t)(8 * sizeof(unsigned long long) - __builtin_clzll((X)) - 1))
#else
#ifdef _MSC_VER
#include <intrin.h>
inline uint32_t LOG2(uint64_t X) {
unsigned long out;
@rfl890
rfl890 / timing-safe-equal.js
Created March 13, 2024 19:37
Timing safe comparison in JavaScript
function timingSafeEqual(a, b) {
if (a.length !== b.length) return false;
let result = 0;
for (let i = 0; i < a.length; i++) {
result |= a[i] ^ b[i];
}
return result === 0;
}
From c796842c4aaaca1b640a1fd0e03c9d8e85f571c8 Mon Sep 17 00:00:00 2001
From: rfl890 <87506407+rfl890@users.noreply.github.com>
Date: Wed, 24 Jan 2024 18:14:16 -0500
Subject: [PATCH] Update PRNG
---
src/lib_math.c | 2 +-
src/lj_prng.c | 43 ++++++++++++++++++++++---------------------
2 files changed, 23 insertions(+), 22 deletions(-)
@rfl890
rfl890 / build-lua-to-exe.lua
Created December 13, 2023 12:55
Internal Script
-- Change to the path of lua51.lib/libluajit-2.1.a/whatever LuaJIT library you link against
local lua_slib = "\"C:\\Users\\user\\bin\\luajit\\lib\\lua51.lib\""
local CC = "clang -O2"
local stub_code = [[#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <luajit.h>
#include <stdlib.h>
@rfl890
rfl890 / color.lua
Created November 30, 2023 22:30
Lua color library
local lib_color = {}
-- Constants
lib_color.color_type = { TYPE_8 = 39710315, TYPE_256 = 34942623, TYPE_RGB = 29505187 }
local FOREGROUND = 1
local BACKGROUND = 2
local ESCAPE = "\x1b["
local RESET = "\x1b[0m"
@rfl890
rfl890 / sha256.c
Created September 11, 2023 18:43
CNG hash
#include <stdio.h>
#include <stdint.h>
#include <Windows.h>
#include <bcrypt.h>
#include <ntstatus.h>
#include <ntdef.h>
typedef struct SHA256State {
BCRYPT_ALG_HANDLE algHandle;
@rfl890
rfl890 / lua-unicode-input.lua
Last active December 13, 2023 00:30
Hacky way of obtaining Unicode input as UTF-8 in Lua(JIT)
local ffi = require("ffi")
ffi.cdef[[
struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;