Skip to content

Instantly share code, notes, and snippets.

View CapsAdmin's full-sized avatar
🌜
Lua

Elias Hogstvedt CapsAdmin

🌜
Lua
View GitHub Profile
local ffi = require("ffi")
ffi.cdef("typedef struct { int *a; } foo_t;")
local function force_gc()
-- silly way to force collection
for i = 1, 10000 do
collectgarbage()
end
end
@CapsAdmin
CapsAdmin / ipadapter-faceid-loras-to-lora.py
Created December 22, 2023 03:35
converts ip-adapter-faceid_sd15.bin["ip_adapter"]["*"] to a lora that can be loaded in comfyui as a normal lora, maybe the order is wrong
import torch
import sys
all_lora_keys = [
"lora_te_text_model_encoder_layers_0_self_attn_k_proj.lora_down.weight",
"lora_te_text_model_encoder_layers_0_self_attn_k_proj.lora_up.weight",
"lora_te_text_model_encoder_layers_0_self_attn_k_proj.alpha",
"lora_te_text_model_encoder_layers_0_self_attn_v_proj.lora_down.weight",
"lora_te_text_model_encoder_layers_0_self_attn_v_proj.lora_up.weight",
@CapsAdmin
CapsAdmin / IPAdapterPlus.py
Created December 15, 2023 15:57
replace comfyui/custom_nodes/ComfyUI_IPAdapter_plus/IPAdapterPlus.py
import torch
import contextlib
import os
import math
import comfy.utils
import comfy.model_management
from comfy.clip_vision import clip_preprocess
from comfy.ldm.modules.attention import optimized_attention
import folder_paths
start end text
0.0 9.0 Three men who previously served in the military are set to speak publicly about what they saw in this guy and heard behind closed doors.
9.0 10.0 All right, what more?
10.0 11.0 Guy and the light team.
11.0 15.0 They have let in. Fifteen people from the public.
15.0 24.0 There was David Grash, who's a former intelligence official, he has knowledge of a covert government program to recover crashed alien spacecraft.
25.0 32.0 You saw me sweared or affirm that the testimony you are about to give is the truth, though all truth and nothing but the truth. So help you guys.
32.0 39.0 That is David Grash, a former Afghanistan combat veteran in 14 year high ranking intelligence office.
39.0 40.0 Hey, how are you?
40.0 41.0 I'm a businessman.
import gradio as gr
import torch
import numpy as np
from PIL import Image
# Define function to generate a red image
def generate_red_image(size: int=256):
# Create a tensor with random values between 0 and 1 for each color channel
image_tensor = torch.rand(3, size, size).to("cuda")
@CapsAdmin
CapsAdmin / luajit_remake_compat.lua
Last active June 3, 2023 21:02
loadfile("luajit_remake_compat.lua")() to get string, bit, require and table library implemented in lua. Intended for use with https://github.com/luajit-remake
-- For the string library I used https://github.com/pygy/strung.lua and removed the need for ffi.
-- My modification is not optimal at all as it's made with ffi in mind, but at least it passed its test suite and might be useful for stress testing.
-- For bit operators I used https://github.com/davidm/lua-bit-numberlua/blob/master/lmod/bit/numberlua.lua
-- for require I used https://github.com/hoelzro/lua-procure
local function find_nyi_functions()
local blacklist = {
loadfile = true,
dofile = true,
@CapsAdmin
CapsAdmin / RangeSlider.ts
Last active September 9, 2022 12:09
quick and dirty typescript version of https://github.com/githuboftigran/rn-range-slider as i just needed some sliders for debugging
import React, {
memo,
MutableRefObject,
PureComponent,
RefObject,
useCallback,
useEffect,
useMemo,
useRef,
useState,
type Mode = "safe" | "faster";
const modeStack: Mode[] = ["safe"];
const getMode = () => modeStack[0];
const pushMode = (mode: Mode) => modeStack.unshift(mode);
const popMode = () => modeStack.shift();
type HasLength = { length: number };
type WithModeRequest<Result> = {
mode: Mode;
local preprocess = {}
function preprocess.Init()
if _G.load then
_G.old_preprocess_load = _G.old_preprocess_load or _G.load
local old_preprocess_load = _G.old_preprocess_load
_G.load = function(code, name, ...)
if type(code) == "string" then
code = preprocess.Preprocess(code, name, nil, "load")
git clone git@github.com:LuaJIT/LuaJIT.git
cd LuaJIT
make
cd ..
gcc -O2 main.c -I LuaJIT/src/ -L LuaJIT/src/ -lluajit
./a.out main.lua