Skip to content

Instantly share code, notes, and snippets.

View g-berthiaume's full-sized avatar

G. Berthiaume g-berthiaume

View GitHub Profile
// Did you know that [Compiler Explorer](godbolt.org) allows you to include any file
// from the internet ?
//
// Just add the following line to your C source:
//
// #include <https://gist.githubusercontent.com/g-berthiaume/84160d113e5639e480eae9a0ef3af1ba/raw/1fde54c83ec3ff74dad536e0bb36d14d4db4e36b/godbolt_utils.h>
//
// This file's purpose is to create a collection of utilities for increasing my productivity on godbolt.
// This file is unlicensed. Do what you want with it. :^)
// g-berthiaume - 2024
@g-berthiaume
g-berthiaume / fizzbuzz.h
Last active January 28, 2021 16:50
Weirdly, this seems to be a classic.
// run it online:
// https://repl.it/repls/SquigglyPessimisticCron
// gberthiaume 2020
//
#include <stdio.h>
#include <string.h>
#include <stdint.h>
char* fizzbuzz(uint8_t const n)
{
@g-berthiaume
g-berthiaume / UNION_CAST.md
Last active December 24, 2019 00:38
[C] A macro to reinterpret your own data safely

A macro to reinterpret your own data safely

#define UNION_CAST(x, destType) \
   (((union {__typeof__(x) a; destType b;})x).b)

You can then use

int myInt = UNION_CAST(myFloat, int);
@g-berthiaume
g-berthiaume / insert_in_file.py
Last active May 17, 2019 12:46
Function to help insert new lines in a file.
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
"""
Python snippets: How to insert lines in a file.
NOTES:
Only standard python 3 library needed.
Tested on python 3.7 on Windows10.
G.Berthiaume 2019
"""
// Count the consecutive zero bits (trailing) on the right with multiply and lookup
// From https://graphics.stanford.edu/~seander/bithacks.html
unsigned int v; // find the number of trailing zeros in 32-bit v
int r; // result goes here
static const int MultiplyDeBruijnBitPosition[32] = {
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
@g-berthiaume
g-berthiaume / yes_no_question.py
Last active December 29, 2019 16:28
aksing a yes/no question on CLI
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
"""
Code snippet for asking user a yes/no question.
No dependencies needed.
Tested with Python 3.7
G.Berthiaume 2019
"""
from tkinter import messagebox
@g-berthiaume
g-berthiaume / list_programs.ps1
Last active January 1, 2019 03:24
Will list all installed programs in Windows 10 using the terminal.
# -------------------------------------------------------------------------------
# list_programs.ps1
# Will list all installed programs in Windows 10 using the terminal.
# From https://www.itechtics.com/list-installed-programs-windows-10/
#
# G. Berthiaume
# 2018
# -------------------------------------------------------------------------------
Write-Output "Date: $(Get-Date -Format u)"
@g-berthiaume
g-berthiaume / Useful GCC Compiler Options.md
Created December 31, 2018 18:27
A useful list of gcc compiler options

Useful GCC Compiler Options

A non exhaustive list of gcc compiler options.

$ gcc myprog.c -o myprog -Wall -Wextra -pedantic -std=c11 [...]

Optimization:

@g-berthiaume
g-berthiaume / forecast.py
Created December 29, 2018 00:25
Display weather forecast in terminal.
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
"""
Display weather forecast from the wttr website in terminal.
Dependency:
requests
Tested with Python 3.7 on windows 10.
G.Berthiaume 2018
@g-berthiaume
g-berthiaume / ListPrograms.bat
Created December 28, 2018 23:59
List all installed programs in a windows computer
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ListPrograms.bat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Will list all installed programs.
::
:: G. Berthiaume
:: 2018
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
echo List all programs installed on %date%, %time%