Skip to content

Instantly share code, notes, and snippets.

View NickDarvey's full-sized avatar

Nick Darvey NickDarvey

  • Melbourne, Australia
View GitHub Profile
@thesmart
thesmart / hid_generate.sql
Created May 5, 2020 17:25
Generates ordered, base36 alpha-numeric ids similar to Slack's ID scheme. Suitable for use as primary key.
-- This function generates ordered, base36 alpha-numeric ids similar to Slack's ID scheme.
--
-- I wanted a primary key scheme that had the following features:
-- 1) Lexical order, so that `ORDER BY` works as expected.
-- 2) Prevents sampling an auto-incrementing primary key to determine growth over time.
-- 3) Shorter and more human-friendly than BIGINT and UUID keys.
-- 4) Has a prefix such that table can be inferred from any record's primary or foreign key.
--
-- It is suitable for use as primary key, provided a few assumptions are true:
-- 1) You do not attempt to genereate more than 10M hids per second (system-time).
@mrange
mrange / dynamic_json.fs
Last active February 9, 2020 22:53
F# Dynamic JSON #2
// Copyright 2015 Mårten Rånge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@fearthecowboy
fearthecowboy / Test.csproj
Last active April 18, 2024 23:37
The definitive way to use PowerShell from an msbuild script
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- #1 Place this line at the top of any msbuild script (ie, csproj, etc) -->
<PropertyGroup><PowerShell># 2>nul || type %~df0|find /v "setlocal"|find /v "errorlevel"|powershell.exe -noninteractive -&amp; exit %errorlevel% || #</PowerShell></PropertyGroup>
<!-- #2 in any target you want to run a script -->
<Target Name="default" >
<PropertyGroup> <!-- #3 prefix your powershell script with the $(PowerShell) variable, then code as normal! -->
<myscript>$(PowerShell)
@aelij
aelij / -Usage.cs
Last active March 29, 2024 14:26
IAsyncEnumerable Bridge for Service Fabric Reliable Collections
class MyService : StatefulService
{
private Task<IReliableDictionary<int, string>> AccountNames => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountNames");
private Task<IReliableDictionary<int, string>> AccountData => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountData");
public async Task<List<Account>> SearchAccountsByNameAsync(string name)
{
using (var txn = StateManager.CreateTransaction())
{
var accountNames = await AccountNames;
@panesofglass
panesofglass / AsyncCallableHandler.fs
Last active April 24, 2023 17:53
How to use base.SendAsync in F# DelegatingHandler
type internal AsyncCallableHandler(messageHandler) =
inherit DelegatingHandler(messageHandler)
member internal x.CallSendAsync(request, cancellationToken) =
base.SendAsync(request, cancellationToken)