Skip to content

Instantly share code, notes, and snippets.

View sandrock's full-sized avatar
💭
😪 migrating lots of stuff to dotnet core

SandRock sandrock

💭
😪 migrating lots of stuff to dotnet core
View GitHub Profile
@sandrock
sandrock / StringBuilder.CopyTo.cs
Created April 23, 2024 09:45
Writing the content of StringBuilder to a file without calling ToString()
public static class Utility
{
/// <summary>
/// Buffer-copy the specified StringBuilder contents into a text writer.
/// </summary>
/// <param name="stringBuilder"></param>
/// <param name="stringWriter"></param>
/// <returns></returns>
public static long CopyTo(this StringBuilder stringBuilder, TextWriter stringWriter)
{
@sandrock
sandrock / ParseArgs.cs
Last active April 27, 2024 08:18
ParseArgs.cs
namespace Somewhere
{
using System;
using System.Collections;
using System.Collections.Generic;
// from <https://gist.github.com/sandrock/d1fb3040e1c9326d8dd16b3bad8930ac>
/// <summary>
@sandrock
sandrock / demo.sh
Last active March 28, 2024 08:12
bash parse semantic version
#!/bin/bash
value=v1.20.03-xx7
semver=$(echo "$value" | sed -r "s/^v?([0-9]+)\.([0-9]+)\.([0-9]+)(.*)$/\1 \2 \3 \4/") ; semver=( $semver )
echo "result: ${semver[0]} ${semver[1]} ${semver[2]} ${semver[3]}"
@sandrock
sandrock / 0README.md
Last active March 21, 2023 10:53
migrate usage of StringBuilder+TagBuilder for HTML rendering
@sandrock
sandrock / README.md
Created September 30, 2022 11:32
Start Docker at Windows startup

Start Docker at Windows startup

Run

Copy the files from this gist into a directory of your choice.

You may customize the StartDocker.ps1 script to include docker commands.

@sandrock
sandrock / CollectionProxy.cs
Created February 24, 2021 12:44
C# CollectionProxy
namespace SrkToolkit.Common
{
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Proxies a collection of <typeparamref name="TSource"/> into a collection of <typeparamref name="T"/> using a direct cast mehod.
/// </summary>
@sandrock
sandrock / dotnet encodings.txt
Created April 27, 2020 13:34
dotnet encodings.txt
Usual encodings
================
1200 utf-16 Unicode
1252 Windows-1252 Western European (Windows)
28591 iso-8859-1 Western European (ISO)
65001 utf-8 Unicode (UTF-8)
Other encodings
================
@sandrock
sandrock / JavaRuntimeCheckTask.cs
Created April 13, 2020 13:17
Java Runtime Check Task
namespace Somewhere
{
using System;
using System.IO;
using Microsoft.Win32;
internal sealed class JavaRuntimeCheckTask
{
public void Verify(PackageContext context)
@sandrock
sandrock / Extensions.InvariantString.cs
Last active October 1, 2022 15:59
C# Returns an invariant, roundtrip-safe string representation numeric values
namespace System
{
using System.Globalization;
// source: https://gist.github.com/sandrock/6fe3298b8ac6d9d0d9872dd811a63908
/// <summary>
/// Extension methods for common types that provide ToInvariantString() capability.
/// </summary>
@sandrock
sandrock / ApiController.cs
Created November 6, 2019 10:59
ASP WebAPi better ApiController NotFound method with negociated response content
namespace MyWebApi
{
public abstract class ApiController : System.Web.Http.ApiController
{
/// <summary>
/// Returns a NotFound HTTP result (404) with a negotiated full-bodyed result.
/// </summary>
/// <returns></returns>
protected override System.Web.Http.Results.NotFoundResult NotFound()