Skip to content

Instantly share code, notes, and snippets.

View abel0b's full-sized avatar
🐉
Compiling

Abel Calluaud abel0b

🐉
Compiling
  • Voie lactée
View GitHub Profile
@abel0b
abel0b / appdata.c
Created November 23, 2020 19:09
Get AppData Roaming folder in C C++
// how to locate application data %AppData% directory path on Windows 10 MSVC
// see on documentation https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath?redirectedfrom=MSDN
// compiled with cl .\appdata.c Shell32.lib
#include <stdlib.h>
#include <stdio.h>
#include <shlobj_core.h>
#include <direct.h>
int main() {
@abel0b
abel0b / dict.c
Created June 28, 2020 13:30
Simple dictionary / hash table implementation in C
#include "dict.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static int NUMBUCKETS = 8;
static int INITBUCKETCAPACITY = 8;
void dict_new(struct Dict* dict) {
dict->numbuckets = NUMBUCKETS;
@abel0b
abel0b / install-llvm.sh
Created June 27, 2020 13:20
Install llvm clang openmp from sources
git clone https://github.com/llvm/llvm-project.git --depth=1 /tmp/llvm
mkdir /tmp/llvm/build
cd /tmp/llvm/build
cmake -DLLVM_ENABLE_PROJECTS="clang;openmp;libcxx;libcxxabi;libunwind;lldb;compiler-rt;lld" -DCMAKE_INSTALL_PREFIX="/opt/llvm" ../llvm
make -j64
make install
@abel0b
abel0b / snippets.mk
Created June 9, 2020 09:28
Makefile snippets
# Check if a library exists
define lib_exists
echo "int main(){}" | g++ -x c++ -Wl,--no-as-needed -l$(1) -
endef
# Update a git submodule
define update_external
if git submodule status external/$(1) | egrep -q '^[-]|^[+]'; then\
git submodule update --init external/$(1);\
fi
@abel0b
abel0b / build.ps1
Created May 31, 2020 10:35
Use msvc in powershell script - Visual Studio 2019
$vswhere = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe'
$vsfound = Test-Path $vswhere
if (-Not $vsfound) {
Write-Host "vswhere not found in $vswhere"
Exit 1
}
$vspath = & $vswhere -property installationPath
Write-Host "vspath = $vspath"
Push-Location "$vspath\Common7\Tools"
cmd /c "VsDevCmd.bat&set" | Foreach {
@abel0b
abel0b / advisor-commands.sh
Created May 25, 2020 13:12
Intel advisor cli cheat sheet
# Survey
advixe-cl --collect=survey --stacks -- ./foo
# Dependencies
advixe-cl --collect=dependencies --stacks -- ./foo
# Memory access patterns
advixe-cl --collect=map --stacks -- ./foo
# Create snapshot
@abel0b
abel0b / Makefile
Created May 9, 2020 18:36
Makefile C
CC ?= gcc
CFLAGS += -std=c99 -Wall -Wextra -Iinclude
LDLIBS = -lm
.PHONY: all release debug native %test clean%
all: release
release: target/release/foobar
debug: target/debug/foobar
@abel0b
abel0b / bash-cli-starter-template.sh
Created May 3, 2020 20:02
Bash script starter template
#!/bin/bash
verbosity=1
debug=false
function cmd_foo {
echo "foo"
}
function cmd_bar {
@abel0b
abel0b / encrypt-and-decrypt-files-with-gpg.sh
Created May 3, 2020 11:54
Cheatsheet encrypt stuff with gpg
# man gpg
# configuration in ~/.gnupg
# generate gpg keypair with default options
gpg --gen-key
# or use dialog
gpg --full-generate-key
# import a key
@abel0b
abel0b / run-powershell-from-bash.sh
Last active February 17, 2024 04:41
Run a powershell script from WSL Windows Subsystem for linux
powershell.exe "$(wslpath -w .)\myscript.ps1"