Skip to content

Instantly share code, notes, and snippets.

View zsmahi's full-sized avatar

Zakaria SMAHI zsmahi

  • France
  • 18:23 (UTC +02:00)
  • LinkedIn in/zsmahi
View GitHub Profile
@zsmahi
zsmahi / MayBe.cs
Created April 2, 2024 22:16
MayBeMonad
public readonly struct MayBe<T> : IEquatable<MayBe<T>> where T : class
{
private readonly T _value;
public MayBe(T value)
{
_value = value;
HasValue = !(value is null);
}
@zsmahi
zsmahi / StronglyTypedId.cs
Last active July 16, 2024 08:06
StronglyTypedId generic class + Generic ValueObject class
public abstract class StronglyTypedId<TValue> where TValue : notnull
{
protected StronglyTypedId(TValue value)
{
if (!IsValid(value))
{
throw new ArgumentException($"{value} is not a valid value for this id");
}
Value = value;
@zsmahi
zsmahi / TaskExtensions.cs
Last active July 30, 2023 09:42
Extension method to chain Tasks in the Promise Way Then-Catch
using System;
using System.Threading.Tasks;
namespace Library.CustomExtensions
{
public static class TaskExtensions
{
public static async Task<TOut> Then<TIn, TOut>(
this Task<TIn> task,
Func<TIn, Task<TOut>> continuation,
@zsmahi
zsmahi / Dockerfile
Created July 15, 2023 22:10
Deploying a Jekyll Website Using Docker
# Use an official Ruby runtime as a parent image
FROM ruby:3.2.2-bookworm
# Install Node.js for some js dependencies
RUN apt-get update -qq && apt-get install -y nodejs
# Install Jekyll and Bundler
RUN gem install bundler jekyll
# Set the working directory in the image to /app
@zsmahi
zsmahi / CollectionHelper.cs
Last active July 12, 2023 19:51
In<T> extension method for checking if an item is within a collection
using System;
using System.Linq;
using System.Collections.Generic;
public static class ExtensionMethods
{
public static bool In<T>(this T item, IEqualityComparer<T> comparer, params T[] collection)
{
if (!collection.Any())
{
@zsmahi
zsmahi / praytimes.py
Created September 21, 2012 14:49
a simple python script showing how to calculate praytimes
#!/usr/bin/env python
# compatible with python 2.x and 3.x
import math
import re
'''
--------------------- Copyright Block ----------------------
praytimes.py: Prayer Times Calculator (ver 2.3)
# -*- coding: utf-8 -*-
## Copyright (C) 2009-2012 Assem Chelli <assem.ch [at] gmail.com>
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,