Skip to content

Instantly share code, notes, and snippets.

View farhangamary's full-sized avatar
🎯
Focusing

Farhang Amary farhangamary

🎯
Focusing
View GitHub Profile
@farhangamary
farhangamary / logging_aop_sample.py
Created November 26, 2024 03:33
The simplicity of AOP in python!
class Aspect:
def before(self, func, *args, **kwargs):
pass
def after(self, result, func, *args, **kwargs):
return result
def except_raised(self, func, excpt, *args, **kwargs):
pass
@farhangamary
farhangamary / funptr.cpp
Created November 23, 2024 13:16
Interesting kind of declarations for function pointers for example: int (*(*a[])(int))(string)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef int (*custom_ln)(string);
typedef custom_ln (*ln_mapper)(int);
int cnt_0(string str)
@farhangamary
farhangamary / functnl.cpp
Last active March 27, 2024 16:41
A sample of meta and a sample of functional programming in c++
#include <iostream>
#include <vector>
#include <ranges>
#include <algorithm>
using namespace std;
int mod_by_six(int val);
int main()
{
@farhangamary
farhangamary / mv_cp.cpp
Created March 10, 2024 23:27
An easy to understand sample of C++ move semanitcs, rvalue, lvalue, move, forward, copy and move constructors
#include <iostream>
#include <string.h>
class SampleStr
{
char *str_data;
int length;
public:
SampleStr(const char *data = "") : length(0), str_data(nullptr)
@farhangamary
farhangamary / CMakeLists.txt
Last active March 1, 2024 01:36
A shared resource which can get read and written alternately among multiple threads
cmake_minimum_required(VERSION 3.18)
project(multith
VERSION 0.1
DESCRIPTION "A sample of a shared resource")
set(CMAKE_CXX_STANDARD 17)
add_executable(multith starter.cpp)
@farhangamary
farhangamary / Instruction
Last active February 25, 2024 19:37
A simple Kernel module in C - It reads the remaining Battery charge and logs it :)
#
#Instructions on how to make, load, check and unload.
#
#
############## check prerequisites ##########################
$ uname -r
6.5.0-18-generic
$ gcc --version
@farhangamary
farhangamary / main.cpp
Created January 24, 2024 17:15
C++ 20 coroutines explained in comments
//
// Created by farhang on 21.01.24.
//
#include <iostream>
#include <coroutine>
#include <exception>
#include <cstdlib>