Skip to content

Instantly share code, notes, and snippets.


Daniel Kamil Kozar xavery

View GitHub Profile
xavery /
Created Jun 16, 2020
Handy script for converting stuff to GIFs
#!/usr/bin/env bash
set -e
delpalette() {
rm -f "$palette"
usage() {
echo >&2 "Usage : $0 [-f fps] [-x xres] <input> <output>"
exit 1
xavery / gist:856f9a6e0777c9a65db0dae5f3d7fa5f
Created Jan 28, 2020
Migrating an existing Ubuntu installation from MBR to UEFI+LVM-with-LUKS
View gist:856f9a6e0777c9a65db0dae5f3d7fa5f
# install these before the migration in the source system
apt install cryptsetup-initramfs lvm2
# assumed partition layout : sda1 - efi, sda2 - boot, sda3 - lvm
mkfs.vfat -F 32 /dev/sda1
mkfs.ext4 /dev/sda2
cryptsetup luksFormat /dev/sda3
cryptsetup open /dev/sda3 sda3_crypt
pvcreate /dev/mapper/sda3_crypt
vgcreate xubuntu /dev/mapper/sda3_crypt
xavery / nxp_crc.c
Created Feb 19, 2019
PoC code comparing bitwise and bytewise NXP CRC implementations
View nxp_crc.c
#include <stdint.h>
#include <stdio.h>
#define CRC_PRESET 0xc7
void nxp_crc(uint8_t *crc, const uint8_t value) {
/* x^8 + x^4 + x^3 + x^2 + 1 => 0x11d */
const uint8_t poly = 0x1d;
*crc ^= value;
xavery / crc_benchmark.cpp
Last active Feb 18, 2019
A benchmark comparing bytewise and bitwise CRC implementations
View crc_benchmark.cpp
#include <benchmark/benchmark.h>
#include <cstdint>
#include <array>
#include <random>
#include <algorithm>
static std::array<std::uint8_t, (1 << 16)> data;
static unsigned int CRC16_bitwise(const uint8_t *buf, int len)
View inverted-factory.cpp
struct FooInterface; // full definition irrelevant here
struct FooFactoryInterface {
virtual FooInterface* create(int p1, float p2) = 0;
class Foo : public FooInterface {
Foo(FooFactoryInterface& f):f_(f) {}
bool init(int p1, float p2) {
foo_.reset(f_.create(p1, p2));
View sortnet10.cpp
#include <array>
template<typename T, size_t N, typename UnaryFunction = std::less<T>>
void sortNet10(std::array<T, N> &data, UnaryFunction&& f = UnaryFunction()) {
static_assert(N == 10, "this function can only work for 10-element arrays");
if (f(data[0], data[5])) std::swap(data[0], data[5]);
if (f(data[1], data[6])) std::swap(data[1], data[6]);
if (f(data[2], data[7])) std::swap(data[2], data[7]);
xavery / qbytearraylist-serialization.cpp
Created May 8, 2017
Serializing and deserializing a QByteArrayList to/from a QDataStream
View qbytearraylist-serialization.cpp
#include <QByteArray>
#include <QByteArrayList>
#include <QDataStream>
#include <QDebug>
#include <QFile>
#include <cstring>
int main(int argc, char *argv[]) {
if (argc != 2) {
return 1;
xavery / sqlite-vtab-isnull.c
Created Feb 2, 2017
A demonstration of differences between = NULL and IS NULL queries in SQLite virtual tables
View sqlite-vtab-isnull.c
** 2009 November 10
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
xavery / .gitignore
Last active Jan 16, 2016
A DOS program to read binary values and convert them to decimal
View .gitignore
View factorial.asm
bits 64
global factorial
; uint64_t factorial(uint n [edi],bool *valid [rsi])
mov [rsi], dword 1 ; assume no overflow until proven otherwise
cmp edi, 1
jbe .ret1
cmp edi, 21
jae .overflow ; result will not fit in a uint64