Skip to content

Instantly share code, notes, and snippets.

@elazarl
elazarl / POD.h
Created March 6, 2016 14:16
Serializing dictionary to NSObjects, a la Go's json package
#import <Foundation/Foundation.h>
@interface POD : NSObject<NSCopying>
-(nonnull NSString *)description;
-(nonnull NSDictionary *)toDictionary;
+(nonnull id)fromDictionary:(nonnull NSDictionary *)dict;
-(nonnull id)copyWithZone:(nullable NSZone *)zone;
@end
@elazarl
elazarl / INT 13 fail
Last active October 19, 2015 16:29
Boot loader failure
This is a demonstration of how INT 13, ah=42 fails after a while.
Run 'bash debug.sh`, then hit `c` a couple of times, you should
see that INT 13 returns with CF set, which means it had an error.
Why is it happening? The code is pretty simple, all it does is reading
a sector from the disk, and copying it to some place in the memory.
@elazarl
elazarl / parse_perf_events.c
Created March 27, 2015 11:29
A small C code sample, demonstrating the complexity of parsing the perf_event_open(2) buffer format
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 / gdbdump.sh
Created July 5, 2014 20:11
hexdump to dump memory in gdb's format
alias gdbdump='hexdump -e '\''"0x%04_ax: " 8/1 "0x%02x\t" "\n"'\'''
# hexdump format is: '"0x%04_ax: " 8/1 "0x%02x\t" "\n"'
@elazarl
elazarl / LongAdderBenchResult.md
Last active August 29, 2015 14:01
Results for LongAdderBench.java

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 / LongAdderBench.java
Last active August 29, 2015 14:00
Benchmark showing that sometime
/*
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
/**
* 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 / ecdsa_sign.go
Created March 31, 2014 20:49
An ECDSA based signature scheme compatible with openssl sha256 -sign/-verify
// 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
//
@elazarl
elazarl / cb.go
Created November 5, 2013 07:21
No backtrace for Go calls across SOs
package main
func Panic() { panic("oooh, no stacktrace") }
func make_bt_longer() {
Panic()
}
func main() {
Completer = func (text string, start, end int) (replacement string, options []string) {
@elazarl
elazarl / bug.go
Created October 7, 2013 21:38
possible bug in Go's code generation
package bug
type returnPanic struct {
err error
}
func F() (err error) {
defer func() {
if _, ok := recover().(returnPanic); !ok {
panic(err)