Skip to content

Instantly share code, notes, and snippets.

View CAFxX's full-sized avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
@CAFxX
CAFxX / stack.go
Last active August 29, 2015 14:23 — forked from bemasher/stack.go
package main
import (
"fmt"
)
type Stack struct {
top *Element
size int
}
@CAFxX
CAFxX / MacroCompression.cpp
Created November 22, 2011 16:39
Macro compression for LLVM
/*
Macro compression transform for LLVM
====================================
Description
-----------
This pass identifies duplicated code sequences in the whole module and replaces
them with equivalent "macros". To keep things simple, macros are defined as
functions made up of two instructions.
@CAFxX
CAFxX / filemap.c
Created February 16, 2012 14:15
filemap
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@CAFxX
CAFxX / get_first_unique_char.c
Created February 23, 2012 15:10
Find the first non-repeated character in a string
#include <stdlib.h>
unsigned char* get_first_unique_char(unsigned char* str, const int len) {
int pos[256] __attribute__ ((__aligned__(64))), i, p;
if (str == NULL || len <= 0)
return NULL;
for (i=0; i<256; i++)
pos[i] = -1;
for (i=0; i<len; i++)
pos[str[i]] = ( pos[str[i]] == -1 ? i : -2 );
@CAFxX
CAFxX / LLVM-BB-trellis.html
Created July 20, 2012 08:30
LLVM fuzzer: BB trellis
<html><body><script>
const nBB = 256; // number of basic blocks to generate
const nI = 1; // number of instructions per basic block
const nVar = 16; // number of variables defined
const nBr = 16; // number of targets of the switch (for bThreaded==false)
const bThreaded = true; // simulate threaded code (implies nBr=nBB)
var i, vars="";
for (i=0; i<nVar; i++)
@CAFxX
CAFxX / MQReasonCodes.java
Created August 31, 2012 12:25
Convert IBM Websphere MQ reason codes to their human-readable description string
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import com.ibm.mq.constants.CMQC;
public class MQReasonCodes {
/* Use reflection on the CMQC class to fetch a human readable description of the
MQ reason code (e.g. getReason(2035) will return "MQRC_NOT_AUTHORIZED"). If the
reason code rc is not found, null will be returned */
@CAFxX
CAFxX / batching.go
Last active April 10, 2018 22:50
Batching(Read|Writ)er
type WriteBatcher struct {
l sync.Mutex
pending bool
buf []byte
err error
}
func (w *WriteBatcher) Write(p []byte) (int, error) {
w.l.Lock()
defer w.l.Unlock()
@CAFxX
CAFxX / multitenant_cpu_fairness.md
Last active May 31, 2018 23:08
Multi-tenant CPU fairness

Multi-tenant CPU fairness

Idea

We want to:

  • make sure that CPU usage in one container can't significantly affect CPU availability in a different container, regardless if the other container is below or above its CPU shares
  • minimizing false-positive CPU overload notifications
  • maximize utilization of unused CPU resources

To this end we would like to find a scheme that progressively gives more freedom in CPU resource consumption to processes that stay below their share of CPU resources (including using more than their allocated shares) while restricting processes that use more than their share of CPU resources, especially if CPU-bound, to use only their allocation.

@CAFxX
CAFxX / keybase.md
Created August 13, 2018 07:55
keybase.md

Keybase proof

I hereby claim:

  • I am cafxx on github.
  • I am cafxx (https://keybase.io/cafxx) on keybase.
  • I have a public key ASCqHgrCYkJIHf07RopDcCeYPXI3kV2St041A11PnDoGPQo

To claim this, I am signing this object:

@CAFxX
CAFxX / intern.go
Last active September 26, 2018 01:23 — forked from karlseguin/intern.go
String interning in Golang
package intern
import (
"sync"
)
type Pool struct {
sync.RWMutex
lookup map[string]string
}