Skip to content

Instantly share code, notes, and snippets.

View zHaytam's full-sized avatar
🎯
Focusing

Haytam Zanid zHaytam

🎯
Focusing
View GitHub Profile
@zHaytam
zHaytam / bootstrap4_dropdown_on_hover.js
Created April 22, 2018 16:37
Bootstrap 4 dropdown-on-hover test
// Bootstrap 4 dropdowns on hover
$('body').on('mouseenter', '.dropdown-on-hover', function (e) {
_d = $(e.target).closest('.dropdown>a');
_d.dropdown('toggle');
});
$('body').on('mouseleave', '.dropdown-on-hover', function (e) {
var _d = $(e.target).prev('a');
console.log(_d);
_d.dropdown('toggle');
});
@zHaytam
zHaytam / Socks5.cs
Last active April 30, 2024 06:05
A Socks5 implementation in .NET Core (C# 8)
using System;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Socks
{
public static class Socks5
@zHaytam
zHaytam / DataFrameUtils.cs
Created December 19, 2019 14:29
Some utility functions for the Microsoft.Data.Analysis.DataFrame class
public static class DataFrameUtils
{
public static void PrettyPrint(this DataFrame df)
{
var sb = new StringBuilder();
int width = GetLongestValueLength(df) + 4;
for (int i = 0; i < df.Columns.Count; i++)
{
@zHaytam
zHaytam / TryingOutDataFrame.cs
Created December 19, 2019 14:46
Trying out DataFrame
using System;
using Microsoft.Data.Analysis;
namespace TryingOutDataFrame
{
class Program
{
static void Main(string[] args)
{
@zHaytam
zHaytam / covidmarocscraper.js
Created March 29, 2020 21:35
A simple scraper for covidmaroc.ma
const axios = require("axios");
const cheerio = require('cheerio');
const covidmarocUrl = 'http://www.covidmaroc.ma/Pages/AccueilAR.aspx';
const chromeUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36';
const moroccoPopulation = 36.79;
function cleanText(text) {
return text.replace(/\u200B/g, '').trim();
}
var propertyGetter = DynamicExpressions.GetPropertyGetter<Product>(propertySentByUser);
// ^ can be cached or even compiled to a Func<Product, object>
var query = _dbContext.Products.AsQueryable().OrderBy(propertyGetter);
// Or OrderByDesceding
public IQueryable<Product> ApplyOrderBy(IQueryable<Product> query, string property)
{
switch (property)
{
case "Name":
return query.OrderBy(p => p.Name);
case "Quantity":
return query.OrderBy(p => p.Quantity);
case "Price":
return query.OrderBy(p => p.Price);
var query = _dbContext.Products.AsQueryable();
query = ApplyOrderBy(query, propertySentByUser);
public IQueryable<Product> ApplyFilter(IQueryable<Product> query, string property, object value)
{
switch (property)
{
case "Name":
return query.Where(p => p.Name.Contains(value.ToString()));
case "Quantity":
return query.Where(p => p.Quantity >= value);
case "Price":
return query.Where(p => p.Price >= value);
var predicate = DynamicExpressions.GetPredicate<Product>(propertySentByUser, operatorSentByUser, valueSentByUser);
// ^ can also be cached or compiled and used anywhere
var products = _dbContext.Products.AsQueryable().Where(predicate).ToList();
// ^ or FirstByDefault, Any, etc...