Skip to content

Instantly share code, notes, and snippets.

View fiddyschmitt's full-sized avatar

Fidel Perez-Smith fiddyschmitt

  • Brisbane, Australia
View GitHub Profile
ffmpeg.exe -t 10 -f gdigrab -framerate 30 -offset_x 1750 -offset_y 990 -video_size 148x90 -show_region 1 -i desktop -c:v h264 -qp 0 output.mkv
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Automation;
namespace libUIHelper
{
public static string RemoveNonPrintable(this string input)
{
var result = Regex.Replace(input, @"\p{C}+", string.Empty);
return result;
}
public static IEnumerable<T> Recurse<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> childSelector, bool depthFirst = false)
{
List<T> queue = new List<T>(source); ;
while (queue.Count > 0)
{
var item = queue[0];
queue.RemoveAt(0);
var children = childSelector(item);
public static T? DeserializJson<T>(this string json) where T : class
{
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
var result = JsonConvert.DeserializeObject<T>(json, settings);
return result;
}
public static string SerializeToJson(this object obj)
{
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
var dObj = (dynamic)obj;
var filter = CreateFilterDelegate<object>(@"dObj.Name.StartsWith(""P"") && dObj.HeightCm >= 180");
var matchesFilter = filter(new Globals(dObj));
Console.WriteLine($"{dObj.Name}: {matchesFilter.Result}");
var proj = CreateSelectDelegate<object>(@"new {dObj.Name.ToUpper(), HeightMm = dObj.HeightCm * 1000}");
var transformed = proj(new Globals(proj));
Console.WriteLine($"{transformed.Result}");
public static string GetProgramOutput(string exe, string args)
{
Process process = new Process();
process.StartInfo.FileName = exe;
process.StartInfo.Arguments = args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
Function GetProgramOutput([string]$exe, [string]$arguments)
{
$process = New-Object -TypeName System.Diagnostics.Process
$process.StartInfo.FileName = $exe
$process.StartInfo.Arguments = $arguments
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.RedirectStandardOutput = $true
$process.StartInfo.RedirectStandardError = $true
$process.Start()
I used (converted from Python):
public static (int X, int Y) Deg2Tile(double latDeg, double lonDeg, int zoom)
{
var latRad = (latDeg * Math.PI) / 180;
var n = Math.Pow(2.0, zoom);
var xtile = (int)((lonDeg + 180.0) / 360.0 * n);
var ytile = (int)((1.0 - Math.Log(Math.Tan(latRad) + (1 / Math.Cos(latRad))) / Math.PI) / 2.0 * n);
return (xtile, ytile);
}
@fiddyschmitt
fiddyschmitt / MultiProducerMultiConsumer.cs
Last active June 28, 2023 14:31
Multiple producers, multiple consumers
//DON'T USE THESE. It spins the CPU when calling TryTake()
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;