Skip to content

Instantly share code, notes, and snippets.

@dezfowler
dezfowler / rxify.js
Last active April 6, 2019 22:01
Testing
import { Subject } from 'rxjs';
import { tap } from 'rxjs/operators';
export const rxify = renderStreamFactory =>
class Rxified extends React.Component {
constructor(props) {
super(props);
this.state = null;
}
@dezfowler
dezfowler / array-assert-1.ts
Last active July 24, 2019 13:01
TypeScript type checking fails
// No error with incorrect 'botton' item
var x1 = <Alignment[]>['top', 'top', 'botton'];
// No error with different underlying value number
var x2 = <Alignment[]>['top', 'top', 2];
// Correctly errors with
// Type '"botton"' is not assignable to type 'Alignment'.
var x3: Alignment[] = ['top', 'top', 'botton'];
@dezfowler
dezfowler / safe-switch.ts
Last active August 6, 2019 12:39
Typed visitor discriminated union
function calculateArea(shape: Shape): number {
switch(shape.__typename) {
case 'Circle':
return Math.PI * (shape.radius ^ 2);
case 'Rectangle':
return shape.width * shape.height;
case 'Square':
return shape.side ^ 2;
case 'Triangle':
return (shape.base / 2) * shape.height;
@dezfowler
dezfowler / Program.cs
Created July 8, 2020 11:45
Serialize to XDocument benchmark
using System.IO;
using System.Text;
using System.Xml.Linq;
using System.Xml.Serialization;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace MyBenchmarks
{
[MemoryDiagnoser]
@dezfowler
dezfowler / ReplaceOwner.ps1
Created May 18, 2022 15:33
Fix incorrect file or folder owner
param (
[string]$from = $(throw "-from is required."),
[string]$to = $(throw "-to is required.")
)
$correctOwner = (Get-Acl $from).GetOwner([System.Security.Principal.SecurityIdentifier])
$acl = Get-Acl $to
$acl.SetOwner($correctOwner)
@dezfowler
dezfowler / Text-adventure.md
Last active February 25, 2023 09:43
Chat GPT prompts

Text adventure prompt

Prompt

I want you to act as if you are an interactive text adventure game and I am the player who must input the actions for the protagonist to perform.

The setting is {any setting you like here}.

I don’t want you to ever break out of your character, and you must not refer to yourself in any way. If I want to give you instructions outside the context of the game, I will use curly brackets {like this} but otherwise you are to stick to being the text adventure program.