Skip to content

Instantly share code, notes, and snippets.

View zHaytam's full-sized avatar
🎯
Focusing

Haytam Zanid zHaytam

🎯
Focusing
View GitHub Profile
var predicate = new DynamicFilterBuilder<Product>()
.And("Enabled", FilterOperator.Equals, true)
.And(b => b.And("Brand", FilterOperator.Equals, "Nike").Or("Brand", FilterOperator.Equals, "Adidas"))
.And(b => b.And("Price", FilterOperator.GreaterThanOrEqual, 20).And("Price", FilterOperator.LessThanOrEqual, 100))
.Build();
var products = _dbContext.Products.AsQueryable().Where(predicate).ToList();
public static Expression<Func<TEntity, object>> GetPropertyGetter<TEntity>(string property)
{
if (property == null)
throw new ArgumentNullException(nameof(property));
var param = Expression.Parameter(typeof(TEntity));
var prop = param.GetNestedProperty(property);
var convertedProp = Expression.Convert(prop, typeof(object));
return Expression.Lambda<Func<TEntity, object>>(convertedProp, param);
}
@zHaytam
zHaytam / remove_duplicate_files.py
Created May 18, 2020 16:32
Deletes duplicated files (e.g. Image (1).png)
from os import walk, path, remove
import sys
import re
pattern = re.compile(".+ \(\d+\)\..+")
# Taken from http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/
def get_human_readable_size(size, precision=2):
suffixes = ['B', 'KB', 'MB', 'GB', 'TB']
@zHaytam
zHaytam / 404.html
Created June 8, 2020 15:28
spa-github-pages's 404.html file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Single Page Apps for GitHub Pages</title>
<script type="text/javascript">
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
// ----------------------------------------------------------------------
@zHaytam
zHaytam / spa-index-script.js
Created June 8, 2020 16:15
spa-github-pages's script in index.html file
<!-- Start Single Page Apps for GitHub Pages -->
<script type="text/javascript">
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
// ----------------------------------------------------------------------
// This script checks to see if a redirect is present in the query string
// and converts it back into the correct url and adds it to the
// browser's history using window.history.replaceState(...),
// which won't cause the browser to attempt to load the new url.
@zHaytam
zHaytam / action.yml
Last active June 8, 2020 18:44
Blazor Wasm GitHu bctions workflow
name: DeployToGitHubPages
env:
PUBLISH_DIR: bin/Release/netstandard2.1/publish/wwwroot
# Include subfolders if needed
on:
push:
branches: [ master ]
jobs:
@zHaytam
zHaytam / git-empty-branch.sh
Created June 8, 2020 18:58
Create an empty branch in Git
# Taken from https://stackoverflow.com/questions/34100048/github-create-empty-branch
git checkout --orphan gh-pages
git rm -rf .
git commit --allow-empty -m "root commit"
git push origin gh-pages
public class Rectangle
{
public double Width { get; init; }
public double Height { get; init; }
public Rectangle()
{
// Of course you can still initialize the values in a constructor
Width = 10;
Height = 5;
public class Rectangle : IEquatable<Rectangle>
{
[CompilerGenerated]
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double <Width>k__BackingField;
[CompilerGenerated]
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double <Height>k__BackingField;
// Defining a record like this
public record Rectangle1 { double Width; double Height; }
// Is equivalent to this
public record Rectangle1
{
public double Width { get; init; }
public double Height { get; init; }
}