Skip to content

Instantly share code, notes, and snippets.

View james-world's full-sized avatar

James World james-world

View GitHub Profile
@james-world
james-world / getNext.js
Created August 21, 2020 23:35
CosmosDb stored procedure to generate the next number in a 7-digit non-repeating pseudo random sequence.
function getNext(name) {
var response = getContext().getResponse();
var result = __.chain()
.filter(function(doc) { return doc.id === name; })
.value({}, updateCounter);
if(!result.isAccepted) throw new Error("The call was not accepted");
var next;
@james-world
james-world / SODiscards.cs
Created July 10, 2020 08:57
Dangers of stand alone discards
void Main()
{
Test1(5);
Test2(5);
}
void Test1(int _)
{
_ = 2 + 2;
Console.WriteLine(_);
@james-world
james-world / FetchAll.ps1
Created April 23, 2020 15:53
Put these in a directory containing all your repos. Run FetchAll it to get latest remote changes for all repos in sub-directories, Run UpdateMain to update the main branch in all repos with main checked out and without local changes.
# Get latest remote changes for all repos in sub-directories
Write-Output "Fetching remote repositories..."
Get-ChildItem -Directory |
# Has a hidden .git directory (i.e. is a repository)
Where-Object { ( $_ | Get-ChildItem -Hidden ).Name -contains ".git" } |
# Has at lease one remote
Where-Object { Push-Location $_; (git remote).Count -gt 0; Pop-Location } |
# Fetch remote changes
ForEach-Object { Push-Location $_; "Checking $_..."; git fetch; Pop-Location; "`t...Done"; }
@james-world
james-world / FSharpTalk.md
Last active December 6, 2019 17:04
Notes from a talk on FSharp
@james-world
james-world / Get-GitIgnore.ps1
Created October 20, 2018 14:55
Powershell command to create a .gitignore file from .gitignore.io
function Get-GitIgnore {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string[]]
$Targets,
[string]
$OutputDirectory = "$PWD",
[string]
$Filename = ".gitignore",
@james-world
james-world / decorators.cs
Created April 2, 2017 12:47
Demostrates unexpected decorator behaviour in Auto 4.4.0
// Suitable for LINQPad with the Autofac nuget package
void Main()
{
ExpectedBehaviour();
UnexpectedBehaviour();
}
public void ExpectedBehaviour()
{
@james-world
james-world / LeakyGenerate.cs
Last active December 20, 2016 03:14
Demonstrate leakiness of Generate and recursive Schedule
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@james-world
james-world / RollingReplaySubject
Last active December 1, 2019 16:21
RollingReplaySubject - Works like ReplaySubject but has buffer cleared on a TimeInterval or based on an input stream.
namespace RxExtensions
{
using System;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
public class RollingReplaySubject
@james-world
james-world / Auth0-angular Popup Login Hang Repro
Created October 31, 2014 11:57
Repro for auth0-angular login dialog not closing
Auth0-angular Popup Login Hang Repro
/* Name of Gist */