Skip to content

Instantly share code, notes, and snippets.

@2bam
2bam / batlog.gnuplot
Last active July 16, 2023 19:22
Record battery and cpu status to CSV file every minute until stopped (Linux / Bash)
#
# gnuplot script to show energy and cpu by time from batlog.sh
#
# To run:
# gnuplot -persist batlog.gnuplot
#
set datafile separator ","
set xdata time
my_fmt = "%a %b %d %H:%M:%S %Y"
@2bam
2bam / gist:0d51158a865765e3c16ddcdc8b8ca525
Created May 7, 2023 10:02
JS sorting algorithm benchmarks [keeping it in case it's lost]
//
// Thx https://www.measurethat.net/Benchmarks/Show/3549/0/javascript-sorting-algorithms
//
// 1000x random ordered: https://www.measurethat.net/Benchmarks/Show/3549/0/javascript-sorting-algorithms
// 1000x almost ordered: https://www.measurethat.net/Benchmarks/Show/25092/0/javascript-sorting-algorithms-best-case-almost-ordered
//
function swap(ary, a, b) {
var t = ary[a];
ary[a] = ary[b];
@2bam
2bam / gist:dc4ca3ec60c744e72868b58a67b4d423
Created October 10, 2022 18:48
Capture libcamera in OpenCV through GStreamer pipeline for a Raspberry Pi
VideoCapture cap("libcamerasrc ! video/x-raw,width=640,height=480 ! appsink", CAP_GSTREAMER);
@2bam
2bam / setup-git-auth.cs
Last active September 11, 2022 14:46
Setup Git For Windows authentication to run git commands from within C# program
void SetupGitAuthentication()
{
// Set the path so git's ssh executables are called instead of Windows'
Environment.SetEnvironmentVariable("PATH", "C:\\Program Files\\Git\\usr\\bin;" + Environment.GetEnvironmentVariable("PATH"));
// This duplicates what "start-ssh-agent.cmd" does to find the agent PID and socket file,
// in order to set SSH_AGENT_PID, SSH_AUTH_SOCK so git works.
// We heuristically take the first we find, as the script does. This seems to work, as
// possibly the PID is not even necessary.
var tmpPath = Path.GetTempPath();
@2bam
2bam / git-for-windows-ssh-problem-permission-denied-publickey.md
Last active April 4, 2023 21:44
Git For Windows "Permission Denied (publickey)" SSH problem calling `git` from CMD/PowerShell, only accepting id_rsa, asking each time the passphrase.

If you:

  • are using PowerShell or CMD directly
  • don't want to be forced to use id_rsa
  • don't want to input a passphrase on each call to git
  • don't want to use Git Bash because you want to use it from CMD/PowerShell directly you need some troubleshooting to use git installation executables and a prior setup:

1. Start or get currently running agent into env vars (PID and socket/pipe file)

start-ssh-agent.cmd

@2bam
2bam / CInteropProxy.cs
Last active March 31, 2022 01:25
Acceptable way to pin/fix structs for C#-C interop including swap chain arrays by using-Dispose pattern without GetPinnableReference because that's garbage.
internal class CInteropProxy {
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
unsafe delegate int C_stepDelegate(World.Pinned* world);
C_stepDelegate? c_step; // Set with kernel32.dll GetProcAddress()
public void Step(in World world)
{
unsafe
{