Skip to content

Instantly share code, notes, and snippets.

elazarl / frag.go
Created Feb 13, 2017
Creating fragmentation on purpose to crash golang's GC
View frag.go
// This tiny program show how to cause fragmentation in golang, killing it
// even though no real memory is actually used.
// Compile:
// $ go build frag.go
// Run:
// $ time (setrlimit $[100*1000];./frag)
// .....(until it crashes)
package main
import "fmt"
elazarl / BlockReadWriter.go
Created May 30, 2011
golang - A blocking reader
View BlockReadWriter.go
package main
import (
elazarl /
Last active Jun 17, 2021
Suuport SSE/Server-Sent-Events/EventSource for java spark
package com.spark;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.*;
import org.eclipse.jetty.servlets.EventSource;
import org.eclipse.jetty.servlets.EventSourceServlet;
import spark.Service;
import spark.Spark;
import spark.embeddedserver.jetty.EmbeddedJettyServer;
elazarl / cp.go
Last active Jun 27, 2020
Unfortunately, searching for "golang copy file" gives subtly wrong code snippets (e.g. that don't check close error code). This is an attempt to copy file content from `src` to `dst`
View cp.go
package cp
import (
func cp(dst, src string) error {
s, err := os.Open(src)
if err != nil {
elazarl / stack_size.c
Last active Apr 12, 2020
This is a demonstration showing how to print stack size of a certain function
View stack_size.c
// We demonstrate how to get the stack usage of a function
// using the __builtin_frame_address function of GCC and clang.
// This function returns:
// The frame is the area on the stack that holds local variables and saved registers.
// The frame address is normally the address of the first word pushed on to
// the stack by the function.
// by saving its value and comparing it to a callee, we get the stack usage of this
// function.
elazarl / simple_transform_before_zstd.c
Created Jan 30, 2020
Check if a simple transform before applying zstd reduce file size
View simple_transform_before_zstd.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
char buf[1024*1024];
elazarl /
Last active Jan 29, 2020
Measures compression and decompression speed and size ratio on many files
import argparse
from collections import namedtuple
import csv
import os
import shutil
import subprocess
import statistics
import re
elazarl /
Last active Jan 26, 2020
NIST test vector to C format
# This converts test vectors from
# to a C-struct format.
# For example to initialize
# struct test_case {
# int count;
# int data_unit_len;
# std::string key;
# std::string index;
# std::string plaintext;
elazarl /
Last active May 16, 2019
replace UUID with distinguishable emojis
# -*- coding: utf-8 -*-
"""uuid4sym - replace UUID version 4 to an easily distinguishable symbol
When looking at a long log file with some UUID4 uuids, you'll have a hard time
distinguishing between two UUIDs.
Both 26cb1b84-7748-11e9-9437-2bf0efaa1b2e and 2725e8de-7748-11e9-a9c8-f3e5d10ab3d6
looks similar to the human eye.
elazarl /
Created Apr 30, 2019
Create an image with filesystem, copies a local directory content to it
"""Create image from a directory
This script creates image whose contents are a given directoy on the filesystem.
Example usage:
$ mkdir mydir
$ echo A > mydir/a
$ ./ -d mydir -i myimage.img