Skip to content

Instantly share code, notes, and snippets.

@avelican
avelican / main.rs
Created June 14, 2024 00:45
rust runtime overflow
use macroquad::prelude::*;
#[macroquad::main("BasicShapes")]
async fn main() {
rand::srand(macroquad::miniquad::date::now() as _);
let w = 400;
let h = 400;
@avelican
avelican / pi.cpp
Created June 13, 2024 23:51
pi fraction finder
#include <stdio.h>
#include <math.h>
#include <float.h>
int main() {
const double PI = 3.141592653589793;
double m = 1;
double n = 1;
// double max_m = 10000;
// double max_n = 10000;
const w4 = @import("wasm4.zig");
// actual render resolution
const SCREEN_SIZE = w4.SCREEN_SIZE;
// game resolution (everything is rendered 2x)
// const SCREEN_WIDTH = 48*2;
const SCREEN_WIDTH = 96;
const SCREEN_HEIGHT = SCREEN_SIZE;
@avelican
avelican / index-variable-width.html
Last active February 2, 2024 01:32
sprite font renderer
<!doctype html>
<html lang="en">
<head>
<title>sprite font</title>
<style>
body{
background-color: gray;
margin: 0;
padding: 0;
}
@avelican
avelican / udpClient.c
Created January 29, 2024 17:10
Noob's attempt: Cross Platform UDP (Linux + Windows)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN // prevent import of WinSock ? (conflict with WinSock2)
#include <windows.h> // sleep()
#define sleep(n) Sleep((n) * 1000)
#include <winsock2.h>
import json
import os
import openai
import tiktoken
import gradio as gr
openai.api_key = os.getenv("OPENAI_API_KEY")
USE_GPT4 = False
OPENAI_MODEL = "gpt-4" if USE_GPT4 else "gpt-3.5-turbo"
@avelican
avelican / stereo.py
Created May 7, 2023 18:28
autostereogram generator
# credit goes to https://github.com/synesthesiam/magicpy
# Instructions: Texture image MUST be as tall as depth map (taller should work too),
# and 1/8th of its width (or thereabouts -- any width will work but might not look too good).
from PIL import Image
if __name__ == '__main__':
depth_file = "depth.jpg"
@avelican
avelican / gpt-async.py
Created May 1, 2023 10:26
Parallelize GPT API
# import openai
import os
import asyncio
import aiohttp
import random
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
@avelican
avelican / yt-txt.py
Created April 30, 2023 08:19
Get YouTube transcript (from subtitles / caption file)
import sys
import subprocess
if len(sys.argv) < 2:
print("Please provide a YouTube video URL as the first argument.")
sys.exit(1)
video_url = sys.argv[1]
command = [
@avelican
avelican / keypoints.py
Created April 26, 2023 23:04
Keypoints.py - Summarize a long text document to bullet points
import os
import openai
prompt = "I'm a busy CEO, please summarize the following in 10-20 bullet points. Include only the most important, useful or interesting information.\n\n"
# model = 'gpt-3.5-turbo' # 'gpt-4' # moved to gpt_chat_completion since we use both
CONTEXT_SIZE = 4096 # 2048 for GPT-3 (as half the input.
# CONTEXT_SIZE = 1024 # tiny context for testing
MAX_TOKENS_IN = int(CONTEXT_SIZE*2/3)
MAX_TOKENS_OUT = CONTEXT_SIZE - MAX_TOKENS_IN