Skip to content

Instantly share code, notes, and snippets.

@rquackenbush
rquackenbush / Explicit.cs
Created May 28, 2024 11:35
CosmosDB / Gremlin Snippets
[Fact]
public async Task Explicit()
{
var twinId = Guid.NewGuid().ToString();
var requestScript = $"g.addV('twin').property('id', '{twinId}').property('partitionKey', '{twinId}').property('Prop1', 'SomeValue').property('Prop2', 42)";
var results = await _client.SubmitAsync<IDictionary<string, object>>(requestScript: requestScript);
var result = results.SingleOrDefault();
@rquackenbush
rquackenbush / endersgame1.printer.cfg
Last active December 27, 2023 05:15
Klipper config for Creality Ender 3 - v4.2.7 with BLTouch wired to the 5 pin connector
[include moonraker_obico_macros.cfg]
# This file contains pin mappings for the Creality "v4.2.7" board. To
# use this config, during "make menuconfig" select the STM32F103 with
# a "28KiB bootloader" and serial (on USART1 PA10/PA9) communication.
# If you prefer a direct serial connection, in "make menuconfig"
# select "Enable extra low-level configuration options" and select
# serial (on USART3 PB11/PB10), which is broken out on the 10 pin IDC
# cable used for the LCD module as follows:
# 3: Tx, 4: Rx, 9: GND, 10: VCC
@rquackenbush
rquackenbush / end.gcode
Last active October 29, 2023 03:51
Ender 3 Custom GCode Prusa Slicer
M104 S0 ; turn off hot end temperature
M140 S0 ; turn off bed temp
; To avoid the Z axis crashing into the print
; https://github.com/MarlinFirmware/Marlin/issues/5652#issuecomment-270745225
G92 Z0 ; fake z home
G1 Z5 ; raise Z up a bit
; G1 Y190 F5000 ; get bed forward
G28 X0 ; home X axis
@rquackenbush
rquackenbush / generate-pfx.sh
Created July 24, 2023 18:34
Generate PFX Cert
# Create a new key / certificate signing request
openssl req -new -newkey rsa:4096 -nodes -keyout snakeoil.key -out snakeoil.csr
# Set CN (common name) to "localhost"
openssl x509 -req -sha256 -days 365 -in snakeoil.csr -signkey snakeoil.key -out snakeoil.pem
# Export the pfx
openssl pkcs12 -export -in snakeoil.pem -inkey snakeoil.key -out snakeoil.pfx
@rquackenbush
rquackenbush / autorest.md
Created May 24, 2023 19:12
Autorest directive that sets the description
directive:
- from: openapi-document
  where: '$.paths["/health/startup"].get'
  debug: true
  transform: |
    $.responses["200"].description = "Startup Health check";
- from: openapi-document
  where: '$.paths["/health/ready"].get'
 debug: true
@rquackenbush
rquackenbush / CashOrMaterialize.cs
Created January 5, 2023 18:53
Take an IEnumerable<T> and cast to IList<T> (if possible), otherwise materialize the list with .ToList()
namespace ConsoleApp1
{
public static class IEnumerableExtensions
{
public static IList<T> CastOrMaterializeList<T>(this IEnumerable<T> source)
{
if (source is IList<T>)
return (IList<T>)source;
return source
@rquackenbush
rquackenbush / Columnizer.cs
Last active January 5, 2023 18:15
Text columnizer
using System.Text;
namespace ConsoleApp1
{
public static class Columnizer
{
public static IEnumerable<string> Columnize(IList<string> headers, IList<string[]> rows, string separator = " ")
{
// Start with the lengths of the column headers
int[] columnWidths = headers
@rquackenbush
rquackenbush / RemoveLastTriplet.cs
Created August 11, 2022 18:52
One (non-optimized) solution for a Stack Overflow question.
using System;
using System.Collections.Generic;
/*
Example 1
input : nums = [2,4,2,2,7,5,6,7,8,6,6,2,6,7,6]
output : nums = [2,4,5,6,8,6]
Example 2 input : nums = [2,2,3,2,3,2]
output : nums = [2,3,3]
@rquackenbush
rquackenbush / DictionaryExtensions.cs
Created August 4, 2022 15:07
Simple extension method to pull a subtyped value from a dictionary.
using System.Collections.Generic;
public static class IDictionaryExtensions
{
public static bool TryGetValue<TKey, TOutValue, TInValue>(this IDictionary<TKey, TInValue> source, TKey key, out TOutValue value)
where TInValue : TOutValue
{
if (source.TryGetValue(key, out var temp))
{
value= temp;
@rquackenbush
rquackenbush / AsyncEnumerableExtensions.cs
Last active July 27, 2022 16:41
A simple batching bit of code for IAsyncEnumerable.
using System.Runtime.CompilerServices;
namespace Extensions.Core;
public static class AsyncEnumerableExtensions
{
public static async IAsyncEnumerable<T[]> BatchAsync<T>(
this IAsyncEnumerable<T> source,
int batchSize,
[EnumeratorCancellation] CancellationToken cancellationToken = default)