Skip to content

Instantly share code, notes, and snippets.

@thelastpenguin
thelastpenguin / hashtable.lua
Last active September 11, 2019 07:48
A high performance implementation of a hash table with a point class for testing purposes
local hashtable = (function()
local hashtable_mt = {}
hashtable_mt.__index = hashtable_mt
local primes = {53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741}
local empty = {}
function hashtable()
local ht = {
data = {},
@thelastpenguin
thelastpenguin / glua-line-plane-intersection.lua
Last active September 15, 2018 17:21
GLua code to compute the intersection of a line with a plane. Used for determining where a player is looking on a 3D2D Screen
-- l0 is the origin of the line
-- l is the direction of the line expressed as a normal vector (tbd: does it have to be normal? possibly not)
-- p0 is the origin of the plane
-- n is a vector orthogonal to the surface of the plane expressed as a normal vector (tbd: does it have to be normal? possibly not)
function vectorIntersectPlane(l0, l, p0, n)
-- we find d by substituting the equation for the line into the equation of the plane and solving for d
d = (p0 - l0):Dot(n) / l:Dot(n) -- distance along the line at which the line intersects the plane
-- the point of intersection is found by substituting the distance back into the line equation
-- p = dl + l0
@thelastpenguin
thelastpenguin / gdrive-backup-setup.sh
Created May 15, 2018 20:48 — forked from stilliard/gdrive-backup-setup.sh
Backup server files with Google Drive
# ref: https://github.com/prasmussen/gdrive
# prerequisite:
# In google drive, setup your folder for storing the backups
# Then grab the code from the url e.g. https://drive.google.com/drive/folders/xxxxx where xxxxx is the code
# This code will be used later in the cron command, keep it secret, keep it safe
# install gdrive sync for backups
wget https://drive.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA -O /usr/local/bin/gdrive
chmod 755 /usr/local/bin/gdrive
@thelastpenguin
thelastpenguin / .ycm_extra_conf.py
Created June 1, 2017 02:21
.ycm_extra_conf.py
import os
import os.path
import fnmatch
import logging
import ycm_core
BASE_FLAGS = [
'-Wall',
'-Wextra',
'-Werror',
@thelastpenguin
thelastpenguin / CMakeLists.txt
Created May 30, 2017 06:42
Polycode CMakeLists.txt - a sample CMake build file for Polycode
cmake_minimum_required(VERSION 2.8)
project(game)
find_package(Threads)
find_package(OpenGL)
find_package(SDL)
set(POLYCODE_DIR /Users/garethgeorge/Desktop/GameDev/Polycode-Framework)
set(POLYCODE_LIBS
${POLYCODE_DIR}/Core/lib/libPolycore.a
@thelastpenguin
thelastpenguin / create-ramdisk.sh
Created May 23, 2017 00:10
creates a 1GB ramdisk mounted at /Volumes/RamDisk on OSX
DISK=`/usr/bin/hdiutil attach -nobrowse -nomount ram://2097152`
/usr/sbin/diskutil erasevolume HFS+ "RamDisk" $DISK
@thelastpenguin
thelastpenguin / webscraper.py
Last active May 16, 2017 00:10
A little python script for web scraping sites in parallel
import aiohttp
import asyncio
async def fetch(session, url):
with aiohttp.Timeout(10):
async with session.get(url) as response:
return await response.text()
async def fetch_all(session, urls, loop):
results = await asyncio.gather(
@thelastpenguin
thelastpenguin / jsonstream.py
Last active October 15, 2020 09:59
A library for writing and reading JSON streams from files (optionally supports gz compression)
"""
JsonStream by Gareth George
LICENSE: The do whatever the heck you want with it license.
Do what you want with it, when you want to do it. I take no responsibility for any damages that may occur in the usage of this script. This means no guaranties as to its reliability or stability.
USAGE:
file = open_stream('filename.json', 'rb') # opens the file with the given file name to be read as a json stream
file = open_stream('filename.json.gz', 'rb') # opens the COMPRESSED file with the file name to be read as a json stream
@thelastpenguin
thelastpenguin / QuotedStringParser.lua
Created August 5, 2016 23:53
Simple quoteed string parser written in lua
local quotes = {
['\''] = true,
['\"'] = true
}
local function parseString(line)
local function skipWhiteSpace(index)
return string.find(line, '%S', index)
end
local function findNextSpace(index)
dumpbin /exports lua_shared.dll > lua_shared.def
then setup the def file with the format:
EXPORTS
FUNC1
FUNC2
...
lib /machine:x86 /def:lua_shared.def /out:lua_shared.lib