Skip to content

Instantly share code, notes, and snippets.

View edubart's full-sized avatar

Eduardo Bart edubart

View GitHub Profile
import sequtils, random
proc c_malloc(size: csize): pointer {.importc: "malloc", header: "<stdlib.h>".}
proc c_aligned_alloc(alignment, size: csize): pointer {.importc: "aligned_alloc", header: "<stdlib.h>".}
proc c_free(p: pointer) {.importc: "free", header: "<stdlib.h>".}
proc mkl_malloc(size: csize, align: int): pointer {.importc: "mkl_malloc", header: "<mkl.h>".}
proc mkl_free(p: pointer) {.importc: "mkl_free", header: "<mkl.h>".}
{.passL:"-lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm".}
@edubart
edubart / mdb.lua
Created December 14, 2018 22:05
Multiple MySQL connections with Lapis
local mdbs = {}
return function(config_name)
local mdb = mdbs[config_name]
if mdb then return mdb end
local type, tostring, pairs, select
do
local _obj_0 = _G
type, tostring, pairs, select = _obj_0.type, _obj_0.tostring, _obj_0.pairs, _obj_0.select
end
local concat
@edubart
edubart / debugmem.lua
Last active December 18, 2018 23:23
Debug Lua Mem
function debug_refs()
local reftable = {}
local function trace_refs(o, src, src2, src3)
local typ = type(o)
if typ == 'number' or typ == 'boolean' or typ == 'string' or typ == 'thread' or typ == 'nil' then return end
if o == debug_refs or o == reftable or o == trace_refs then return end
if reftable[o] then return end
reftable[o] = true
if src3 then
src = string.format('%s%s%s', src, src2, tostring(src3))
@edubart
edubart / gen_lua_functions.lua
Created January 28, 2019 21:51
Generate lua functions from lua environment
local function get_args(fun)
local args = {}
local hook = debug.gethook()
local argHook = function( ... )
local info = debug.getinfo(3)
if 'pcall' ~= info.name then return end
for i=1,100 do
local name, value = debug.getlocal(2, i)
if name == nil or name:match('%(') then
package="lbc"
version="20180729-1"
source = {
url = "http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/lbc-100.tar.gz",
md5 = "e5db9e3d0cc28099e0b3b6018939b43e",
dir = "lbc-100"
}
description = {
summary = "A simple arbitrary precision library",
detailed = [[
package = "lcomplex"
version="20180729-1"
source = {
url = "http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/lcomplex-100.tar.gz",
dir = "lcomplex-100",
md5 = "ba3c9babf127cf1a313453bcabaf2a73"
}
description = {
-- import SDL headers
!!cdefine 'SDL_DISABLE_IMMINTRIN_H'
!!cinclude '<SDL2/SDL.h>'
!!linklib 'SDL2'
-- import SDL structures
local SDL_Event = @record {
type: uint32,
padding: array<byte, 56>
}
/* This file was auto generated by Euluna. */
/* Compile command: gcc -pipe -std=c99 -fno-strict-aliasing -rdynamic -lm -Wall -Wextra -Wno-incompatible-pointer-types -g -lSDL2 -o "euluna_cache/playground/snake" "euluna_cache/playground/snake.c" */
/* Compile hash: 2waXGLampSxudc7zNvTWHfYvFPNb */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#define EULUNA_NORETURN __attribute__((noreturn))
@edubart
edubart / raytrace.lua
Created May 31, 2019 22:00
euluna raytracer test
!!strict
-- optimize for performance
!!cflags '-O3 -ffast-math -march=native -fno-plt -flto -fopenmp -rdynamic -g'
!!ldflags '-flto'
--------------------------------------------------------------------------------
-- SDL
-- import SDL headers
@edubart
edubart / inheretance_example.cpp
Created February 3, 2020 13:53
inheretance_example.cpp
#include <stdint.h>
#include <stdio.h>
struct Shape {
Shape(int64_t x, int64_t y): x(x), y(y) {}
virtual int64_t area() {return 0;}
int64_t x, y;
};
struct Rectangle : public Shape {