Skip to content

Instantly share code, notes, and snippets.

View cezarguimaraes's full-sized avatar
💭
🤔

Cezar Guimarães cezarguimaraes

💭
🤔
View GitHub Profile
@cezarguimaraes
cezarguimaraes / 0_reuse_code.js
Created May 21, 2017 04:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cezarguimaraes
cezarguimaraes / splay_tree.cpp
Last active February 12, 2017 12:39
Splay Tree
#include <bits/stdc++.h>
using namespace std;
struct node {
node *l, *r, *p;
int key, s;
node() : l(nullptr), r(nullptr), p(nullptr), s(0) { }
};
@cezarguimaraes
cezarguimaraes / console.lua
Created January 16, 2016 16:56
Interactive console for Lua 5.1
--[[
Usage:
-- Start a console instance, holds its own environment
local console = InteractiveConsole {
sum = function(a, b)
return a + b
end
}
-- First call: define output and error functions
@cezarguimaraes
cezarguimaraes / tablestorage.lua
Last active January 14, 2016 22:43
Simple Lua 5.2+ module that enables tables to be reused
--[[
Reasoning:
If your program uses (and stops using) a lot of tables, you will be dealing with the memory allocation and deallocation overhead,
Roberto Ierusalimschy suggests "recycling" tables as a way of optimizing code that uses a lot of them. This small module uses the
__gc metamethod (enabled for tables in version 5.2) to know whenever a table isn't being used anymore and stores it for future use,
avoiding an extra deallocation and future allocation of a new table. If you aren't sure that this module will help your code's
performance, do not use it because it might backfire on your goals. Even then you should customize the table clean up (or not clean
them at all) depending on what your are going to use them for.
Usage:
@cezarguimaraes
cezarguimaraes / ioitems.lua
Last active November 2, 2019 00:25
Parse tibia dat files
local vstruct = require 'vstruct'
function Items(path)
local buffer = io.open(path, 'rb')
local signature = vstruct.readvals('u4', buffer)
local itemCount, creatureCount, effectCount, distanceCount = vstruct.readvals('4 * u2', buffer)
local items = {}