Skip to content

Instantly share code, notes, and snippets.

@brianmed
brianmed / args.d
Last active March 27, 2022 16:02
dTrace macOS Montery Script that prints commands with arguments
#!/usr/sbin/dtrace -C -s
#pragma D option quiet
// https://gist.github.com/viroos/1242279
// $ sudo dtrace -C -s ./args.d
proc:::exec-success
{
@brianmed
brianmed / Program.cs
Created December 22, 2021 18:47
SQLite Example in C# that Creates Rows with NewId and Random Data via DbContext
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata;
using MassTransit;
@brianmed
brianmed / ILGpuGrayscale.csproj
Last active January 12, 2022 18:38
Convert RGBA32 image to Grayscale via ILGPU in C#
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ILGPU" Version="0.10.1" />
</ItemGroup>
@brianmed
brianmed / dotnet-remoteRun
Last active September 5, 2021 02:54
ASP.Net MVC Core 5 Remote Run with Local File Editing
#!/bin/bash
# PATH=$PATH:. DOTNET_WATCH_SUPPRESS_MSBUILD_INCREMENTALISM=1 DOTNET_WATCH_SUPPRESS_LAUNCH_BROWSER=1 DOTNET_WATCH_SUPPRESS_BROWSER_REFRESH=1 DOTNET_USE_POLLING_FILE_WATCHER=1 dotnet watch --verbose remoteRun
set -e
# Because the text goes crazy when the watcher detects a change
stty sane
# publish so we get wwwroot
@brianmed
brianmed / ipRange.sh
Last active August 15, 2021 05:33
Hopefully Computes if Two IP Addresses are "In Range"
#! /bin/bash
IFS=. read LeftOctetA LeftOctetB LeftOctetC LeftOctetD <<EOF
192.168.4.5
EOF
IFS=. read RightOctetA RightOctetB RightOctetC RightOctetD <<EOF
192.168.4.8
EOF
@brianmed
brianmed / Program.cs
Last active August 14, 2021 01:01
Fun code in C# 10 (top level program) that coalesces booleans
if (Coalesce(true, false) is true) {
Console.WriteLine("Yay!");
}
if (Coalesce(true, true) is true) {
Console.WriteLine("Worked");
}
static bool Coalesce(params bool[] truth)
{
@brianmed
brianmed / Joy.csproj
Last active December 18, 2021 02:32
Posix Signals in .Net 6!!
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
@brianmed
brianmed / Startup.cs
Last active July 31, 2021 02:23
Some Core stuff
services.AddCors(options =>
{
options.AddPolicy(
"default",
policy =>
{
// I'm guessing
policy.WithOrigins("http://10.0.0.5:5000")
.AllowAnyHeader()
.AllowCredentials()
@brianmed
brianmed / gist:378a3ed1928048105bd5746abdd157c8
Created July 25, 2021 15:49
CreateTempFileWithExtension C# .Net
public string CreateTempFileWithExtension(string extension)
{
string file = string.Empty;
do
{
file = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid().ToString()}.{extension}");
} while (File.Exists(file));
return file;
@brianmed
brianmed / Program.cs
Created July 14, 2021 00:55
tcgetattr Marshalling fun for .Net 5
using System;
using System.Runtime.InteropServices;
namespace SysRplSerialPort
{
[StructLayout(LayoutKind.Explicit)]
public struct TermiosStruct
{
[MarshalAs(UnmanagedType.U4), FieldOffset(0)]
public uint c_iflag;