Skip to content

Instantly share code, notes, and snippets.

View Gurdil's full-sized avatar

Jean-Baptiste PHILIPPE Gurdil

View GitHub Profile
@Gurdil
Gurdil / stack-use-after-scope.cpp
Created October 9, 2025 13:19
Exemple of dangling reference
#include <iostream>
#include <string>
#include <vector>
struct B{
int val = 78;
};
class A{
const B &b;
@Gurdil
Gurdil / partNumber.cpp
Created May 9, 2022 08:38
Retreive part of a number C++
#include <cmath>
#include <iostream>
int getNumberPart(int number, unsigned int start, unsigned int stop)
{
return (number % static_cast<int>(std::pow(10,stop)) - number % static_cast<int>(std::pow(10,start))) / static_cast<int>(std::pow(10,start));
}
int main()
{
@Gurdil
Gurdil / bit.cpp
Created March 1, 2022 10:39
Play with bit
#include <stdio.h>
#include <stdint.h>
#include <utility>
#include <iostream>
#include <cstdint>
template <typename T>
void switchBit(T &data, uint fisrt, uint second)
{
@Gurdil
Gurdil / hibernate.ps1
Created July 5, 2021 20:36
Hibernate your windows PC in some minutes
$time = [DateTime]::Now.AddMinutes(45)
$date=$time.ToString("d")
$hourMinute=$time.ToString("t")
Write-Host($date);
Write-Host($hourMinute);
schtasks /create /tn "$env:UserName\Hibernate" /tr "shutdown /h" /sc once /sd $date /st $hourMinute /f
@Gurdil
Gurdil / virtualInheritance.cpp
Created September 12, 2019 14:48
virtual inheritance example
#include <iostream>
class A
{
public:
int i = 0;
public:
A()
{
@Gurdil
Gurdil / leakMemoryWindows.cpp
Last active September 6, 2019 14:29
Detect leak memory on windows platform exemple
//https://docs.microsoft.com/fr-fr/visualstudio/debugger/finding-memory-leaks-using-the-crt-library?view=vs-2019
//https://support.microsoft.com/en-us/help/151585/how-to-use-crtbreakalloc-to-debug-a-memory-allocation
#include <iostream>
//include to set flag
#include <stdlib.h>
#include <crtdbg.h>
//define it at compilation property level for apply at project level
@Gurdil
Gurdil / contHash.cpp
Created August 20, 2019 11:54
constexpr hash
#include<iostream>
constexpr inline size_t _Hash_seq(const char *_First, size_t _Count)
{ // FNV-1a hash function for bytes in [_First, _First+_Count)
#if defined(_M_X64) || defined(_LP64) || defined(__x86_64) || defined(_WIN64)
static_assert(sizeof(size_t) == 8, "This code is for 64-bit size_t.");
const size_t _FNV_offset_basis = 14695981039346656037ULL;
const size_t _FNV_prime = 1099511628211ULL;
@Gurdil
Gurdil / recursiveTemplate.cpp
Created June 4, 2019 07:28
Exemple of using recursivity with template in c++
#include <sstream>
#include <iostream>
#include <vector>
template <unsigned int i>
class A
{
A<i-1> a;
public:
void show()
@Gurdil
Gurdil / variaticTemplate.cpp
Created June 3, 2019 13:23
Example of how to variatic template in C++
#include <sstream>
#include <iostream>
#include <vector>
class CudaLog
{
void cudaLog(std::ostream &stream)
{
stream << std::endl << "This is the end!" << std::endl;
}
@Gurdil
Gurdil / getProductVersion.cpp
Last active March 20, 2019 23:25
c'est dégueulasse mais c'est windows!!!
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include <iostream>
#pragma comment(lib, "version.lib")
//----------------------------------------------------------------------
int GetProductVersion(const char *szFile, char *szProductVer, size_t len)