Skip to content

Instantly share code, notes, and snippets.

@kalamay
kalamay / ANSI.md
Created January 21, 2023 04:04 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@kalamay
kalamay / ilist.h
Last active October 28, 2018 02:15
intrusive double linked list
#include <memory>
#include <cstddef>
template <class T, class Deleter = std::default_delete<T>>
class ilist
{
public:
using self_type = ilist<T>;
using pointer = T*;
using unique_ptr = std::unique_ptr<T, Deleter>;
@kalamay
kalamay / shared_ptr.c
Created December 2, 2017 18:14
Shared Pointer
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdbool.h>
static inline void increment(unsigned *cnt)
{
__atomic_fetch_add(cnt, 1, __ATOMIC_RELAXED);
}
@kalamay
kalamay / lock.h
Created December 20, 2016 05:48
Lock macros.
// based on: http://locklessinc.com/articles/locks/
#include <unistd.h>
#define XPAUSE() __asm__ __volatile__("pause\n": : :"memory")
#define XBARRIER() __asm__ __volatile__("": : :"memory")
#define XCMPXCHG(P, O, N) __sync_bool_compare_and_swap((P), (O), (N))
#define XATOMIC_FETCH_ADD(P, V) __sync_fetch_and_add((P), (V))
#define XATOMIC_ADD_FETCH(P, V) __sync_add_and_fetch((P), (V))
#define XWAIT(cond) do { \
for (unsigned n = 0; (cond); n++) { \
@kalamay
kalamay / keybase.md
Created January 5, 2016 00:39
keybase.md

Keybase proof

I hereby claim:

  • I am kalamay on github.
  • I am larkin (https://keybase.io/larkin) on keybase.
  • I have a public key whose fingerprint is 3D36 AC61 46EB 55A0 2C2E 44EE 40DD 1BCD 1615 DE69

To claim this, I am signing this object:

@kalamay
kalamay / refcount.lua
Last active August 29, 2015 14:20
luajit ffi reference counting
local ffi = require('ffi')
ffi.cdef[[
typedef struct Other Other;
typedef struct Thing Thing;
struct Other {
Thing *thing;
int index;
};
@kalamay
kalamay / imgix-s3-recommended.json
Created June 24, 2014 22:08
Recommended permissions for Imgix S3 sources
@kalamay
kalamay / imgix-s3-minimum.json
Created June 24, 2014 22:02
Minimum permissions for Imgix S3 sources
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::mybucket/*"
},
{