Skip to content

Instantly share code, notes, and snippets.

View alifarazz's full-sized avatar
🐉

Ali Farazdaghi alifarazz

🐉
View GitHub Profile
@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 <la@archlinuxcn.org>
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; }
@alifarazz
alifarazz / ref_counted_binary_tree.cc
Created January 19, 2022 17:14
A memory-safe bare-minimum binary tree implementation in c++
#include <functional>
#include <iostream>
#include <memory>
#include <optional>
template <int T>
struct S {
int _[T];
};
@alifarazz
alifarazz / cnorris.nim
Last active May 9, 2021 13:33
Chuck Norris awful joke bot
import telebot, asyncdispatch, logging, options, parsetoml, strformat,
httpclient, json
from strutils import strip, replace
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
addHandler(L)
var proxyURL{.threadvar}: string
#[
The proxy should be an http one. If you have a socks based proxy,
(define list '((1 2) (3 4)))
(car list) ; -> '(1 2)
(car (cdr list)) ; -> '(3 4)
(cadr list) ; -> '(3 4)
(leaf 3) ; leaf-data
(node left_subtree right_subtree) ; node-data
@alifarazz
alifarazz / soa_sort.cc
Last active April 3, 2021 01:59
Sort a struct of arrays using an extra array as indexer (therefore, with one level of indirection)
#include <algorithm>
#include <array>
#include <iostream>
#include <random>
#include <string_view>
const int LEN = 10;
using Indexer = int;
@alifarazz
alifarazz / tictactoe.py
Last active January 20, 2021 07:59
TicTacToe using minmax and alpha-beta pruning
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class Table:
def __init__(self, table=None):
empty = [3 * [" "], 3 * [" "], 3 * [" "]]
self.table = table if table else empty
def __delitem__(self, key) -> None:
self.table.__delattr__(key)