Skip to content

Instantly share code, notes, and snippets.

View mshwf's full-sized avatar
🎯
Focusing

Mohamed El-Shawaf mshwf

🎯
Focusing
View GitHub Profile
@mshwf
mshwf / MyConsoleHosted.csproj
Last active March 9, 2022 09:43
Minimum code required to setup NLog in a console app (.NET 5) and Hosting a windows service
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
//Shared code
public class ResponsiveLabel : Label
{
public double MinSize
{
get => (double)GetValue(MinSizeProperty);
set => SetValue(MinSizeProperty, value);
}
public static readonly BindableProperty MinSizeProperty =
@mshwf
mshwf / GeoHelper.cs
Last active February 5, 2020 11:24
Create box around geo-coordinate given its position and distance (in Km)
public static class GeoHelper
{
private const double r_earth = 6371;
private const double pi = Math.PI;
private static double RadiansToDegrees(double rads) => rads * 180.0 / pi;
private static double ToRadian(double degrees) => degrees * pi / 180.0;
public static (Position topRight, Position btmRight, Position btmLeft, Position topLeft) GetBoundingBox(Position position, double distance) =>
GetBoundingBox(position.Lat, position.Long, distance);
public static (Position topRight, Position btmRight, Position btmLeft, Position topLeft) GetBoundingBox(double centerLat, double centerLong, double distance)
@mshwf
mshwf / GesturesBehavior.cs
Last active December 4, 2019 11:50
Reusable behavior to simplify adding tap gesture recognizer to Xamarin.Forms Views
public static class GesturesBehavior
{
public static readonly BindableProperty TapCommandProperty =
BindableProperty.CreateAttached("TapCommand", typeof(ICommand), typeof(GesturesBehavior), null, propertyChanged: OnTapCommandChanged);
public static ICommand GetTapCommand(BindableObject view)
=> (ICommand)view.GetValue(TapCommandProperty);
public static void SetTapCommand(BindableObject view, ICommand value)
@mshwf
mshwf / removeGUIDsFromFileNames.cs
Last active November 23, 2019 21:45
Removing GUIDs from file names downloaded using youtube-dl tool
//Some files downloaded from Pluralsight using youtube-dl tool have GUIDs appended to their names,
//e.g.: Course Overview-13acb659-b860-4dac-b284-64fc18a2ece1.mp4, this C# function removes them
static void Main()
{
RemoveGuidsFromFilesIn(@"D:\C#\CourseFolder");
}
private static void RemoveGuidsFromFilesIn(string path)
{
@mshwf
mshwf / BaseViewModel.cs
Created November 14, 2019 21:23
boilerplate code for base view model for MVVM
public class BaseViewModel : INotifyPropertyChanged
{
public INavigation Navigation { get; set; }
bool isBusy = false;
public bool IsBusy
{
get { return isBusy; }
set { SetProperty(ref isBusy, value); }
}
@mshwf
mshwf / SLinkedList.cs
Last active September 8, 2019 13:45
Singly linked list implementation in C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace ExtendedCollection
{
[DebuggerDisplay("{Value}")]
public class SNode<T>
{
@mshwf
mshwf / occurrences.cs
Created June 23, 2019 21:36
finds occurrences of a sub-string in a string
List<Kmer> kmers = new List<Kmer>();
string message = "gjhcebfu71uevkkvhjv,yjvykku71jrbirbgerngtgntteu71agg6g79htu718eay8hibioay+8eru71ohob8vy89egyhoih89vu71oyhbigr89yhrrvoaeoghau71e8ryg98ergh.oaeryl9g7rv7g7iytg643483gi@$#t32@#2R23r213ri4tyg2ti.88oichu71tp9hg";
for (int i = 0; i <= message.Length - 3; i++)
{
string substring = message.Substring(i, 3);
int occurences = Regex.Matches(message, Regex.Escape(substring)).Count;
kmers.Add(new Kmer { Text = substring, Occ = occurences });
}
class Program
{
static void Main(string[] args)
{
var img = Image.FromFile(@"C:\Users\Mohamed.Elshawaf\Desktop\imageTests\original.png");
var ratio = .75;
var height = img.Height;
var width = img.Width;
int newHeight = (int)(height * ratio);
int newWidth = (int)(width * ratio);