Skip to content

Instantly share code, notes, and snippets.

@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.

@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 / 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 / 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 / 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 / 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 / redux-obs-example.js
Created April 4, 2019 07:14
redux-observable simple example
import { ofType } from 'redux-observable';
const pingEpic = action$ => action$.pipe(
ofType('PING'),
delay(1000), // Asynchronously wait 1000ms then continue
mapTo({ type: 'PONG' })
);
@dezfowler
dezfowler / Clock.jsx
Last active March 29, 2019 18:13
Simple rxified Clock
const { interval, empty } = require('rxjs');
const { switchMap, startWith, map } = require('rxjs/operators');
const Clock = rxify((initialProps, prop$) => {
return prop$
.pipe(
switchMap(props => props.running ? interval(0, 1000) : empty()),
startWith(1),
map(_ => (<span className="time">{new Date().toLocaleTimeString()}</span>))
)
@dezfowler
dezfowler / Clock.jsx
Created December 14, 2018 19:04
Observable Clock.jsx
class Clock extends React.Component {
constructor(props) {
super(props);
console.log('new');
this.state = { time: new Date() };
}
componentDidMount() {
this.propsChangeSubject = new Subject();
this.subscription = this.propsChangeSubject
@dezfowler
dezfowler / Clock.jsx
Created December 14, 2018 19:00
Async Clock.jsx
class Clock extends React.Component {
constructor(props) {
super(props);
this.intervalId = undefined;
this.state = { time: new Date() };
}
componentWillUnmount() {
this.stopTick();
}