Skip to content

Instantly share code, notes, and snippets.

View alifarazz's full-sized avatar
🐉

Ali Farazdaghi alifarazz

🐉
View GitHub Profile
@alifarazz
alifarazz / tmux.conf
Last active March 31, 2025 16:55
Personal tmux config
# in $HOME/.config/tmux/tmux.conf
# set-option -g default-shell "path to fish"
# I copied most of this off someone's blog.
# # remap prefix from 'C-b' to 'C-a'
# unbind C-b
# set-option -g prefix C-a
# bind-key C-a send-prefix
# split panes using | and -
@alifarazz
alifarazz / sync-with-remote.bash
Last active December 22, 2024 05:25
Basic script to sync a local project with a remote server
#!/usr/bin/env bash
set -euEo pipefail
set -x # show every command being executed
##### Constants
remote_path_prefix="nesaean:/project/ali" # Remote ssh server is set in my ~/.ssh/config
watcher_match_regex=".*\.(cu|cc|hh|bash|md|c|h|inc)" # Only watch for file paths matching regex
##### Process argv
@alifarazz
alifarazz / cpu_burn.cc
Last active October 6, 2024 23:02
Stress test CPU with int ops + ld + st
// g++ -std=c++20 cpu_burn.cc -o cpu_burn
#include <bits/stdc++.h>
constexpr size_t maxn = 192;
constexpr int iter = 1024 * 1024;
std::array<std::jthread, maxn> threads;
std::array<unsigned int, (1024ull * 1024 * 512)> data;
#define _GNU_SOURCE
#include <linux/prctl.h> /* Definition of PR_* constants */
#include <sys/prctl.h>
#include <sys/syscall.h> /* for __NR_write */
#include <ucontext.h> /* REG_RBP, REG_RSP */
#include <unistd.h> /* for write(2) */
#include <assert.h>
@alifarazz
alifarazz / umwait.cc
Last active July 30, 2024 03:47
An example for Intel umonitor umwait tpause instructions introduced in Tremont, Alder Lake, Sapphire Rapids architectures
// g++ -O3 -Wall -Wextra -Wconversion -Wshadow -Wpedantic -std=c++20 -march=alderlake umwait.cc -o umwait.elf
// ./umwait.elf or ./umwait.elf w
#include <atomic>
#include <iostream>
#include <latch>
#include <thread>
#include <immintrin.h>
#include <x86intrin.h>
@alifarazz
alifarazz / example1.cc
Last active July 16, 2024 21:47
Strict Aliasing and restrict key word examples
#include <cstdio>
int f(int *ap, float *bp) {
*ap = 1;
*bp = 2.0f;
return *ap;
}
int main() {
int a = 0; float b = 0.0f;
@alifarazz
alifarazz / variable_dump.md
Last active May 20, 2024 19:53
CMake variable dump

CMake All Variable Dump

Put this wherever you'd want to dump the variables from.

message("=============BEGIN VARIABLE DUMP ========================")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
    message("${_variableName}=${${_variableName}}")
endforeach()
message("=============END VARIABLE DUMP ==========================")
@alifarazz
alifarazz / .gitconfig
Last active July 24, 2023 12:44
Yeah, it's a gitconfig file, nothing interesting
[alias]
kosdast = git add .
co = checkout
br = branch
pu = push --tags
puff = push --force-with-lease
st = status --branch
ci = commit
ca = commit --amend
can = commit --amend --no-edit
@alifarazz
alifarazz / PKGBUILD
Created February 2, 2023 13:06
ccls-git PKGBUILD, uses LTO and other compiler optimizations
## Obtained from: https://aur.archlinux.org/packages/ccls-git
# Maintainer: Fangrui Song <i at maskray.me>
# Co-Maintainer: Shengyu Zhang <[email protected]>
pkgname=ccls-git
_pkgname=ccls
pkgver=20230115
pkgrel=1
pkgdesc='C/C++ language server supporting cross references, hierarchies, completion and semantic highlighting'
@alifarazz
alifarazz / object_slicing_test.cc
Last active January 19, 2022 17:50
Exploration of "object slicing" in c++ classes
#include <iostream>
#include <vector>
#include <memory>
using namespace std::literals;
class Base
{
public:
virtual auto who() const -> std::string { return "Base"s; }