Skip to content

Instantly share code, notes, and snippets.

View chamook's full-sized avatar
🍫
Would you risk it for a chocolate biscuit?

Adam Guest chamook

🍫
Would you risk it for a chocolate biscuit?
View GitHub Profile
//lurking within other code
var thingFac = new ThingFactory(myThingName, myThingVal);
var thing = thingFac.MakeThing(thirdParam);
private static Thing MakeThing(string thingName, int thingVal, string thirdParam)
{
if (thingName == null)
throw new ArgumentNullException(nameof(thingName));
if (thirdParam == null)
throw new ArgumentNullException(nameof(thirdParam));
return new Thing(thingName, thingVal, thirdParam);
}
public interface IConfigurationProvider
{
int TimeoutSeconds { get; }
Uri Endpoint { get; }
int RetryCount { get; }
}
public class ConfigurationProvider
{
public int TimeoutSeconds =>
Int32.Parse(Environment.GetEnvironmentVariable("TIMEOUT_SECONDS"));
public Uri Endpoint =>
new Uri(Environment.GetEnvironmentVariable("ENDPOINT"));
public int RetryCount =>
Int32.Parse(Environment.GetEnvironmentVariable("RETRY_COUNT"));
}
type Colour = {
Id : string
Name : string
Hex : string
RGB : RGB
HSL : HSL
}
and RGB = { Red : int; Green : int; Blue : int }
and HSL = { Hue : int; Saturation : int; Lightness : int }
struct Colour: Decodable {
var id: String
var name: String
var hex: String
}
var colours: [Colour] = []
private func loadColours() {
let url = URL(string: "http://localhost:5000/my-colours")
let customJsonContentType mimeType data next (ctx : HttpContext) =
sprintf "%s; charset=utf-8" mimeType |> ctx.SetContentType
let serializer = ctx.GetJsonSerializer()
serializer.SerializeToBytes data
|> ctx.WriteBytesAsync
type CustomNegotiationConfig (baseConfig : INegotiationConfig) =
interface INegotiationConfig with
member __.UnacceptableHandler =
baseConfig.UnacceptableHandler
type MiniColour = {
Id : string
Name : string
Hex : string
}
type MiniMyColoursDto = { Colours : MiniColour list }
let toMiniColour (c : Colour) = { MiniColour.Id = c.Id; Name = c.Name; Hex = c.Hex }
let url = URL(string: "http://localhost:5000/my-colours")!
var request = URLRequest(url: url)
request.setValue("application/vnd.chamook.mini-colours+json", forHTTPHeaderField: "Accept")
URLSession.shared.dataTask(with: request) { [weak self] (data, response, error) in
...
let tryGetPropertyName<'a> propertyName =
FSharpType.GetRecordFields typeof<'a>
|> Array.tryFind
(fun x -> String.Equals(x.Name, propertyName, StringComparison.OrdinalIgnoreCase))
|> Option.map (fun x -> x.Name)
let includingRegex = Regex("including=(.*?)(\Z|\0)")
let (|FilteredRepresentation|_|) (accept : string option) =
match accept with