Skip to content

Instantly share code, notes, and snippets.

@FrankKerrigan
FrankKerrigan / Program.cs
Last active March 7, 2020 12:04
Task error handling C#
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Yield
{
class Program
{
//This is not real code only an example
static void Main(string[] args)
using System;
using System.Collections.Generic;
namespace Yield
{
class Program
{
//This is not real code only an example
static void Main(string[] args)
{
@FrankKerrigan
FrankKerrigan / simpleyeild.cs
Created March 5, 2020 22:54
C# Simple Yeild
using System;
using System.Collections.Generic;
namespace Yield
{
class Program
{
static void Main(string[] args)
{
foreach (var number in GetNumbers())
@FrankKerrigan
FrankKerrigan / fizzbuzz.cs
Created March 5, 2020 22:18
FizzBuzz using Yield, Func and IEnumerable
class Program
{
static void Main(string[] args)
{
foreach (var i in FizzBuzz(100))
{
Console.WriteLine(i);
}
}
@FrankKerrigan
FrankKerrigan / BinarySearch.cs
Last active February 9, 2019 23:25
C# Binary Search Recursive call
static void GetBinarySearchRecursive()
{
var list = new[] { 2, 3, 4, 5, 6, 7, 8, 9, 11, 23, 44, 66, 77, 88, 99, 101, 102, 104, 170, 344, 445, 565, 673, 733, 874, 912, 1001, 1120 };
int searchTerm = 102;
int start = 0;
int end = list.Length;
var RecordNo = BinarySearchRecursive(ref list, start, end, searchTerm);
if (RecordNo == -1)
@FrankKerrigan
FrankKerrigan / BinarySearch.cs
Last active February 9, 2019 23:26
C# Binary Search non-recursive
static void BinarySearch()
{
// sort array
var list = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 23, 44, 66, 77, 88, 99, 101, 102, 104, 170, 344, 445, 565, 673, 733, 874, 912, 1001, 1120 };
var searchTerm = 9999;
int result = -1; //assume is all postive numbers
var start = 0;
var end = list.Length;
int RecordPosition = -1;
@FrankKerrigan
FrankKerrigan / ListUnion.cs
Created February 9, 2019 20:44
C# Manual List Union; finds items in both lists and display distinct list
static void Union()
{
int[] first = new[] { 1, 2, 3, 4, 6, 7, 7, 8, 8, 75, 4, 4, 3, 3, 3, 3, 4, 56, 6, 7, 7, 6, 4, 3, 2, 35, 56, 56, 56, 5, 77 };
int[] second = new[] { 1, 3, 5 };
List<int> InBoth = new List<int>();
for(var i = 0; i< first.Length; i++)
{
for(var v =0; v<second.Length; v++)
{
@FrankKerrigan
FrankKerrigan / distinct.cs
Created February 9, 2019 20:40
C# Distinct on array
// Manual Distinct using C#
// Used List<int> to make it easier to read
static void Distinct()
{
int[] allList = new[] { 1, 2, 3, 4, 6, 7, 7, 8, 8, 75, 4, 4, 3, 3, 3, 3, 4, 56, 6, 7, 7, 6, 4, 3, 2, 35, 56, 56, 56, 5, 77 };
List<int> distinct = new List<int>();
foreach(var i in allList)
@FrankKerrigan
FrankKerrigan / install_NNYwin10linux.sh
Last active October 25, 2018 20:32
Shebang Issues and running Node NPM YARN for FESK on Windowa 10 Linux Sub System
#!/bin/sh
# this script installs various stuff to help run YARN stuff on windows 10
# Developed as could not run "yarn add @fesk/scripts --dev" due to issues with shebangs #!
# First install Windows subsystem on Windows 10
# Install Ubuntu 18.X
# Need Root privs to run this.
# sudo -i