Skip to content

Instantly share code, notes, and snippets.

This file has been truncated, but you can view the full file.
{"series":[{"columns":["ts","2","3","4","5","6","7","8"],"name":"01f542c9-c3ce-4c1e-ae00-9c601240823c","points":[[1633039200000,null,9251,0,null,null,25.4,24.4],[1633040100000,null,9251,0,null,null,25.4,24.4],[1633041000000,null,null,null,null,null,null,null],[1633041900000,null,9251,0,null,null,25.4,24.4],[1633042800000,null,9252,0,null,null,25.4,24.3],[1633043700000,null,9252,0,null,null,25.4,24.3],[1633044600000,null,null,null,null,null,null,null],[1633045500000,null,9252,0,null,null,25.4,24.3],[1633046400000,null,9253,0,null,null,25.4,24.3],[1633047300000,null,9253,0,null,null,25.4,24.3],[1633048200000,null,null,null,null,null,null,null],[1633049100000,null,9253,0,null,null,25.4,24.3],[1633050000000,null,9254,0,null,null,25.4,24.3],[1633050900000,null,null,null,null,null,null,null],[1633051800000,null,9254,0,null,null,25.4,24.3],[1633052700000,null,9254,0,null,null,25.4,24.3],[1633053600000,null,9255,0,null,null,25.4,24.3],[1633054500000,null,null,null,null,null,null,null],[1633055400000,null,9255,0,null,
@dgg
dgg / rounding.ts
Created June 22, 2021 09:24
rounding a number in typescript
export const DECIMAL_PLACES = 1
// it may have some rounding problems in some cases, but we should be good
export const round = (n: number, decimals: number = DECIMAL_PLACES): number => {
const abs = n < 0 ? Math.abs(n) : n
const factorOfTen = Math.pow(10, decimals)
const rounded = Math.round(abs * factorOfTen) / factorOfTen
const result = abs === n ? rounded : -rounded
@dgg
dgg / leftFromFirst.js
Created September 11, 2018 19:57
test-last-ts
describe("leftFromFirst", () => {
const testSpec = [
{args: [null, "lazy lazy fox jumped"], value : null, desc : "substring not found"},
//{args: ["", "lazy lazy fox jumped"], value : null, desc : "substring not found"},
{args: [null, ""], value : null, desc : "(null, '') --> null"},
{args: [null, null], value : null, desc : "(null, null) --> null"},
{args: [null, null], value : null, desc : "(null, null) --> null"},
//{args: ["", ""], value : null, desc : "(*, '') --> ''"},
//{args: ["", null], value : '', desc : "(*, null) --> ''"},
]
@dgg
dgg / equivalence-test.cs
Created March 9, 2018 09:24
They-got-your-back
[Test]
[TestCase(2, 1, true)]
[TestCase(1, 2, false)]
[TestCase(1, 1, false)]
[TestCase(null, 1, false)]
[TestCase(1, null, false)]
[TestCase(null, null, false)]
public void Snippets_Are_Equivalent(int? qty1, int? qty2, bool result)
{
bool shouldCompare = qty1 != null && qty2 != null;
@dgg
dgg / Client.cs
Created January 3, 2018 15:05
Anatomy-of-a-Breaking-Change
using System;
using BreakingChangeAnatomy.Library;
using BreakingChangeAnatomy.Library.ChildNs;
namespace BreakingChangeAnatomy.Client
{
class Program
{
static void Main(string[] args)
{
@dgg
dgg / lesser-marker-interface.cs
Last active December 15, 2017 07:09
heavy-weight-champion
internal interface ICurrencyInfoProvider
{
CurrencyInfo Get(CurrencyIsoCode code);
}
// not a "real" marker interface
internal interface ICurrencyInfoInitializer : ICurrencyInfoProvider, IDisposable { }
@dgg
dgg / custom-assertions.cs
Created November 27, 2017 08:51
Testing DSLs
int even = 2, odd = 3;
// meh
Assert.That(even % 2, Is.EqualTo(0));
// slightly better (message)
Assert.That(odd % 2, Is.Not.EqualTo(0), "Number must be odd");
// better
Assert.That(odd, new EvenContraint());
// best
Assert.That(even, Must.Be.Even());
@dgg
dgg / SampleFilter.cs
Last active November 26, 2017 13:13
samplify-swagger
internal class SampleFilter : ISchemaFilter
{
public void Apply(Schema model, SchemaFilterContext context)
{
var attribute = context.SystemType.GetCustomAttribute<HasCustomSampleAttribute>();
if (attribute != null)
{
model.Example = attribute.BuildExample(context.SystemType);
}
}
@dgg
dgg / the-culprit.cs
Created October 21, 2017 12:52
pissed-by-function
public class AClassWithOneMethod
{
public static int GetOrdering(string someName, SomeAttributeDefinition someAttributeDefinition)
{
if (SomeConstants.ACollection.Exists(x => x == someName))
return 20;
switch (someName)
{
case SomeConstants.AConstant:
return 10;
@dgg
dgg / instructions.md
Created October 14, 2017 19:01
deploy subfolder to gh-pages
  1. checkout doc
  2. create subfolder www/
  3. generate content in www/
  4. commit content in www/
  5. git subtree split --prefix www -b gh-pages
  6. add and commit more content to www/
  7. git subtree push --prefix www origin gh-pages