Skip to content

Instantly share code, notes, and snippets.

from math import pow
def linear_to_srgb(c):
if c < 0.0031308:
return 12.92 * c
return 1.055 * pow(c, 0.41666) - 0.055
def srgb_to_linear(c):
if c < 0.04045:
return c / 12.92
@vivkin
vivkin / Makefile
Last active June 4, 2017 15:31
Small LZ77 compressor. Uses variable length integers from xz for coding length\offset
CC ?= cc
CFLAGS ?= -Wall -Wextra -std=c11 -O3
BINDIR = bin
OUTNAME = lz
SOURCES = lz.c
OBJECTS = $(SOURCES:%.c=$(BINDIR)/%.o)
export V := false
export CMD_PREFIX := @
@vivkin
vivkin / vms.c
Created February 14, 2014 00:09
mach zero fill count
#include <stdio.h>
#include <sys/mman.h>
#include <mach/mach.h>
#include <mach/vm_statistics.h>
void vm_stat()
{
int host = mach_host_self();
vm_statistics64_data_t stat;
mach_msg_type_number_t count;
@vivkin
vivkin / mouse-click.c
Created January 27, 2014 21:56
auto OS X mouse click with delay
// clang mouse-click.c -o mouse-click -framework ApplicationServices
#include <ApplicationServices/ApplicationServices.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 3)
{
fprintf(stderr, "usage: %s [seconds to wait] [number of clicks]\n", argv[0]);
@vivkin
vivkin / constexprhash.h
Last active December 31, 2015 15:18
Compile time CRC32, Bernstein and FNV1a hash functions
constexpr unsigned int CRC32_TABLE[] = {
0x00000000, 0x1DB71064, 0x3B6E20C8, 0x26D930AC, 0x76DC4190, 0x6B6B51F4, 0x4DB26158, 0x5005713C,
0xEDB88320, 0xF00F9344, 0xD6D6A3E8, 0xCB61B38C, 0x9B64C2B0, 0x86D3D2D4, 0xA00AE278, 0xBDBDF21C
};
constexpr unsigned int crc32_4(char c, unsigned int h) { return (h >> 4) ^ CRC32_TABLE[(h & 0xF) ^ c]; }
constexpr unsigned int crc32(const char *s, unsigned int h = ~0) { return !*s ? ~h : crc32(s + 1, crc32_4(*s >> 4, crc32_4(*s & 0xF, h))); }
constexpr unsigned int djb2a(const char *s, unsigned int h = 5381) { return !*s ? h : djb2a(s + 1, 33 * h ^ *s); }
constexpr unsigned int fnv1a(const char *s, unsigned int h = 0x811c9dc5) { return !*s ? h : fnv1a(s + 1, (h ^ *s) * 0x01000193); }
@vivkin
vivkin / vimrc
Last active December 22, 2015 04:38
execute pathogen#infect()
filetype plugin indent on
syntax on
set nocp
set tabstop=4
set shiftwidth=4
set expandtab
set smartindent
set cinoptions=:0,l1,g0,N-s,(0