Skip to content

Instantly share code, notes, and snippets.

View jamesikanos's full-sized avatar

James Woodall jamesikanos

View GitHub Profile
@jamesikanos
jamesikanos / from-live-query.ts
Created July 7, 2023 09:34
The fromLiveQueryArray function is a utility function for Reactive Programming in JavaScript. It takes a Live Query, which is a special kind of query that dynamically updates as its results change, and converts it into an Observable.
/*
* MIT License
*
* Copyright (c) 2023 James Woodall (jamesikanos@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
const compare = (a, b) => {
// 1. Split by `.`
const splitA = a.split('.');
const splitB = b.split('.');
// 2. Inner Compare function for each conmponent
const _cmp = (an, bn) => (an < bn ? -1 : an > bn ? 1 : 0);
const maxLoop = Math.max(splitA.length, splitB.length);
@jamesikanos
jamesikanos / azureBlockBlobUploader.ts
Created April 22, 2021 12:32
An Angular-compatible uploader for Azure Block Blobs. Requires a compatible SAS upload URL
/**
MIT License
Copyright (c) 2021, James Woodall
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@jamesikanos
jamesikanos / stock.full.ts
Last active August 25, 2020 07:48
A drop-in app.component.ts replacement for a Stock Ticker Application. Demonstrates how to use both Promises and Observables in the same pipeline.
import { Component, EventEmitter } from '@angular/core';
import { of, Observable, interval, merge, from, BehaviorSubject } from 'rxjs';
import { switchMap, map, switchMapTo, delayWhen, filter, delay, tap, take, shareReplay, catchError } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
const rngUrl = "https://www.random.org/integers/?num=1&min=1&max=6000&col=1&base=10&format=plain&rnd=new";
@Component({
selector: 'app-root',
template: `
@jamesikanos
jamesikanos / workflow-uploader.csproj
Created June 12, 2020 12:42
WorkfloPlus Auto Uploader Example
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>workflow_uploader</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.json" Version="12.0.3" />
@jamesikanos
jamesikanos / ExtendedRedisCacheHandle.cs
Created March 24, 2017 09:02
Extended Redis Cache Handle
public class ExtendedRedisCacheHandle : CacheManager.Redis.RedisCacheHandle<string>
{
private const string BaseRegion = "Base";
private readonly string _extraRegionName;
public ExtendedRedisCacheHandle(ICacheManagerConfiguration managerConfiguration, CacheHandleConfiguration configuration,
ILoggerFactory loggerFactory, ICacheSerializer serializer)
: base(managerConfiguration, configuration, loggerFactory, serializer)
{
@jamesikanos
jamesikanos / MongoEvalExtensions.cs
Last active January 28, 2022 04:26
MongoClient C# Eval Implementation
public static class MongoClientExtensions
{
/// <summary>
/// Evaluates the specified javascript within a MongoDb database
/// </summary>
/// <param name="database">MongoDb Database to execute the javascript</param>
/// <param name="javascript">Javascript to execute</param>
/// <returns>A BsonValue result</returns>
public static async Task<BsonValue> EvalAsync(this IMongoDatabase database, string javascript)
{