Skip to content

Instantly share code, notes, and snippets.

View mniip's full-sized avatar
😼

mniip mniip

😼
View GitHub Profile
@mniip
mniip / where.lua
Last active August 29, 2015 14:09
where.lua - traverses a lua state and finds a path to a given object or hex address.
local _G, assert, newproxy, pairs, tostring, type = _G, assert, newproxy, pairs, tostring, type
local coroutine_create = coroutine.create
local debug_getfenv, debug_gethook, debug_getinfo, debug_getlocal, debug_getmetatable, debug_getregistry, debug_getupvalue, debug_upvalueid, debug_getuservalue = debug.getfenv, debug.gethook, debug.getinfo, debug.getlocal, debug.getmetatable, debug.getregistry, debug.getupvalue, debug.upvalueid, debug.getuservalue
local string_byte, string_format, string_gsub, string_match = string.byte, string.format, string.gsub, string.match
local where = {}
-- Auxiliary functions for finding the n'th key and n'th value in a table. Note
-- that the index may be invalidated even if the table is not modified, for
-- example if the table is weak
function where.nthkey(t, n)
@mniip
mniip / ldb.h
Last active August 29, 2015 14:10
(WIP) Stackless Lua api for C++ powered by template metaprogramming
inline void dumpstack(lua_State *L)
{
int n = lua_gettop(L);
printf(" <%p> Stack dump: %d values\n", L, n);
int i;
for(int i = 1; i <= n; i++)
{
printf(" [%d] ", i);
switch(lua_type(L, i))
{
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/mman.h>
#define MAX_SHIFT 24
#define REPETITIONS 10
#define ITERATIONS (1 << 20)
diff --git a/lua-5.2.3/src/Makefile b/lua-5.2.3/src/Makefile
index 7b4b2b7..efe504b 100644
--- a/lua-5.2.3/src/Makefile
+++ b/lua-5.2.3/src/Makefile
@@ -103,7 +103,7 @@ freebsd:
generic: $(ALL)
linux:
- $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lpthread"
@mniip
mniip / files-ng.lua
Last active August 29, 2015 14:12
TPT file-to-particle converter
local MEDIUM_TYPE = elem.DEFAULT_PT_BRAY
local BLOCK_LENGTH = 19
local SECTOR_LENGTH = 604
local SECTOR_OFFSET = 5
local BLOCK_OFFSET = 4
local SIGNATURE_X = 4
local SIGNATURE_Y = 4
local SIGNATURE_MAGIC = 0xBEEFD1ED
@mniip
mniip / isbanned.pl
Last active August 29, 2015 14:13
A freenode-specific irssi script that checks whether someone is banned on some channel. For hexchat version see https://gist.github.com/mniip/441aacc9f7f571b8ea25
use Irssi;
use strict;
use bignum;
use Socket;
use vars qw($VERSION %IRSSI);
%IRSSI =
(
name => "isbanned",
description => "freenode-specific module that checks whether someone is banned on some channel",
@mniip
mniip / Lambda.hs
Last active August 29, 2015 14:13
Alpha-less lambda calculus in Haskell.
module Lambda (
Lambda(..),
($$),
lambda,
lambdaEnv,
annotate,
fromInt,
toInt,
fromBool,
toBool,
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define error(...) (printf(__VA_ARGS__), exit(EXIT_FAILURE))
struct node_s
{
int type;
data Combinator = Id | Join | Const | Flip | Lift Combinator | Compose [Combinator] deriving (Eq,Show)
reorder src dst = reCompose $ optimize $ deCompose $ trans src dst
where
trans src [] = nullify src
trans src dst = Compose [trans src $ init dst, findAndMove src $ last dst]
nullify [] = Id
nullify (_:xs) = Compose [Const, nullify xs]
findAndMove [] c = error "Not found"
findAndMove (x:xs) c
IN=in.c
LINKER=in.T
OUT=out
all:
gcc -Os -fPIC -o $(OUT) $(IN) -ggdb -nostdlib -T $(LINKER) -fno-asynchronous-unwind-tables -Wl,-z,max-page-size=4096
strip $(OUT)
strip -R .comment $(OUT)