Skip to content

Instantly share code, notes, and snippets.

View geoff-m's full-sized avatar

Geoff McQueen geoff-m

View GitHub Profile
@geoff-m
geoff-m / output.txt
Created April 7, 2023 03:03
Simple demo of Parallel LINQ
Parallel took: 00:00:00.4485898
Sequential took: 00:00:11.0775119
Parallel speedup: 24.69x
@geoff-m
geoff-m / file-mimetype.c
Created April 4, 2023 21:52
Usage of /usr/bin/file to get the MIME type of a file
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
bool getMimeType(const char* filePath, char* output, int maxOutputLength) {
const char* COMMAND_BASE = "/usr/bin/file -b --mime-type ";
// + 1 for null terminator
char* command = calloc(1, strlen(COMMAND_BASE) + strlen(filePath) + 1);
@geoff-m
geoff-m / Main.java
Created December 21, 2020 00:36
Demo application using ForkJoinPool
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
double sequentialTime = 1;
@geoff-m
geoff-m / MonteCarloPi.cs
Created August 24, 2020 18:45
Demonstration of a Monte Carlo method to approximate pi.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace MonteCarloPi
{
class Demo
{
static void Main(string[] args)
@geoff-m
geoff-m / LinkedListIsEven.cs
Created August 6, 2020 20:15
Test whether a number is even using a linked list
class Utility {
class LinkedListNode<T>
{
public T Value;
public LinkedListNode<T> Next;
}
static bool IsEven(int n)
{
// Create a circular linked list with 2 nodes.
var even = new LinkedListNode<bool>() { Value = true };
@geoff-m
geoff-m / PureObjectOrientedWorld.cs
Created July 10, 2020 08:16
Demo of compilation of stupid code
using System;
namespace test
{
class PureObjectOrientedWorld
{
static void Main(string[] args)
{
var p = new PureObjectOrientedWorld();
p.Test(5, 12, 12);
@geoff-m
geoff-m / RockPaperScissors.cs
Last active April 20, 2021 07:58
How to tell who wins in rock paper scissors
enum RockPaperScissorsChoice
{
Rock = 1,
Paper = 2,
Scissors = 4
}
static string DescribeRockPaperScissorsResult(RockPaperScissorsChoice first, RockPaperScissorsChoice second)
{
if (first == second)