Skip to content

Instantly share code, notes, and snippets.


Leon Bambrick secretGeek

View GitHub Profile
secretGeek / FileStashy.cs
Created Nov 13, 2020
FileStashy (and IStashy)
View FileStashy.cs
// This is an implementation of "IStashy" that saves/loads your objects as Json, in files, in a subfolder named after the type of the Object.
public class FileStashy : IStashy<string>
private readonly IHostingEnvironment _hostingEnvironment;
public FileStashy(IHostingEnvironment hostingEnvironment)
_hostingEnvironment = hostingEnvironment;
secretGeek / get-meetings.ps1
Last active Aug 18, 2021
Get today's schedule from Outlook, using COM, and format as text for my TODO.txt file
View get-meetings.ps1
# Get a list of meetings occurring today.
function get-meetings() {
$olFolderCalendar = 9
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace('MAPI')
$Start = (Get-Date).ToShortDateString()
$End = (Get-Date).ToShortDateString()
$Filter = "[MessageClass]='IPM.Appointment' AND [Start] > '$Start' AND [End] < '$End'"
$appointments = $ns.GetDefaultFolder($olFolderCalendar).Items
$appointments.IncludeRecurrences = $true
secretGeek / gist:317994b4b9190287c3c6beff1ecb2ff4
Last active Jul 27, 2019
example of language with self-contained functions
View gist:317994b4b9190287c3c6beff1ecb2ff4

Xah Lee said:

i really want a language where you can copy paste any function definition in any project and use in another project. doesn't seem to exist. For this to work, the function param must encode any dependency, of global var and libs.

It took me a while to get my head around this idea, but here's some thoughts so far.

(I'll use C# as my example syntax here)

Imagine a function that is already self-contained....

secretGeek / WindowsIsUsingDarkTheme.cs
Created Jun 16, 2019
Test if Windows is using a dark theme (from a Windows forms app, for example) (This is not battle-tested in the wild)
View WindowsIsUsingDarkTheme.cs
//using Microsoft.Win32
public bool WindowsIsUsingDarkTheme()
var keyName = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
var valueName = "AppsUseLightTheme";
var value = Registry.GetValue(keyName, valueName, null);
if (value == null)
return false;
View gist:5ecad391916efa4a3acaa94685d4e41b

(my possibly incorrect line of thinking in relation to this tweet... )

First thing I think is:

we're not trying to work out the probability of being caught exactly once, or exactly twice etc. So we use an old statistics trick and turn it around, asking:

What is one minus the probability that he will be caught exactly 0 times?

To set about answering this, we start by saying, how often does he drink?

secretGeek / fforr.cs
Last active Aug 16, 2019
A new and better* way to write for loops in C#. (* .... it's not better)
View fforr.cs
// In this week's episode of "YOUR DOING IT WRONG"
void Main()
// The ** OLD ** keyword-heavy way to write a for loop.... nobody does this any more...
for (int i = 0; i < 12; i++)
secretGeek / Program.cs
Created Aug 30, 2017
simulate Alt-Enter in parent console from windows app
View Program.cs
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace PaulBettsWIN32
static class Program
static void Main(string[] args)
View sudoku (linqpad)
void Main()
var grid = goodGrid();
var foundOne = false;
var game = grid.Write();
secretGeek / golfquine.cs
Created Feb 11, 2016
golf quine in c# (157 bytes)
View golfquine.cs
class c{static void Main(){var s="class c{{static void Main(){{var s={0}{1}{0};System.Console.Write(s,(char)34,s);}}}}";System.Console.Write(s,(char)34,s);}}
secretGeek / Download_Worry_Dream_References.linq
Created Feb 11, 2016
LinqPad script that downloads all PDFs/etc from Bret Victors worry dream refs page.
View Download_Worry_Dream_References.linq
void Main()
// LinqPad script that downloads all PDFs/etc from Bret Victors worry dream refs page.
var targetPath = @"PATH_TO_WHERE_YOU_KEEP_YOUR_EBOOK\eBooks";
//These filenames were extracted from -- using NimbleText.
//(TODO: Use regex or html agility pack to find them programmatically)
var refs = new string[] {