Skip to content

Instantly share code, notes, and snippets.

View secretGeek's full-sized avatar
😮‍💨
just-so-tired

Leon Bambrick secretGeek

😮‍💨
just-so-tired
View GitHub Profile
@secretGeek
secretGeek / FileStashy.cs
Created November 13, 2020 02:09
FileStashy (and IStashy)
// 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
secretGeek / get-meetings.ps1
Last active September 13, 2022 22:19
Get today's schedule from Outlook, using COM, and format as text for my TODO.txt file
# 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
secretGeek / gist:317994b4b9190287c3c6beff1ecb2ff4
Last active July 27, 2019 04:12
example of language with self-contained functions

Xah Lee said: https://twitter.com/xah_lee/status/1154957785441816576

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
secretGeek / WindowsIsUsingDarkTheme.cs
Created June 16, 2019 04:56
Test if Windows is using a dark theme (from a Windows forms app, for example) (This is not battle-tested in the wild)
//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;
}

(my possibly incorrect line of thinking in relation to this tweet... https://twitter.com/secretGeek/status/1135831731347398657 )

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
secretGeek / fforr.cs
Last active August 16, 2019 21:10
A new and better* way to write for loops in C#. (* .... it's not better)
// 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++)
{
Console.WriteLine(i);
}
@secretGeek
secretGeek / Program.cs
Created August 30, 2017 12:47
simulate Alt-Enter in parent console from windows app
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace PaulBettsWIN32
{
static class Program
{
[STAThread]
static void Main(string[] args)
void Main()
{
//testGenerating();
var grid = goodGrid();
//grid.Write().Dump();
grid.MakeGame();
//grid.Write().Dump();
var foundOne = false;
var game = grid.Write();
while(!foundOne)
@secretGeek
secretGeek / golfquine.cs
Created February 11, 2016 13:02
golf quine in c# (157 bytes)
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
secretGeek / Download_Worry_Dream_References.linq
Created February 11, 2016 00:59
LinqPad script that downloads all PDFs/etc from Bret Victors worry dream refs page.
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 http://worrydream.com/refs/ -- using NimbleText.
//(TODO: Use regex or html agility pack to find them programmatically)
var refs = new string[] {
"Hamming-TheArtOfDoingScienceAndEngineering.pdf",
"Licklider-IntergalacticNetwork.pdf",