Skip to content

Instantly share code, notes, and snippets.

View danielrbradley's full-sized avatar

Daniel Bradley danielrbradley

View GitHub Profile
@danielrbradley
danielrbradley / TestController.fs
Last active August 29, 2015 14:06
Optional query parameters in WebAPI with F#
module Web
open System.Web.Http
[<AllowNullLiteral>]
type QueryModel() =
member val Top = 50 with get, set
member val Skip = 0 with get, set
[<RoutePrefix("api/test")>]

CarolR

The aim of CarolR is to play synchronised, real-time, polyphonic music from an orchestra of devices in the same area, to create an immersive, collaborative, Christmas music experience.

Challenges

In the design of such a system, we had several challenges to overcome:

  • Live performance music output
  • Encoding and programming of synchronised, muti-track music
@danielrbradley
danielrbradley / AsyncAsserts.cs
Last active January 4, 2016 02:27
Custom Throws assert for the NUnit framework for handling async code.
namespace NUnit.Framework
{
using System;
using System.Threading.Tasks;
using NUnit.Framework;
public static class AsyncAsserts
{
/// <summary>
@danielrbradley
danielrbradley / windows-software-installation.md
Last active December 8, 2016 12:21
Windows software installation

Windows Software Installation

Standard

  • Chrome
  • Opera
  • Firefox
  • Notepad++
    • View -> Show Symbol -> Show White Space and Tab
    • Settings -> Preferences -> Tab Settings -> Tick "Replace by space"
  • Settings -> Preferences -> Editing -> Untick "Display bookmark"
@danielrbradley
danielrbradley / 1-plain-function.fs
Created December 9, 2016 15:53
3 ways of organising F# functions related to a type
module VendingMachine
type Coin = Quarter | Dime | Nickel
let valueOf coin =
match coin with
| Quarter -> 0.25m
| Dime -> 0.10m
| Nickel -> 0.05m
@danielrbradley
danielrbradley / unsafe.fsx
Last active January 1, 2017 09:12
Types instead of Hungarian notation
// Response to https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/
// How to use types in place of naming conventions
module Unsafe
// What different variations do we want to handle?
type Encodable =
| Safe of string
| Unsafe of string
// Wrap our Request method to always mark the output as unsafe
@danielrbradley
danielrbradley / Request-accept-headers.md
Last active April 13, 2017 16:10
AWS API Gateway proxy via Lambda

Headers added by chrome...

Going direct to the PNG:

text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

When linked from img tag in an html page:

image/webp,image/*,*/*;q=0.8
@danielrbradley
danielrbradley / README.md
Created August 3, 2018 22:43
Script for backing up processed photos

My method for storing and backing up photos is as follows:

  1. All photos get downloaded into the Archive folder, in a folder for the current year, with the batch folder name starting with the date.
  2. The photos get reviewed, the ones which get picked are edited, exported as JPEGs, and the edit metadata saved alongside.
  3. Once editing is complete, the processed JPEGs are uploaded to wherever they're being shared (e.g. Google Photos).
  4. Run the script below which copies only files which have been picked and edited into the Best folder using the same folder names, but not grouped into years.
  5. The Best folder is backed up to a second local disk, and an offsite location (AWS Glacier).
  6. The Archive folder is only backed up onto a second local replicated disk.
@danielrbradley
danielrbradley / exec.ts
Created October 25, 2019 09:28
Pulumi custom component for running local commands
import * as pulumi from '@pulumi/pulumi';
import { exec, ExecOptions } from 'child_process';
export type ExecArgs = {
command: pulumi.Input<string>;
options?: pulumi.Lifted<ExecOptions>;
};
export class Exec extends pulumi.ComponentResource {
stdout: pulumi.Output<string>;
@danielrbradley
danielrbradley / OfflineApp.tsx
Created November 5, 2019 10:50
Integrating service worker auto-refresh with reach router
import React, { useEffect, useRef } from 'react';
import { Location } from '@reach/router';
import { register } from '../serviceWorker';
/**
* Include this component around your router to register a service worker to cache the application
* so it works offline. Then, when the application has automatically updated itself, intercept the
* Reach router location change and do a hard browser navigation to enble the application updates
* to be applied.
* @example