Skip to content

Instantly share code, notes, and snippets.

View alifarazz's full-sized avatar
🐉

Ali alifarazz

🐉
View GitHub Profile
@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)
##
# Div by 10 in x64
#
# @file
# @version 0.1
.PHONY: default all run clean
default: a
all: default
@alifarazz
alifarazz / smallest_pair.py
Last active June 3, 2020 18:05
Get minimum Euclidean distance between points in an XY plane using O(n.lgn).
from scipy import spatial
import numpy as np
pos = np.c_[np.random.rand(100), np.random.rand(100)]
tree = spatial.cKDTree(pos)
dist, ids = tree.query(pos, 2)
print(f'min dist: {np.min(dist[:, 1]): 8f}')