Skip to content

Instantly share code, notes, and snippets.

@elazarl
elazarl / ecdsa_sign.go
Created Mar 31, 2014
An ECDSA based signature scheme compatible with openssl sha256 -sign/-verify
View ecdsa_sign.go
// A signer/verifier compatible with openssl ecdsa signature scheme
//
// $ openssl ecparam -name prime256v1 -genkey -noout >ec.pem
// $ openssl ec -pubout <ec.pem >ecpub.pem
//
// and with sha256 verification
//
// $ echo a|openssl sha256 -sign ec.pem > sig.bin
// $ echo a|openssl sha256 -verify ecpub.pem -signature sig.bin
//
View KillRegions.java
/**
* Usage:
* $ javac KillRegions
* $ # list all regions in cluster, search for first listed region in MYTABLE
* $ java -cp `hbase classpath`:. KillRegions -l|grep MYTABLE|head -n1 >/tmp/regions.txt
* $ # delete first regions in MYTABLE, listed above
* $ java -cp `hbase classpath`:. KillRegions </tmp/regions.txt
*/
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
@elazarl
elazarl / LongAdderBench.java
Last active Aug 29, 2015
Benchmark showing that sometime
View LongAdderBench.java
/*
Welcome to the game show "lies and benchmarks".
We will present the participants a required result, and they would build a
benchmark that reaches the predetermined conclusions.
When done professionally, this activity is called "benchmarketing".
Our task for today is to prove LongAdder is slower than AtomicLong. Our
observation is, LongAdder prevents write contention to a single a atomic
@elazarl
elazarl / LongAdderBenchResult.md
Last active Aug 29, 2015
Results for LongAdderBench.java
View LongAdderBenchResult.md

By @cmpxchg16 1%-100% writes samples for LongAdderBench.java:

for  1% writes=16,000 (16 threads * 100,000 ops each=1,600,000):
  LongAdder  1.209ms
  AtomicLong 0.281ms
AtomicLong faster than LongAdder by 76.77%

for  2% writes=32,000 (16 threads * 100,000 ops each=1,600,000):
  LongAdder  2.019ms
  AtomicLong 0.485ms
@elazarl
elazarl / parse_perf_events.c
Created Mar 27, 2015
A small C code sample, demonstrating the complexity of parsing the perf_event_open(2) buffer format
View parse_perf_events.c
int print_records_read(void *_this, void *buf, int size) {
int nread = 0;
struct perf_record_mmap *mmap_r;
struct perf_record_lost *lost_r;
struct perf_record_comm *comm_r;
struct perf_record_exit *exit_r;
struct perf_record_throttle *throttle_r;
struct perf_record_fork *fork_r;
struct perf_record_read *read_r;
struct print_records *pr = _this;
@elazarl
elazarl / redcon.go
Created Jun 6, 2011
redirect network stream
View redcon.go
package main
import (
"log"
"io"
"os"
"crypto/tls"
"strings"
"net"
"flag"
View goroutine2coroutine.py
#!/usr/bin/env python
# coroutine equivalent of http://play.golang.org/p/lKBbS56f-n
def generate(s,even,odd):
for i,c in enumerate(s):
if i%2 == 0:
even.send(c)
else:
odd.send(c)
@elazarl
elazarl / Publishing.java
Created Dec 20, 2011
Trying to recreate the "Holder" class publishing error from JCIP.
View Publishing.java
/**
* Trying to recreate the "Holder" class publishing error from JCIP.
* See http://stackoverflow.com/a/6812936/55094 for the description of the problem.
*/
public class Publishing {
static class Holder {
int h = 0;
int dummy = 0;
public Holder(int h) {
for (long i=0;i<1000*1000;i++) {
@elazarl
elazarl / trie.c
Created Jan 21, 2012
A simple and minimal C implementation of trie
View trie.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// weird exercise from a friend
// need to Implement this struct
typedef struct attrib_t {
struct attrib_t* bytes[256];
const char *data;
@elazarl
elazarl / BencodeWriter.java
Created Feb 1, 2012
A simple bencode encoder that can handle streaming data
View BencodeWriter.java
class BencodeWriter {
static class SizedInputStream {
public InputStream stream;
public int size;
public SizedInputStream(InputStream _stream,int _size) {stream = _stream;size = _size;}
}
public static class BencodeProducer {
private OutputStream out;
public BencodeProducer(OutputStream o) {out = o;}