Skip to content

Instantly share code, notes, and snippets.

View Python1320's full-sized avatar

Python1320 Python1320

  • M.Sc. (Tech.) Project Researcher
  • Finland
View GitHub Profile
@Python1320
Python1320 / gluasc
Created June 18, 2014 23:26
Gmod Lua Syntax Checker for SVNs
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>
static const char *getF(lua_State *L, void *ud, size_t *size)
{
FILE *f=(FILE *)ud;
@Python1320
Python1320 / opwhitelist.lua
Created July 28, 2014 09:24
luajit opcode whitelist for Garry's Mod
local bcnames = "ISLT ISGE ISLE ISGT ISEQV ISNEV ISEQS ISNES ISEQN ISNEN ISEQP ISNEP ISTC ISFC IST ISF MOV NOT UNM LEN ADDVN SUBVN MULVN DIVVN MODVN ADDNV SUBNV MULNV DIVNV MODNV ADDVV SUBVV MULVV DIVVV MODVV POW CAT KSTR KCDATAKSHORTKNUM KPRI KNIL UGET USETV USETS USETN USETP UCLO FNEW TNEW TDUP GGET GSET TGETV TGETS TGETB TSETV TSETS TSETB TSETM CALLM CALL CALLMTCALLT ITERC ITERN VARG ISNEXTRETM RET RET0 RET1 FORI JFORI FORL IFORL JFORL ITERL IITERLJITERLLOOP ILOOP JLOOP JMP FUNCF IFUNCFJFUNCFFUNCV IFUNCVJFUNCVFUNCC FUNCCW"
local jit = jit or require("jit")
assert(jit.version_num == 20003, "LuaJIT version mismatch")
local jutil = jit.util or require'jit.util'
local band = bit.band
local t = {}
@Python1320
Python1320 / coroutinefun.lua
Last active April 1, 2022 13:47
Garry's Mod Lua (glua, luajit) coroutine fun (testing version)
--setfenv(1,_G)
local meta={}
local co=setmetatable({},meta)
_G.co=co
-- todo
-- error handler wrapper?
-- select() polling support (epoll() please :c)
-- co.make steal parameters
-- ?
import json
import os
import sys
import re
parse_steamid = re.compile(r"^STEAM_(?P<X>\d+):(?P<Y>\d+):(?P<Z>\d+)$")
import struct
json_data=open("hac_db_all.json").read()
--do return print(util.SteamIDTo64("STEAM_0:1:1")) end
local fSid=file.Open("hac_sids.dat",'rb','DATA')
local fReasons=file.Read("hac_reason.dat",'DATA')
local reasons = {}
local lastpos=1
require'vstruct'
local strchar=string.char
local strfind=string.find
local gsub=string.gsub
local strsub=string.sub
local strlen=string.len
local tinsert=table.insert
local strlower=string.lower
local tremove=table.remove
local format=string.format
local getn=function(x) return #x end
@Python1320
Python1320 / luadata_test.lua
Created August 20, 2014 17:59
testing luadata prettier printing, although more expensive :(
local luadata = {}
local encode_table
local typex=type
function table.isarray(t)
local i = 0
for _ in pairs(t) do
i = i + 1
if t[i] == nil then return false end
@Python1320
Python1320 / etagsproxy.py
Created August 22, 2014 13:29
ETags Proxy for GMod http fetching and caching :x (does not work since no headers get transmitted, need to move header responses to body)
import webapp2
from google.appengine.api import memcache
from google.appengine.api import urlfetch
from google.appengine.ext import db
import hashlib
reason_texts = {
414:"fu",
@Python1320
Python1320 / gmod_sqldatetime.lua
Last active August 29, 2015 14:05
print(date('now','start of year','+9 months','weekday 2'))
-- http://www.sqlite.org/lang_corefunc.html#last_insert_rowid
function sql.LastRowID()
local ret = sql.Query("SELECT last_insert_rowid() as x")[1].x
return ret
end
-- http://www.tutorialspoint.com/sqlite/sqlite_date_time.htm
local escape=sql.SQLStr
local function gen_datefunc(fname)
@Python1320
Python1320 / hook_ex.lua
Created September 5, 2014 12:08
hook.Add callchain thingy
H=NewChain(
function(chain,...)
if not chain[2] then
return hook.Run(chain[1],...) -- call hook
elseif chain[2] then
return hook.GetTable()[chain[1]][chain[2]](...) -- call single hook??
end
end,
function(chain,val)
if isfunction(val) then