Skip to content

Instantly share code, notes, and snippets.

View mbcrawfo's full-sized avatar

Michael Crawford mbcrawfo

  • Raleigh, NC, USA
View GitHub Profile
@mbcrawfo
mbcrawfo / dotnet-ef.sh
Last active May 18, 2024 17:02
Helper script for the dotnet ef CLI
#!/bin/bash
# This script helps provide project specific options to the dotnet ef cli.
if [ $# -eq 0 ]; then
echo "Usage: ./dotnet-ef.sh <command> [options]"
exit 1
fi
args=(
@mbcrawfo
mbcrawfo / Program.cs
Created August 10, 2022 19:52
MulAdd Benchmarks
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
public class Benchmark
{
private readonly Random _random = new(314159265);
@mbcrawfo
mbcrawfo / Converter.cs
Created April 18, 2022 20:11
Custom JsonConverter for Dynamic Property Types
using System;
using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json;
using Xunit;
namespace TestProject1;
public enum PricingState
{
@mbcrawfo
mbcrawfo / selfmod.c
Last active September 14, 2016 23:01
Self modifying C program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
int main(int argc, char* argv[])
{
int x = 0xabcd0123;
printf("x = %d\n", x);
@mbcrawfo
mbcrawfo / ILogManager.cs
Last active May 10, 2016 14:59
NLog in Xamarin.Forms
public interface ILogManager
{
ILogger GetLogger(Type type);
ILogger GetLogger<T>();
}
@mbcrawfo
mbcrawfo / FileSystemWithLayoutsRazorView.cs
Created December 18, 2015 04:20
Layouts for Postal outside of ASP.Net
// Temporary implementation until this PR is integrated into Postal:
// https://github.com/andrewdavey/postal/pull/117
internal class FileSystemWithLayoutsRazorView
: IView
{
private readonly IRazorEngineService m_razorService;
private readonly string m_cacheName;
/// <summary>
/// Creates a new <see cref="FileSystemRazorView"/> using the
@mbcrawfo
mbcrawfo / infy.c
Last active August 29, 2015 14:16
setpgid race condition
#include <unistd.h>
int main()
{
while (1)
{
sleep(1);
}
}
@mbcrawfo
mbcrawfo / ColorComparator.java
Last active August 29, 2015 14:14
Alek is a lazy bastard
class ColorComparator implements Comparator<Integer> {
private ColorEnumType color;
public ColorComparator(ColorEnumType color) {
this.color = color;
}
@Override
public int compare(Integer a, Integer b) {
int mask = 0xff;
@mbcrawfo
mbcrawfo / BitCount.java
Created January 22, 2015 05:22
Counts the number of "1" bits in a file.
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.text.MessageFormat;
import javax.swing.JFileChooser;