Skip to content

Instantly share code, notes, and snippets.

Avatar

Ani Betts anaisbetts

View GitHub Profile
@anaisbetts
anaisbetts / Buzzer.cs
Created Jan 1, 2022
Doorbell Automation
View Buzzer.cs
namespace HomeDotAnaisDotDev;
using System;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using HomeAssistantGenerated;
using NetDaemon.Common;
using NetDaemon.HassModel.Common;
View NativeMethods.txt
EnumDisplaySettings
ChangeDisplaySettingsExW
View result.ts
export abstract class Result<T> {
abstract isOk(): boolean;
abstract isErr(): boolean;
abstract ok(): T | undefined;
abstract err(): Error | undefined;
static Ok<T>(val: T): Result<T> {
return new OkValue(val);
}
View murder-processes.cs
public async Task KillProcessNicely(uint pid, int delayInMs = 3*1000)
{
// Ugh, this is gross - https://stackoverflow.com/questions/16653517/how-best-to-post-wm-quit-to-a-running-process
var tids = NativeMethods.GetAllTopLevelWindowsInZOrder()
.Select(hwnd => {
uint wndpid = 0;
var tid = NativeMethods.GetWindowThreadProcessId(hwnd, out wndpid);
if (wndpid != pid) {
return (uint)0;
}
View reentrancy-sucks.txt
> JustTheGame.dll!JustTheGame.LicensePromptViewModel..ctor.AnonymousMethod__18_5(Akavache.LoginInfo _) Line 67 C#
System.Reactive.dll!System.Reactive.Linq.ObservableImpl.Do<Akavache.LoginInfo>.Actions._.OnNext(Akavache.LoginInfo value) Line 158 C#
System.Reactive.dll!System.Reactive.Linq.ObservableImpl.Select<System.__Canon, System.__Canon>.Selector._.OnNext(System.__Canon value) Line 48 C#
System.Reactive.dll!System.Reactive.SafeObserver<JustTheGame.GameStoreHeuristicInfo>.WrappingSafeObserver.OnNext(JustTheGame.GameStoreHeuristicInfo value) Line 31 C#
System.Reactive.dll!System.Reactive.Linq.ObservableImpl.Select<ReactiveUI.ReactiveCommand<System.Reactive.Unit, System.__Canon>.ExecutionInfo, System.__Canon>.Selector._.OnNext(ReactiveUI.ReactiveCommand<System.Reactive.Unit, System.__Canon>.ExecutionInfo value) Line 48 C#
System.Reactive.dll!System.Reactive.Sink<ReactiveUI.ReactiveCommand<System.Reactive.Unit, JustTheGame.GameStoreHeuristicInfo>.ExecutionInfo>.ForwardOnNext(ReactiveUI.ReactiveComman
@anaisbetts
anaisbetts / index.ts
Created Aug 31, 2019
Create a PostgreSQL + Hasura database in Docker with Pulumi
View index.ts
import * as pulumi from '@pulumi/pulumi';
import * as docker from '@pulumi/docker';
import * as pg from '@pulumi/postgresql';
const cfg = new pulumi.Config();
const network = new docker.Network('net');
const pgImg = new docker.RemoteImage('postgresql-image', {
name: 'postgres:11',
keepLocally: true
@anaisbetts
anaisbetts / index.ts
Created Aug 30, 2019
PostgreSQL + Pulumi
View index.ts
import * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";
import * as pg from '@pulumi/postgresql';
const cfg = new pulumi.Config();
const network = new docker.Network("net");
const pgImg = new docker.RemoteImage("postgresql-image", {
name: "postgres:11",
keepLocally: true
View globalhotkey.cs
namespace GlobalHotKey
{
public class GlobalKeyboardHookEventArgs : HandledEventArgs
{
public GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; }
public GlobalKeyboardHook.LowLevelKeyboardInputEvent KeyboardData { get; private set; }
public GlobalKeyboardHookEventArgs(
GlobalKeyboardHook.LowLevelKeyboardInputEvent keyboardData,
GlobalKeyboardHook.KeyboardState keyboardState)
@anaisbetts
anaisbetts / example.ts
Last active Jan 20, 2019
always use function parameters
View example.ts
function Example() {
// Crap, we just made a Firebase query for each render instead of
// what we wanted, a query set up on mount, and cleaned up on unmount
const query = useQuery(db.collections('lots-of-stuff').limit(10000));
return <ul>query.docs.map(x => (<li>{x}</li>));
}
View example.tsx
import { Model } from '@whenjs/when';
import { useState } from 'react';
import { useWhen } from '../src/when-react/use-helpers';
class ViewModel extends Model {
public foo: number;
constructor() {
super();