Skip to content

Instantly share code, notes, and snippets.

View vstakhov's full-sized avatar

Vsevolod Stakhov vstakhov

  • Cambridge, UK
  • 11:12 (UTC +01:00)
View GitHub Profile
local u = require "lua_util"
local m = require "lua_magic"
local l = require "rspamd_logger"
local text = require "rspamd_text"
local rspamd_task = require "rspamd_task"
local rspamd_util = require "rspamd_util"
local function load_task(opts, fname)
if not fname then
fname = '-'
local cr = require "rspamd_cryptobox_hash"
local rspamd_util = require "rspamd_util"
local lua_util = require "lua_util"
repeat
local inp = rspamd_util.readline()
if inp then
print(cr.create(lua_util.rspamd_str_trim(inp)):base32():sub(1, 32))
end
until not inp
@vstakhov
vstakhov / fun_test.lua
Last active July 19, 2019 14:14
lua-fun
local fun = require "fun"
local rspamd_util = require "rspamd_util"
local l = require "rspamd_logger"
-- filter(map(ls))
local function t(inp, f)
return fun.filter(function(map_elt) return map_elt end,
fun.map(function(list_elt)
return f(list_elt)
end, inp))
function f1(t) 
  local t1 = util.get_ticks(true); 
  for i=1,1000500 do table.insert(t, i) end 
  local t2 = util.get_ticks(true)
  print(string.format("%d = %d", #t, t2 - t1))
end

Keybase proof

I hereby claim:

  • I am vstakhov on github.
  • I am vstakhov (https://keybase.io/vstakhov) on keybase.
  • I have a public key whose fingerprint is DD9A 126C E675 1EA5 2A97 04A3 0764 7B67 9008 1437

To claim this, I am signing this object:

@vstakhov
vstakhov / jemalloc.md
Created January 12, 2017 12:40
Jemalloc profiler practical sample
  1. Get source package: apt-get source libjemalloc-dev
  2. Install build depends: apt-get build-dep libjemalloc-dev
  3. Go to the source dir and edit debian/rules file adding the following text:
override_dh_auto_configure:
        dh_auto_configure -- --enable-debug --enable-fill --enable-prof --enable-stat
  1. Build packages: dpkg-buildpackage

New mime parser algorithm for Rspamd

  1. If we have any complicated (multipart or message) part in the top, then apply the following algorithm. Otherwise goto step 10
  2. Use multipattern scan (hyperscan/aho-corasic) to find all occurences of patterns \r-- and \n--
  3. For each occurence we check sanity:
  • We find the length of substring where there are no \r and \n
  • We check the ending of this substring
  • If this substring is empty, we skip it
  • If this substring ends with -- we assume it closing
  1. For normal boundaries calculate H(boundary), where H is a hash function described below
#include <stdint.h>
#include <string.h>
#include <assert.h>
static inline uint64_t
diffuse(uint64_t val)
{
uint64_t a, b;
val *= 0x6eed0e9da4d94a4fULL;
//a = val >> 32;
@vstakhov
vstakhov / seahash.cc
Last active December 3, 2016 18:47
Seahash in C(++)
#include <stdint.h>
#include <string.h>
#include <assert.h>
static inline uint64_t
diffuse(uint64_t val)
{
uint64_t a, b;
val *= 0x6eed0e9da4d94a4fULL;
a = val >> 32;