Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
# Copyright (c) 2018-2022 Joergen Ibsen
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
@jibsen
jibsen / addflags.md
Created June 10, 2016 18:35
CMake functions to add compiler flags

Code

Here are two simple CMake functions that take a list of compiler flags, and append those that do not result in an error when used to the supplied variable.

Depending on which version of CMake you need to support, you might want to look into the COMPILE_FLAGS property and target_compile_options().

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@jibsen
jibsen / buildtime.md
Created April 6, 2016 14:54
Comparing clone and build time between native Windows and Linux VM

About

These are timings for cloning the [squash][] repository including submodules, running [CMake][] to generate makefiles, and building the project in debug mode.

All toolsets run on the same machine (Core i5, 8 GB, Win10 64):

@jibsen
jibsen / bytes.md
Last active December 20, 2023 10:02
Ramblings about uint8_t and undefined behavior

Introduction

The C standard only specifies minimum limits for the values of character types and standard integer types. This makes it possible to generate efficient code on diverse architectures, but can pose problematic if your code expects the limits to match your development platform, or if you have to do low-level things.

Before C99, the usual way to solve this was to use typedef to declare synonyms

@jibsen
jibsen / bsort32.asm
Created November 15, 2015 09:42
Bubble sort in 16 bytes of x86 assembly language
;;
;; The "worlds smallest" bubble sort (16 bytes)
;;
;; Copyright (c) 1998 by Joergen Ibsen / Jibz
;; All Rights Reserved
;;
bits 32
section .text
@jibsen
jibsen / srgbtogenericrgb.py
Created October 22, 2014 06:50
Example of converting RGB colors from sRGB to Generic RGB
#!/usr/bin/env python3
# Copyright (c) 2014 Joergen Ibsen
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
@jibsen
jibsen / pastry.py
Created September 17, 2014 12:34
Copy lines to clipboard one at a time
#!/usr/bin/env python3
# Copyright (c) 2014 Joergen Ibsen
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
@jibsen
jibsen / concol.c
Created December 2, 2013 09:09
Simple example of printing text in color to a Windows console window. Most interesting bit is probably con_wait_key, which works for most keys including Esc.
/*
* Console Color
*
* Copyright (c) 2005 Joergen Ibsen
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
@jibsen
jibsen / coordsort.c
Last active December 25, 2015 01:59
A simple example that reads integer coordinates in the form x,y into a scv_vector and prints them in lexicographical order.
#include <stdlib.h>
#include <stdio.h>
#include "scv.h"
struct point {
int x;
int y;
};