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 / EventsInCSharp_FullExample.cs
Created April 30, 2017 19:39
A well explained example on events in C#, the example taken as it is from the book Mastering Visual C#.NET
/*
Example12_4.cs illustrates the use of an event
*/
using System;
// declare the MeltdownEventArgs class (implements EventArgs)
public class MeltdownEventArgs : EventArgs
{
// declare a private field named message
private string message;
// define a constructor
@mshwf
mshwf / SuccessAndFailedCallBackInC#.cs
Last active May 16, 2017 07:05
Implementing SuccessCallBack and FailedCallBack
using System;
using System.Collections.Generic;
namespace TestConsole
{
public class Book
{
public int Id { get; set; }
public string Title { get; set; }
@mshwf
mshwf / feed.atom
Last active December 23, 2017 08:29
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Mobile Essentials Gallery</title>
<id>MobileEssentials</id>
<updated>2015-06-28T12:50:07.4556340+00:00</updated>
<entry>
<id>Xamarin.CocosSharpTemplates</id>
<title>CocosSharpTemplates</title>
<summary>CocosSharp is a C# implementation of the Cocos2D APIs that runs on any platform where MonoGame runs. This will install a collection of CocosSharp Project Templates that allows for the creation of a simple CocosSharp minimal skeleton game solution and project to get developers up and running fast.</summary>
<published>2015-06-28T12:49:12.9106912Z</published>
class MyClass
{
public int RowNo { get; set; }
public int Value { get; set; }
}
public static class LinqEx
{
public static IEnumerable<T> Project<T>(this IEnumerable<T> lst1,
@mshwf
mshwf / OrderBy.cs
Last active April 29, 2018 09:20
OrderBy by property name
public static class NiceLinq
{
public static IEnumerable<T> OrderBy<T>(this IEnumerable<T> notOrderedList, string propertyName)
{
var lambda = GetLambda<T>(propertyName);
var orderedList = notOrderedList.OrderBy(lambda);
return orderedList;
}
private static Func<T, object> GetLambda<T>(string propertyName)
public static IEnumerable<T> InterlockWith<T>(this IEnumerable<T> seq1, IEnumerable<T> seq2)
{
Tuple<T[], int>[] metaSequences = new Tuple<T[], int>[2];
metaSequences[0] = Tuple.Create(seq1.ToArray(), seq1.Count());
metaSequences[1] = Tuple.Create(seq2.ToArray(), seq2.Count());
var orderedMetas = metaSequences.OrderBy(x => x.Item2).ToArray();
for (int i = 0; i < orderedMetas[0].Item2; i++)
{
yield return metaSequences[0].Item1[i];
public static IQueryable<T> SelectExcept<T, TKey>(this IQueryable<T> sequence,
Expression<Func<T, TKey>> excluder) where T : new()
{
List<string> excludedProperties = new List<string>();
if (excluder.Body is MemberExpression memberExpression)
{
excludedProperties.Add(memberExpression.Member.Name);
}
else if (excluder.Body is NewExpression anonymousExpression)
{
@mshwf
mshwf / OptionalType.cs
Created June 20, 2018 20:58
Full optional type implementation
//credits to Zoran Horvat, author of Making Your C# Code More Object-oriented course.
namespace MakingYourCSharpCodeMoreObjectOriented
{
public class Option<T> : IOption<T>
{
private IEnumerable<T> Content { get; }
private Option(IEnumerable<T> content)
{
Content = content;
@mshwf
mshwf / LINQchallenges1.cs
Last active July 19, 2018 07:23
My attempt to solve Lunchtime LINQ Challenge part1 https://www.markheath.net/post/lunchtime-linq-challenge
//challeng 1
string names = "Davis, Clyne, Fonte, Hooiveld, Shaw, Davis, Schneiderlin, Cork, Lallana, Rodriguez, Lambert";
var team = names.Split(',').Select((player, index) => (index + 1) + ". " + player.Trim()).Aggregate((curr, next) => curr + ", " + next);
//challenge 2 (see answer)
string playersData = "Jason Puncheon, 26/06/1986; Jos Hooiveld, 22/04/1983; Kelvin Davis, 29/09/1976; Luke Shaw, 12/07/1995; " +
"Gaston Ramirez, 02/12/1990; Adam Lallana, 10/05/1988";
var players = playersData.Split(';').Select(player => (Name: player.Trim().Substring(0, player.IndexOf(',') - 1), DoB: DateTime.ParseExact(player.Substring(player.IndexOf(',') + 1).Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture))).Select(x => new { x.Name, x.DoB, Age = DateTime.Now.Year - x.Item2.Year }).OrderBy(x => x.Age).ToList();
@mshwf
mshwf / index.html
Last active October 25, 2018 13:58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex">
<link rel="shortcut icon" href="https://www.paytabs.com/images/favicon.png" />
<title>PayTabs - موثوقة و طريقة دفع سهلة</title>