Skip to content

Instantly share code, notes, and snippets.

View fclairamb's full-sized avatar
🤖

Florent Clairambault fclairamb

🤖
View GitHub Profile
@fclairamb
fclairamb / log.c
Last active July 6, 2023 13:41
Simple C logging code
#include "log.h"
unsigned char log_run_level = LOG_LVL_DEBUG;
const char * log_level_strings [] = {
"NONE", // 0
"CRIT", // 1
"WARN", // 2
"NOTI", // 3
" LOG", // 4
@fclairamb
fclairamb / color.py
Last active December 25, 2015 06:19
RGB 24 --> 16 bits
def rgb16(r, g, b):
r = (r & 255) >> 3 # RED (5 bits)
g = (g & 255) >> 2 # GREEN (6 bits)
b = (b & 255) >> 3 # BLUE (5 bits)
c = (r << (6+5)) | (g << 5) | b
return "0x{0:04x}".format(c)
@fclairamb
fclairamb / backup-servers.sh
Created September 30, 2013 21:11
This backup script uses btrfs for snapshots and delete oldest snapshots when we reach a certain level of disk usage. Note: The most important difference with tools like rsnapshot is that it can calculate differences at a block level (whereas hardlinks only allow such a thing at a file level). Putting the snapshotting logic on the filesystem laye…
#!/bin/sh -x
# === ARGUMENTS PARSING ===
# We don't want to define a default period
PERIOD=
while echo $1 | grep ^- > /dev/null; do
if [ "$1" = "--daily" ]; then
@fclairamb
fclairamb / ctest.c
Last active December 23, 2015 09:48
Producer/Consumer exercice as requested by superman. v2, superman wasn't happy enough.
#ifdef SHELL
SCENARIO=$1
if [ "${SCENARIO}" = "" ]; then
SCENARIO=1
fi
gcc -pthread -O3 -DSCENARIO=${SCENARIO} -Wall -Werror $0 && ./a.out
exit 0
#endif
#include <pthread.h>
#include <stdio.h>
@fclairamb
fclairamb / Makefile
Created September 17, 2013 16:35
sikuli supplemental linuxvision converted the crappy "makeVisionProxy" into a makefile
OBJS=build/cvgui.o build/finder.o build/imgdb.o build/pyramid-template-matcher.o build/sikuli-debug.o build/tessocr.o build/vision.o build/visionJAVA_wrap.o
INCS=-I/usr/local/include -I/usr/include -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux
OPTS= -O3 -fPIC -MMD -MP $(INCS)
LIB=dist/libVisionProxy.so
all: $(LIB)
#ifdef SHELL
gcc -Wall -Werror $0 && ./a.out 10
exit 0
#endif
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char * argv [] ) {
int size = atoi(argv[1]);
#ifdef SHELL
gcc $0 && ./a.out
gcc -m32 $0 && ./a.out
exit 0
#endif
#include <stdio.h>
void nb1() {
char * str = "999999999999";
@fclairamb
fclairamb / unitialized_value.c
Created September 3, 2013 16:55
valgrind demo
#ifdef SHELL
gcc $0 -g -Wall -Werror && valgrind -q ./a.out
exit 0
#endif
#include <stdio.h>
int main( int argc, char * argv [] ) {
int i;
for(; i < 10; i++ ) {
@fclairamb
fclairamb / debug.c
Created September 3, 2013 16:42
An evil way to test debug macro: ./debug.c BEGIN! ./debug.c:main:19: test! ./debug.c:main:20: test! END ! BEGIN! END !
#ifdef SHELL
gcc $0 && ./a.out
gcc -DNDEBUG $0 && ./a.out
exit 0
#endif
#include <stdio.h>
#ifndef NDEBUG
#define DEBUG(fmt, arg...) \
@fclairamb
fclairamb / build_jetty_package.sh
Last active December 21, 2015 20:09
Jetty debian package builder. It takes the jetty script as is and build a jetty server that runs at startup. It's quick & simple version. Improvements are welcome.
#!/bin/sh
JETTY_VERSION=9.0.5.v20130815
# We reset everything
rm -Rf jetty-distribution-${JETTY_VERSION} jetty
# We prepare the dirs
mkdir -p jetty/opt jetty/etc/init.d jetty/etc/default jetty/DEBIAN