Skip to content

Instantly share code, notes, and snippets.

@elazarl
elazarl / frag.go
Created February 13, 2017 15:32
Creating fragmentation on purpose to crash golang's GC
// 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
elazarl / setup xen environment
Last active December 4, 2016 15:06
Setup Xen development environment
setup xen environment
@elazarl
elazarl / SparkEventSource.java
Last active June 17, 2021 08:12
Suuport SSE/Server-Sent-Events/EventSource for java spark sparkjava.com
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
elazarl / qemu-with-bridge.py
Last active May 25, 2017 15:07
runs QEMU command, creating an isolated bridge with NAT internet access there, runs SSH daemon and adds bridge to QEMU's command line
#!/usr/bin/python3
"""
This scripts creates an isolated network environment,
and adds necessary configuration to the given QEMU command line to run
in this network.
WARNING: for development purposes only, allows PE for every user on the host.
Typical Usage
@elazarl
elazarl / ifdef_guard_to_pragma_once.py
Created September 13, 2016 11:57
Convert .h files using ifdef guard to use pragma once
#!/usr/bin/python
import sys
import os
import tempfile
import re
starts_with_ifndef = re.compile(r'^\s*#ifndef.*\n#define.*\n')
ends_with_endif = re.compile(r'#endif.*$')
@elazarl
elazarl / objdump-hexdump.c
Created August 8, 2016 15:03
C hexdump in objdump -x format
#include <ctype.h>
#include <stdio.h>
struct buf {
unsigned char *p;
uint64_t len;
};
void hexdump(struct buf buf) {
int i = 0;
@elazarl
elazarl / vagurl.sh
Created June 28, 2016 19:31
List vagrant box download URLs
#!/bin/bash
if [ -z "$@" ]; then
echo Example usage:
echo $0 ubuntu/xenial64
echo Output:
echo https://atlas.hashicorp.com/ubuntu/boxes/xenial64/versions/20160627.0.0/providers/virtualbox.box
echo https://atlas.hashicorp.com/ubuntu/boxes/xenial64/versions/20160625.0.0/providers/virtualbox.box
echo ...
exit 1
fi
@elazarl
elazarl / jitter.c
Last active April 21, 2016 08:16
Compare rdtsc time passed before and after a call to nanosleep
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <regex.h>
#include <time.h>
#include <stdbool.h>
@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.