Skip to content

Instantly share code, notes, and snippets.

View leok7v's full-sized avatar

Leo Kuznetsov leok7v

View GitHub Profile
@leok7v
leok7v / named_dark_colors.c
Created April 30, 2024 21:55
named dark colors
typedef enum colors_t {
/* Main Panel Backgrounds */
charcoal = 0x36454F,
onyx = 0x353839,
gunmetal = 0x2A3439,
jet_black = 0x343434,
outer_space = 0x414A4C,
eerie_black = 0x1B1B1B,
oil = 0x3B3C36,
@leok7v
leok7v / lorem_ipsum_generator.c
Created January 6, 2023 08:22
lorem ipsum generator in C
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct {
char* text;
@leok7v
leok7v / !test
Created September 14, 2022 21:24
!test
# this file names the gist
@leok7v
leok7v / polyfit.c
Last active June 26, 2022 01:13
Weekend 1 hour project - needed simplest possible "least squares fitting of a polynomial"
// polyfit
// Created by leo on 6/25/22.
// Copyright © 2022 leok7v.github.io. All rights reserved.
#include <stdbool.h>
#include <assert.h>
#include <math.h>
#include <float.h>
// by Legendre in 1805:
@leok7v
leok7v / vigil.h
Created September 27, 2021 01:13
better assert() with optional format and varadic args
#pragma once /* Copyright (c) Dmitry "Leo" Kuznetsov 2021 see LICENSE for details */
#include <assert.h> // to prevent further redefinition of assert
// better assert(0 <= i && i < n, "index i=%d out of [0..%d( range", i, n);
// also available as 'swear' and 'implore' instead of assert()
// see: https://github.com/munificent/vigil
#undef assert
#if defined(_DEBUG) || defined(DEBUG) || defined(ASSERT_IN_NDEBUG)
@leok7v
leok7v / README.md
Last active May 26, 2020 01:41
dcode4 - Delta Hex Coding ('Compression')

Delta Hex Coding ('Compression')

TLDR

Here's how to compress greyscale image bytes using dcode4:

    static void foo(byte* data, int bytes) {
        byte cenoded[bytes * 2];
        int k = encode4(data, bytes, coded, sizeof(encoded));    
        byte decoded[bytes];
 int n = decode4(encoded, k, decoded, sizeof(decoded));
@leok7v
leok7v / build-apk.bash
Last active May 23, 2020 20:53
Single file bash script to build Android Hello World apk (target API=21) on osx
#!/bin/bash
# https://medium.com/@authmane512/how-to-build-an-apk-from-command-line-without-ide-7260e1e22676
# dependencies:
# https://installvirtual.com/install-openjdk-8-on-mac-using-brew-adoptopenjdk/
# brew updata
# brew tap AdoptOpenJDK/openjdk
# brew cask install adoptopenjdk8
# https://developer.android.com/ndk/downloads
# https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip
# and use:
@leok7v
leok7v / hashtable.h
Last active June 1, 2021 13:19
Simple hash table in C
#ifndef HASHTABLE_DEFINITION // single file library cannot use pragma once
#define HASHTABLE_DEFINITION // https://en.wikipedia.org/wiki/Header-only
// https://github.com/nothings/single_file_libs
/*
License: "Unlicense" (public domain) see bottom of the file for details.
This is brain dead 4 hours implementation of #153 of absolutely non-universal,
simple, growing, lineral rehash, key and value retaining hashtable with open
read/write access to table entries.
@leok7v
leok7v / system_np.c
Created February 1, 2018 02:00
Windows: system_np() - Creating a Child Process with Redirected Input and Output
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
// Reworked MSDN sample starting with https://stackoverflow.com/questions/14147138/capture-output-of-spawned-process-to-string
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
// Implemented in ~C99 instead of C++
// Child Process window hidden (for use from WinMain() /SYSTEM:WINDOWS executable)
// Creates background thread for peeking the pipes to avoid deadlocks.
// Implements timeout in milliseconds and tames CPU utilization with WaitForMultipleObjects.