Skip to content

Instantly share code, notes, and snippets.

View mshwf's full-sized avatar
🎯
Focusing

Mohamed El-Shawaf mshwf

🎯
Focusing
View GitHub Profile
public static string ToAgeString(DateTime dob)
{
DateTime today = DateTime.Today;
int months = today.Month - dob.Month;
int years = today.Year - dob.Year;
if (today.Day < dob.Day)
{
months--;
public static string ToAgeString(DateTime dob)
{
DateTime today = DateTime.Today;
int months = today.Month - dob.Month;
int years = today.Year - dob.Year;
if (today.Day < dob.Day)
{
months--;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
//Created by Mshwf, Jan 2019
namespace OudAuction.Controls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public class TextSwitch : Grid
@mshwf
mshwf / boiler_flutter.dart
Last active May 11, 2019 07:48
The auto-generated code in main.dart file by >flutter create
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
@mshwf
mshwf / proxy.cs
Created May 22, 2019 22:12
implementing DynamicProxy in .NET
using ConsoleTest.Repos;
using Goodreads;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Security.Principal;
using System.Text;
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);
@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 });
}
@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 / 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 / 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)
{