Skip to content

Instantly share code, notes, and snippets.

@LPGhatguy
LPGhatguy / demo.lua
Last active August 29, 2015 14:02
OpenGL function loader for LuaJIT. This is a fixed up version of slime73's original code. See demo.lua for usage.
local glfw = require("glfw3") --Let's say we have a magic GLFW3 binding there!
local openGL = require("opengl")
openGL.loader = glfw.GetProcAddress
openGL:import()
--and somewhere else
local vbo = ffi.new("GLuint[1]")
gl.GenBuffers(1, vbo)
gl.BindBuffer(GL.ARRAY_BUFFER, vbo[0])
gl.BufferData(GL.ARRAY_BUFFER, ffi.sizeof(vertices), vertices, GL.STATIC_DRAW)
@LPGhatguy
LPGhatguy / fdef_to_stsnippet.lua
Last active August 29, 2015 14:02
Run this is a folder full of 'fdef' files to turn it into a folder of sublime-snippet files. See sample.fdef, sample.sublime-snippet, and sample-all.sublime-snippet.
--[[
]]
local lfs = require("lfs")
local CWD = "./"
function readfile(path)
local handle = io.open(path, "r")
if (handle) then
local data = handle:read("*a")
handle:close()
@LPGhatguy
LPGhatguy / digest.js
Last active January 5, 2024 13:47
Half-baked HTTP/HTTPS Digest Authentication for node.js.
var http = require("http");
var https = require("https");
var crypto = require('crypto');
function HTTPDigest(username, password, use_https) {
this.username = username;
this.password = password;
this.use_https = use_https;
}
@LPGhatguy
LPGhatguy / cascade.lua
Created August 28, 2014 00:26
Lua cascade operator. This has issues with Lua's expression-versus-statement policies, so it can be slightly ambiguous
local function table_copy(source, target)
target = target or {}
for key, value in pairs(source) do
target[key] = value
end
return target
end
@LPGhatguy
LPGhatguy / luajit-curl.lua
Last active March 19, 2023 09:53
A cURL binding for LuaJIT. Missing some constants presumably, but functional
--[[
LuaJIT-cURL
Lucien Greathouse
LuaJIT FFI cURL binding aimed at cURL version 7.38.0.
Copyright (c) 2014 lucien Greathouse
This software is provided 'as-is', without any express
or implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software.
@LPGhatguy
LPGhatguy / composition.lua
Last active August 29, 2015 14:11
Function composition operator in Lua using __concat, which might not be the best operator to use.
debug.setmetatable(function() end, {
__concat = function(self, with)
return function(...)
return self(with(...))
end
end
})
local sin = math.sin
print((sin .. sin)(5)) --sin(sin(5))
@LPGhatguy
LPGhatguy / VoipEncoder.lua
Created December 16, 2014 22:18
Demonstration of encoding SoundData into a packet
local ffi = require("ffi")
-- Create a C struct representing the header for our packet
ffi.cdef([[
typedef struct {
uint32_t uuid; // user identifier
uint32_t size; // in bytes
uint32_t bitrate; // in Hz
uint16_t bitdepth; // bits per sample
uint16_t channels; // probably 1 or 2
@LPGhatguy
LPGhatguy / README.md
Last active August 29, 2015 14:16
An API to generate badges and place them in markdown readme files automatically using shields.io.

README Sample

This file is to be used with the example.lua file.

Here, we use Markdown's ability to use shortlink images:

Testing results: ![shield_build] ![shield_tests]

Version information:

@LPGhatguy
LPGhatguy / alias.lua
Created October 17, 2015 09:08
Converts snake_case libraries (like excessive moe's) to camelCase.
local function breakSnake(id)
if (type(id) ~= "string") then
return id
end
return (id:gsub("(%w)_(%a)", function(a, b)
return a .. b:upper()
end))
end
@LPGhatguy
LPGhatguy / main.lua
Created October 17, 2015 09:27
Pote: The Portable Game FS Extension
local pote = require("pote")
function love.load(args)
pote.mount(args)
print(love.filesystem.read("app/main.lua"))
end