Skip to content

Instantly share code, notes, and snippets.

@brianmed
brianmed / joy.c
Created June 2, 2023 10:33
Decode H264 Frame with FFmpeg
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
void my_log_callback(void *ptr, int level, const char *fmt, va_list vargs)
@brianmed
brianmed / Program.cs
Created May 24, 2023 00:44
C# macOS getrlimit example via DllImport
using System.Runtime.InteropServices;
namespace getrlimit;
class Program
{
[DllImport("libc", CallingConvention = CallingConvention.Cdecl)]
public static extern int getrlimit(int resource, IntPtr rlp);
[StructLayout(LayoutKind.Sequential)]
@brianmed
brianmed / launch.json
Created April 6, 2023 00:24
Visual Studio Code Remote Debugging Example
{
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"program": "app.dll",
"args": ["--urls=http://*:8000"],
"cwd": "/home/bpm/appDirectory",
"stopAtEntry": false,
@brianmed
brianmed / Program.cs
Last active February 11, 2023 20:22
C# Repeat Slow Task
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace JoyRepeateTask;
public class Program
{
@brianmed
brianmed / FFmpegProbePackets
Created December 18, 2022 02:39
Small Program that Outputs Number of Streams in a Container via FFmpeg
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
@brianmed
brianmed / MultipleSockets.cs
Last active December 2, 2022 04:54
Separate sending and receiving sockets.. hopefully
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<_EnableMacOSCodeSign>false</_EnableMacOSCodeSign>
</PropertyGroup>
@brianmed
brianmed / build-ios.sh
Last active September 4, 2022 00:44
Build and deploy an iOS app for testing with .Net Maui
# Either the OS will delete or manually delete later
export FORDELETE="forDelete-$(date '+%FT%T')" && (test -d bin || test -d obj) && sh -c 'mkdir "$FORDELETE" && echo "$FORDELETE"' && ((test -d bin && mv -i bin "$FORDELETE") ; (test -d obj && mv -i obj "$FORDELETE")) && mv -i "$FORDELETE" /tmp
dotnet clean -f net6.0-ios && dotnet publish -f net6.0-ios -p:BuildType=Device && ideviceinstaller -u 00000000-00000000000000 -i bin/Debug/net6.0-ios/publish/TheApp.ipa
tput -T$TERM init
...
# This is also helpful
@brianmed
brianmed / Program.cs
Created August 5, 2022 12:17
ZXing QRcode with ImageSharp and without System.Drawing
using System;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using ZXing;
using ZXing.Common;
/*
<ItemGroup>
@brianmed
brianmed / hls.html
Created April 21, 2022 12:03
Example HLS Viewer with hls.js
<html>
<head>
<title>Hls.js demo - basic usage</title>
</head>
<body>
<!-- https://github.com/video-dev/hls.js/releases -->
<script src="dist/hls.js"></script>
<center>
@brianmed
brianmed / EmailQueueHostedService.cs
Created April 16, 2022 02:14
Example BackgroundService with C# ASP.Net Core
using Microsoft.EntityFrameworkCore;
namespace Joy.HostedServices;
public class EmailQueueHostedService : BackgroundService
{
private IServiceScopeFactory ScopeFactory { get; init; }
public EmailQueueHostedService(IServiceScopeFactory scopeFactory)
{