Skip to content

Instantly share code, notes, and snippets.

View fclairamb's full-sized avatar
🤖

Florent Clairambault fclairamb

🤖
View GitHub Profile
@fclairamb
fclairamb / get_ppid_and_name.c
Created October 6, 2014 20:30
posix: Get parent process id and name
#ifdef SHELL
gcc -Wall -Werror $0 && ./a.out
exit $?
#endif
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
@fclairamb
fclairamb / rapidjson_gen_json.cpp
Created January 5, 2016 13:04
Write some JSON using a rapidjson library
#ifdef SHELL
g++ -Wall -Werror -g -I../../cclib/rapidjson/include $0 && ./a.out
exit 0
#endif
// Output is:
// {"project":"rapidjson","stars":11}
// {"Name":"XYZ","Rollnumer":2,"array":["hello","world"],"Marks":{"Math":"50","Science":"70","English":"50","Social Science":"70"}}
// {"FromEmail":"sender@gmail.com","FromName":"Sender's name","Subject":"My subject","Recipients":[{"Email":"recipient@gmail.com"}],"Text-part":"this is my text"}
@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 / log4j2.rolling.xml
Last active April 6, 2023 16:45
log4j2.xml sample setup files: * rolling: To enable rolling logging. * setup file to log on file (rotation should be handled by logrote), syslog (to collect all the logs from the different services) and console...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<properties>
<property name="name">app</property>
<property name="pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5.5p | %-10.10t | %-20.20C:%-5.5L | %msg%n</property>
<!--
It will look like that:
2013-04-03 07:37:51.993 | WARN | main | lnetgateway.Server:56 | My app is logging stuff
-->
</properties>
@fclairamb
fclairamb / gin_gokit_logger.go
Last active January 30, 2022 15:31
GIN Logger with go-kit/log
package ginlogger
// Directly inspired from the default gin.Logger
// This is to be used like this:
// r := gin.New()
// r.Use(gin.Recovery())
// r.Use(ginlogger.LoggerWithGoKit(mylogger))
import (
#ifdef SHELL
gcc -Wall -Werror $0 && ./a.out
exit $?
#endif
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
#define DIJ_MAX_PATHS 10
@fclairamb
fclairamb / round.cpp
Last active December 3, 2021 19:12
round.cpp
#ifdef __SHELL__
set -ex
if [ "$0" = "sh" ]; then
curl https://gist.githubusercontent.com/fclairamb/0387016387c5474e06476f0a84b6ad86/raw/round.cpp > round.cpp && \
chmod a+rx round.cpp && \
./round.cpp
exit $?
fi
BIN=test-$(arch)
@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
MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
panic(cpu 0 caller 0xffffff8021ac2838): nvme: "Fatal error occurred. ID=0xffffffff ARG1=0xffffffff ARG2=0xffffffff ARG3=0xffffffff EDD0=0xffffffff EDD1=0xffffffff EDD2=0xffffffff EDD3=0xffffffff EDD4=0xffffffff EDD5=0xffffffff EDD6=0xffffffff EDD7=0xffffffff NANDV=0x2, DRAMV=0x2, SSDC=512GB. FW Revision=16.14.01\n"@/System/Volumes/Data/SWE/macOS/BuildRoots/2288acc43c/Library/Caches/com.apple.xbs/Sources/IONVMeFamily/IONVMeFamily-557.100.13/Common/IONVMeController.cpp:5499
Backtrace (CPU 0), Frame : Return Address
0xffffffb0f5443960 : 0xffffff801f28e02d
0xffffffb0f54439b0 : 0xffffff801f3d48e3
0xffffffb0f54439f0 : 0xffffff801f3c4eda
0xffffffb0f5443a40 : 0xffffff801f232a2f
0xffffffb0f5443a60 : 0xffffff801f28d84d
0xffffffb0f5443b80 : 0xffffff801f28db43
#!/bin/bash
# The binary is most likely to have the current directory name
PROCESS=${PWD##*/}
# We kill the previous process
killall ${PROCESS}
# We launch the process
go build