Skip to content

Instantly share code, notes, and snippets.

🎸
Focusing

Leon Bambrick secretGeek

🎸
Focusing
Block or report user

Report or block secretGeek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@secretGeek
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... 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 May 15, 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++)
{
Console.WriteLine(i);
}
@secretGeek
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
{
[STAThread]
static void Main(string[] args)
View sudoku (linqpad)
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 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
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 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",
View quine.cs
using System;
namespace Quine
{
class Program
{
static string[] program = new string[] {
"using System;",
"namespace Quine",
"{",
" class Program",
View todo.ps1
dir *.md | % { $file = $_.Name; get-content $_ | select-string -pattern "//TODO:" | % { $file.substring(0,10) + ":" + $_.ToString().replace("//TODO:","").trim() }} | more
@secretGeek
secretGeek / bake.ps1
Created Oct 1, 2014
bake.ps1 -- generates an epub for me, using pandoc, with my chosen cover image, stylesheet, yaml metadata and my chapters.
View bake.ps1
pandoc -f markdown -t epub --epub-cover-image=cover.jpg -o yfp.epub --smart --toc --epub-stylesheet=epub.css title.txt .\00_Title.md .\01_Before_we_begin.md .\02_ideas.md .\03_Choose_your_concept.md .\04_Landing_page.md .\05_Pricing.md .\06_Build_your_product.md .\07_Launch_time.md .\08_Optimize.md .\09_Support.md .\10_Refresh.md .\11_tools.md .\12_Glossary.md .\13_reading_list.md --epub-chapter-level=3
You can’t perform that action at this time.