Skip to content

Instantly share code, notes, and snippets.

View peterthorsteinson's full-sized avatar

Peter Thorsteinson peterthorsteinson

View GitHub Profile
// Starting and Stopping midi playback on multiple threads
using System;
using System.Threading;
using Melanchall.DryWetMidi.Devices;
using Melanchall.DryWetMidi.Smf;
class Program
{
public static Playback playback;
static void Main()
{
using System;
using System.Collections.Generic;
using System.Timers;
class Program
{
static List<Bot> bots = new List<Bot>();
static void Main()
{
Console.CursorVisible = false;
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
list.Add(new Tuple<string, string>("fruit", "apple"));
list.Add(new Tuple<string, string>("fruit", "peach"));
list.Add(new Tuple<string, string>("vegetable", "carrot"));
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
{
var nums = GetArrayOfFirstTenIntegers();
foreach (int n in nums)
{
using System;
class Program
{
static void Main()
{
int num = 10;
Console.WriteLine(AddUpToLoop(num));
Console.WriteLine(AddUpToRecursive(num, 0));
Func<int, int, int> AddUpToLambda = null;
AddUpToLambda = (num, sum) => { return num == 0 ? sum : AddUpToLambda(--num, sum + num + 1); };
using System;
class Program
{
static void Main()
{
for (int i = 0; i < 20; i++)
{
object value = GetValueFromSomewhere();
switch (value)
{
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Pig Dice");
Game game = new Game();
game.Play();
}
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Thread[] threadArray = new Thread[8];
(threadArray[0] = new Thread(ThreadFunc)).Start(ConsoleColor.Red);
(threadArray[0] = new Thread(ThreadFunc)).Start(ConsoleColor.Yellow);
(threadArray[0] = new Thread(ThreadFunc)).Start(ConsoleColor.Magenta);
Here are two programs (client and server) that talk via tcp/ip over a socket connection.
1. Run the server side program first and note the ip address of the machine that it is running on.
2. Then run the client and enter the ip address of the server.
3. Finally enter a message and hit enter. The message is sent to the server, reversed, and then sent back to the client.
///////////////////
// TCP Client
using System;
using System.Net.Sockets;
// Output:
// First 10 fibonacci numbers:
// 0 1 1 2 3 5 8 13 21 34
class First10FibonacciNumbers
{
static void Main()
{
int previous = 0;
int current = 1;