Skip to content

Instantly share code, notes, and snippets.

View ahmedalkabir's full-sized avatar
🏠
Working from home

Ahmed Alkabir ahmedalkabir

🏠
Working from home
View GitHub Profile
@ahmedalkabir
ahmedalkabir / option.go
Created March 13, 2024 06:15
Option Monadic operation implementation
package option
type Option[T any] struct {
value T
isFull bool
}
func Some[T any](value T) Option[T] {
return Option[T]{value: value, isFull: true}
}
#include <Arduino.h>
#include <WiFi.h>
#include <MQTT.h>
#include <ArduinoJson.h>
char tago_buffer[500];
StaticJsonDocument<500> tago_json;
constexpr size_t operator""_str(const char* str, size_t size) noexcept
{
size_t digest = 0;
while (size-- > 0) {
char val = *str;
digest ^= val * val ^ val; // worst hash algorithm
++str;
}
return digest;
}
@ahmedalkabir
ahmedalkabir / vending_machine.cpp
Created January 17, 2019 00:11
vending machine
#include <string>
#include <vector>
#include <iostream>
#include <cctype>
#include <memory>
// كلاس الأصناف
class Product
{
public:
@ahmedalkabir
ahmedalkabir / stack_class.cpp
Created November 10, 2018 22:23
STACK Implementation
#include<iostream>
#include<vector>
using namespace std;
template<typename T, int num>
class Stack{
public:
void push(const T& t){
@ahmedalkabir
ahmedalkabir / 4_element.cpp
Last active November 10, 2018 18:03
remove 4 element
#include<iostream>
#include<array>
using namespace std;
// Stack Container to simplify Stack
// operations
template<typename T,int SIZE>
struct Stack{
@ahmedalkabir
ahmedalkabir / queue.cpp
Last active November 10, 2018 15:45
QUEUE Imlementation
#include<iostream>
using namespace std;
int QUEUE[100], s_of_element, front, back;
void enqueue(void){
int temp;
if(back == s_of_element){
cout << "QUEUE IS FULL" << endl;
@ahmedalkabir
ahmedalkabir / stack.cpp
Last active November 10, 2018 22:19
STACK implemetation
#include<iostream>
using namespace std;
int STACK[100], s_of_element, top;
void push(void){
int temp;
if(top >= s_of_element-1){
cout << "STACK IS FULL" << endl;
@ahmedalkabir
ahmedalkabir / binary.cpp
Last active October 25, 2018 20:54
Simple version of metafunction that converts Binary to Decimal
#include<iostream>
// Improved version of metafunction that convert
// Binary to Decimal
//
template<unsigned long N>
struct B_TO_D{
static unsigned constexpr value = B_TO_D<N/10>::value << 1 | N%10; // prepend higher bits to lowest bit
};