Skip to content

Instantly share code, notes, and snippets.

View HamedFathi's full-sized avatar
🌎

Hamed Fathi HamedFathi

🌎
View GitHub Profile
public class Result
{
public bool Success { get; private set; }
public string Error { get; private set; }
public bool Failure
{
get { return !Success; }
}
@HamedFathi
HamedFathi / ExpressionCombiner
Created November 13, 2021 21:44 — forked from janvanderhaegen/ExpressionCombiner
C# code to combine two lambda expressions
//Shoutout to MBoros on stackoverflow
public static class ExpressionCombiner {
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> exp, Expression<Func<T, bool>> newExp)
{
// get the visitor
var visitor = new ParameterUpdateVisitor(newExp.Parameters.First(), exp.Parameters.First());
// replace the parameter in the expression just created
newExp = visitor.Visit(newExp) as Expression<Func<T, bool>>;
// now you can and together the two expressions
using System;
namespace Dummy
{
class Program
{
private static void Header(string title)
{
Console.WriteLine(new string('=', 79));
Console.WriteLine(title);
@HamedFathi
HamedFathi / DynamicPermissionManagementEntities.cs
Created April 1, 2021 22:09 — forked from rabbal/DynamicPermissionManagementEntities.cs
Domain Entities for Dynamic Permissions Management
public abstract class Entity
{
public long Id { get; set; }
[SuppressMessage("ReSharper", "BaseObjectGetHashCodeCallInGetHashCode")]
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
public override int GetHashCode()
{
if (IsTransient())
return base.GetHashCode();
@HamedFathi
HamedFathi / ArrayDeconstructionExtensions.cs
Created June 11, 2020 15:36 — forked from waf/ArrayDeconstructionExtensions.cs
Add deconstruction (i.e. destructuring) syntax support for arrays for C# 7
using System;
using System.Linq;
namespace Extensions
{
/// <summary>
/// Allow the up to the first eight elements of an array to take part in C# 7's destructuring syntax.
/// </summary>
/// <example>
/// (int first, _, int middle, _, int[] rest) = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
/* eslint-disable no-unused-vars */
/* eslint-disable no-else-return */
// JSX constructor, similar to createElement()
export const h = (type, props, ...children) => {
return {
type,
// Props will be an object for components and DOM nodes, but a string for
// text nodes
props,
@HamedFathi
HamedFathi / JSON.cs
Created December 9, 2019 06:06 — forked from yasar11732/JSON.cs
JSON parser and stringifier implemented in C# (Recursive Descent Parser)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace MiniWebFramework
{
public enum JSONValueType
@HamedFathi
HamedFathi / Recursive-descent-backtracking.js
Created December 4, 2019 09:40 — forked from DmitrySoshnikov/Recursive-descent-backtracking.js
Recursive descent parser with simple backtracking
/**
* = Recursive descent parser =
*
* MIT Style License
* By Dmitry Soshnikov <[email protected]>
*
* In this short lecture we'll cover the basic (non-predictive, backtracking)
* recursive descent parsing algorithm.
*
* Recursive descent is an LL parser: scan from left to right, doing
@HamedFathi
HamedFathi / tokenize.js
Created July 10, 2019 08:20 — forked from BonsaiDen/tokenize.js
Small, simple, JS tokenizer in JS.
/**
* Simple JavaScript tokenizer (not a full parser!!!)
*
* Portions taken from Narcissus by Brendan Eich <[email protected]>.
*/
/*jshint evil: true, regexdash: false, regexp: false */
var KEYWORDS = [
'break',
@HamedFathi
HamedFathi / gist:8d2ac1e02ebedc0b7399d84c1534bd50
Created June 6, 2019 08:26 — forked from ebraminio/gist:5292017
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin
// Check Iranian National Code Validity - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، روبی، جاوااسکریپت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین، گرووی
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست http://www.fardanews.com/fa/news/127747
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**