Skip to content

Instantly share code, notes, and snippets.

View malkia's full-sized avatar

Dimiter 'malkia' Stanev malkia

View GitHub Profile
@simonhf
simonhf / lmdb-perf-test.txt
Created March 21, 2014 01:34
Performance testing lmdb with 16 concurrent processes & 70 million keys
# # ssh to Rackspace 16 vCPU box to perf test lmdb
# # try to do a similar multi-process test to the one at https://github.com/simonhf/sharedhashfile
# # note: could not figure out how to insert more that 70 million keys; other test inserts 100 million keys
# # note: created lmdb hash file on /dev/shm to make it a fairer test
# # note: as you can see below, inserting is extremely slow but lmdb only claims that reading is lighting fast :-)
# # note: the 'mix' 2% update, 98% read test shows that read performance gets bogged down if reading & writing :-(
# # note: not sure if I am using the lmdb API is the optimum way so please forgive me & suggest changes!
# # note: comments to feedback@sharedhashfile.com please
# apt-get update
# apt-get install build-essential
function DeleteArrayElements( array, index, count )
-- Deletes one or more (count) array elements from the specified index.
-- Returns an undo function, which if called would revert the operation.
local deletedElements = {}
assert( index >= 1 and index <= #array, "index=" .. index .. " must be >= 1 and <= " .. #array .. " (#array)" )
assert( count >= 1 and count <= #array - index + 1, "count=" .. count .. " must be >= 1 and <= " .. #array - index + 1 .. " (#array - index + 1) where #array=" .. #array .. " and index=" .. index)
for i = 0, count - 1 do
@drbobbeaty
drbobbeaty / heavySender.cpp
Created December 2, 2010 21:55
Simple ZMQ Transmitter Illustrating Memory Usage
/**
* On my CentOS 5 system this application sent the first 3000 messages
* with a running memory footprint less than 7 MB. In a few minutes, it
* leveled out at 18MB. Based on the sending rate, the maximum data rate
* out of this process should be less than 75kbps -- well below the
* ZMQ_RATE of 10Mbps. While there doesn't seem to be a long-term leak,
* the fact that this application does the first 3000 sends with a memory
* footprint far less than it's terminal value is concerning.
*
* If I change nothing other than the ZMQ_RATE value and change it to
@stevedonovan
stevedonovan / safe_array.lua
Created December 30, 2010 08:20
This defines an array with strict bounds checking. It is also impossible to set any existing index to a nil value, so the array remains free of holes. The table functions will not work on such arrays because they are userdata, giving an extra layer of pro
local function out_of_range(i,n)
if type(i) == 'number' then
if i > 0 and i <= n then return true
else error('out of range',3)
end
else
error 'cannot index array by non-number type'
end
end
diff --git a/win32/win32.c b/win32/win32.c
index 6366d92..4e52d7b 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4115,39 +4115,62 @@ winnt_stat(const WCHAR *path, struct stati64 *st)
{
HANDLE h;
WIN32_FIND_DATAW wfd;
+ WIN32_FILE_ATTRIBUTE_DATA wfa;
@AdrienLemaire
AdrienLemaire / ftpplugintex.vim
Created September 21, 2011 12:56
Mupdf hack to open pdf directly to the (sub)*section you're editing from vim in Latex
" Function: OpenPdfToSection
function! OpenPdfToSection()
let g:my_section = substitute(getline(search('\\\(sub\)\?section', 'bn')), '\\\%(sub\)\?section{\([^}]\+\)}', '\1', '')
" some weird trailing space can appear, remove them
let g:my_section = substitute(g:my_section, "^ *", "", "g")
let g:Tex_ViewRuleComplete_pdf = 'mupdf -f "'.g:my_section.'" -r 102 $*.pdf'
call Tex_ViewLaTeX()
" reinitialize the variable to keep <leader>lv working
let g:Tex_ViewRuleComplete_pdf = 'mupdf -r 102 $*.pdf'
endfunction
@malkia
malkia / cdef-sample.lua
Created January 12, 2012 20:23
idea: extend luajit's ffi.cdef so that it can return introspection information
-- Something like (ZeroMQ in this case)
return {
typedefs = {
functions = {
zmq_free_fn = { "void", "data", "hint" },
},
structs = {
zmq_pollitem_t = "zmq_pollitem_t"
},
@davidm
davidm / hamming_weight_test.lua
Created March 17, 2012 21:05
hamming weight calculation tests
--[[
Correctness and benchmark tests of various hamming weight implementations.
This is also called "popcount".
See also
http://lua-users.org/wiki/HammingWeight
http://stackoverflow.com/questions/109023/best-algorithm-to-count-the-number-of-set-bits-in-a-32-bit-integer
http://www.dalkescientific.com/writings/diary/archive/2008/07/03/hakmem_and_other_popcounts.html
http://perso.citi.insa-lyon.fr/claurado/ham/overview.pdf
http://chessprogramming.wikispaces.com/Population+Count
David Manura, 2012-03.
@geoffleyland
geoffleyland / ray-object.lua
Created July 5, 2012 00:50
Raytrace using vector objects
local sqrt = math.sqrt
local huge = math.huge
local delta = 1
while delta * delta + 1 ~= 1 do
delta = delta * 0.5
end
-- vectors -------------------------------------------------------------------
@geoffleyland
geoffleyland / ray-stack.lua
Created July 5, 2012 00:50
Raytrace avoiding vector objects
local sqrt = math.sqrt
local huge = math.huge
local delta = 1
while delta * delta + 1 ~= 1 do
delta = delta * 0.5
end
-- vectors -------------------------------------------------------------------