Skip to content

Instantly share code, notes, and snippets.

View theandrew168's full-sized avatar

Andrew Dailey theandrew168

View GitHub Profile
@theandrew168
theandrew168 / solve.py
Created April 15, 2024 23:59
Using A* to solve a color combination puzzle
import collections
import itertools
import queue
import random
Puzzle = collections.namedtuple('Puzzle', 'board width height')
# mix two colors together and get the result
def mix(c0, c1):
@theandrew168
theandrew168 / spritesheet.lua
Created February 20, 2023 02:12
How to do basic OOP stuff in Lua
local Spritesheet = {}
Spritesheet.__index = Spritesheet
function Spritesheet.new(sheetPath, spriteWidth, spriteHeight)
assert(spriteWidth, 'Missing sprite width!')
assert(spriteHeight, 'Missing sprite height!')
local spritesheet = {}
setmetatable(spritesheet, Spritesheet)
@theandrew168
theandrew168 / performance.sql
Created November 29, 2021 20:06
PostgreSQL Performance Queries
-- Need to enable the extension (and restart):
-- https://pganalyze.com/docs/install/01_enabling_pg_stat_statements#configure-postgresql
-- Enable the pg_stat_statements extension (requires database superuser)
CREATE EXTENSION pg_stat_statements;
-- Check which queries are consuming the most time
SELECT
substring(query, 1, 50) AS short_query,
round(total_time::numeric, 2) AS total_time,
@theandrew168
theandrew168 / db.py
Created July 26, 2021 18:45
Useful SQLite3 connection setup in Python
import sqlite3
# References:
# https://charlesleifer.com/blog/going-fast-with-sqlite-and-python/
# https://docs.peewee-orm.com/en/latest/peewee/database.html#recommended-settings
# sqlite optimization pragmas
pragmas = {
'journal_mode': 'wal', # allow readers and writers to co-exist
'cache_size': -64 * 1024, # set page-cache size in KB (neg values mean KB)
# create the hard disk image
qemu-img create -f qcow2 void.qcow2 20G
# boot iso with hard disk attached
qemu-system-x86_64 -accel kvm -cpu kvm64 -smp 4 -m 4096 -hda void.qcow2 -cdrom void-live-x86_64-20191109.iso
# install OS to the hard disk
# boot from hard disk
qemu-system-x86_64 -accel kvm -cpu kvm64 -smp 4 -m 4096 -hda void.qcow2
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# git aliases
alias gs='git status'
alias ga='git add'
alias gaa='git add --all'
alias gc='git commit -v'
@theandrew168
theandrew168 / opengl.c
Last active November 28, 2020 18:37
Minimal example of a custom OpenGL function loader
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include "opengl.h"
#define OPENGL_DEFINE(func_name, func_type) \
set t_vb=
syntax on
set tabstop=4
set expandtab
set noautoindent
set nocindent
set nosmartindent
set indentexpr=
@theandrew168
theandrew168 / main.py
Created October 31, 2019 02:21
Still had all DES - this was a rabbit hole
from des import DesKey
import io
import uu
SAMPLE_DATA = br"""
begin 600 text.d
MJ4$2A<<%*O__[-,H5 [)._TZKE;(LDEV 7MDS=:?HD#ZP5ZV\76UMHE;@C:R
K-9];N1J/-+KTPF)S7N-MW6)[V!8L*N!Z])Z@&^A.ZQ%_@Y<;W"07/^?@D0
end
#include <iostream>
class Adder {
public:
int add(int a, int b) const { return a + b; }
};
int main() {
// Dynamic allocation using "new"
Adder *adder = new Adder();