Skip to content

Instantly share code, notes, and snippets.

View mortymacs's full-sized avatar

Morteza NourelahiAlamdari mortymacs

View GitHub Profile
[alias]
conflicts = "diff --name-only --diff-filter=U --relative"
del-all = "!f(){ git branch | grep \"$1\" | xargs git branch -D; }; f"
del-local = "!f(){ git branch | grep \"$1\" | xargs git branch -d; }; f"
restore-from-history = "!f(){ git checkout \"$(git rev-list -n 1 HEAD -- $1)\"^ -- \"$1\"; }; f"
show-files = "diff-tree --no-commit-id --name-only -r"
ss = "status --short"
status-lines = "diff --stat"
tree = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'"
who = "git-who"
add_newline = false
format = "$sudo$username$directory$git_branch$git_commit$git_state$nix_shell$status$cmd_duration$python$character"
[character]
error_symbol = "[ ](red)"
success_symbol = "[ ](purple)"
vimcmd_replace_one_symbol = "[ ](orange})"
vimcmd_replace_symbol = "[ ](organge)"
vimcmd_symbol = "[ ](green)"
vimcmd_visual_symbol = "[ ](#c77dff)"
add_newline = false
format = "$sudo$username$directory$git_branch$git_commit$git_state$nix_shell$status$cmd_duration$python$character"
[character]
error_symbol = "[ ](red)"
success_symbol = "[ ](purple)"
vimcmd_replace_one_symbol = "[ ](orange})"
vimcmd_replace_symbol = "[ ](organge)"
vimcmd_symbol = "[ ](green)"
vimcmd_visual_symbol = "[ ](#c77dff)"
@mortymacs
mortymacs / main.cpp
Created September 5, 2025 08:11 — forked from GavinRay97/main.cpp
P2590R2: "Explicit lifetime management" (start_lifetime_as) implementation
// How can we make this program well-defined without sacrificing efficiency? If the destination type
// is a trivially-copyable implicit-lifetime type, this can be accomplished by copying the storage
// elsewhere, using placement new of an array of byte-like type, and copying the storage back to its
// original location, then using std::launder to acquire a pointer to the newly-created object, and
// finally relying on the compiler to optimise away all the copying. However, this would be very
// verbose and hard to get right. For expressivity and optimisability, a combined operation to
// create an object of implicit-lifetime type in-place while preserving the object representation
// may be useful. This is exactly what std::start_lifetime_as is designed to do
template<class T>
@mortymacs
mortymacs / main.py
Last active October 6, 2024 22:11
sample python design pattern
In [5]: from abc import ABC, abstractmethod
...: class Base(ABC):
...: @abstractmethod
...: def get_by_id(self, id):
...: pass
...: class C1(Base):
...: def get_by_id(self, id):
...: return f"hello client1: {id}"
...: class C2(Base):
...: def get_by_id(self, id):
@mortymacs
mortymacs / main.c
Created August 25, 2024 08:12
Sample Unittest in C
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
static void db_connection(void **state)
{
(void) state;
}
@mortymacs
mortymacs / main.c
Created August 25, 2024 08:09
C Pointer playground
#include <stdio.h>
#include <stdlib.h>
int *x()
{
int* a = malloc(sizeof(int));
*a = 19;
return a;
}
@mortymacs
mortymacs / main.c
Created August 25, 2024 08:06
Check file in C
#include <unistd.h>
#include <stdio.h>
int main()
{
if(access("a.sh", F_OK) != -1)
{
printf("Exists!\n");
}
else
@mortymacs
mortymacs / main.c
Created August 25, 2024 08:04
Dictionary by Glib in C
//gcc dict.c `pkg-config --libs --cflags glib-2.0`
#include <glib.h>
#include <stdio.h>
int main()
{
GHashTable* hash = g_hash_table_new(g_str_hash, g_str_equal);
g_hash_table_insert(hash, "name", "Mort");
g_hash_table_insert(hash, "email", "hello@localhost");