Skip to content

Instantly share code, notes, and snippets.

View StefanoBelli's full-sized avatar

ste StefanoBelli

  • Rome, Italy
View GitHub Profile
@StefanoBelli
StefanoBelli / broken_stackframe_setjmp.c
Last active February 22, 2022 12:54
setjmp experiments
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
typedef unsigned long long __u64;
#define get_rsp(into) \
__asm__ __volatile__("movq %%rsp, %0;" : "=m"(into) :: "memory")
#ifndef PUSH_RET_ADDR
@StefanoBelli
StefanoBelli / dgcchk.py
Last active January 30, 2022 19:39
Digital Green Certificate decoder and validator 4fun
#!/usr/bin/python
# Stefano Belli
# Digital Green Certificate decoder and validator 4fun
# Changelog
# * -- First change since publishing --
# - fix datetime.now offset-awareness
# - fix incorrect vaccine data retrieved from DGC led to wrong test results
# - fix incorrect comparison between dose number and scheduled total doses to check vaccination completeness
#!/bin/bash
DL="https://teams.microsoft.com/downloads/desktopurl?env=production&plat=linux&arch=x64&download=true&linuxArchiveType=deb"
BUILDDIR=/tmp/teams-build
PRIV="sudo"
if ! which wget 2>/dev/null >>/dev/null; then
echo "unable to find wget"
exit 1
fi
@StefanoBelli
StefanoBelli / Makefile
Last active February 19, 2020 20:17
Makefile C template
SHELL = /bin/bash
CC = gcc
OBJECT_FLAG = -c
CFLAGS = -O2 -pedantic -std=c99 -Wall -Wextra -Wshadow -W
LIBS = -lexample
OBJS = example.o
OUT = example
SUPPRESS_OUTPUT = > /dev/null 2>&1
all:$(OBJS)
@StefanoBelli
StefanoBelli / sane_example.c
Created August 26, 2019 13:13
SANE API usage example
// SANE API usage example
// link against libsane
// --> http://www.sane-project.org/html/doc012.html
#include <sane/sane.h>
#include <stdio.h>
int main() {
//
// Initialize SANE
//
#include <Windows.h>
void ClearConsole(HANDLE console) {
const COORD origin = { 0,0 };
DWORD writtenBytes;
DWORD consoleSize;
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(console, &info);
@StefanoBelli
StefanoBelli / smalloc.S
Created July 6, 2019 07:07
Simple libc-independent malloc implementation (originally written for sysh) (look at the comment section
#
# smalloc.S
#
# Simple Malloc implementation for sysh, libc-independent
#
# IF ARCH IS x86_64 THEN
# STRUCT (block_header) : {
# DATA_SIZE off 0
# _FREE_BLK off 8
//gcc showstats.c -lwiringPi -lwiringPiDev
#define ROWS 2
#define COLS 16
#define RS 1
#define EN 4
#define D7 7
#define D6 0
#define D5 2
#define D4 3
@StefanoBelli
StefanoBelli / x86_fast_string.cpp
Last active January 2, 2019 23:11
Using MSVC, Clang and GCC x86 intrinsics to use x86's SSE4.2 ISA to implement some string manip functions
// x86_fast_string.cpp
#include <nmmintrin.h>
#include <immintrin.h>
#include <cstdint>
#if defined(_MSC_VER)
#define x86_fetch_eflags(mem_dst_32) \
__asm { \
__asm pushfd \
@StefanoBelli
StefanoBelli / num.h
Last active April 26, 2021 06:59
More than simple math (math utils for C++)
#ifndef NUMERIC_H
#define NUMERIC_H
#include <initializer_list>
#include <type_traits>
#include <sstream>
#include <string>
#include <exception>
#include <vector>
#include <array>