Skip to content

Instantly share code, notes, and snippets.

View sandrock's full-sized avatar

SandRock sandrock

View GitHub Profile
@sandrock
sandrock / JsonHelper.cs
Created September 12, 2025 08:38
JsonHelper.cs
namespace Somewhere
{
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
/// <summary>
@sandrock
sandrock / browser-report.js
Created July 9, 2025 16:53
Report browser settings like whatsmybrowser.org
/*
* Report browser settings like whatsmybrowser.org
* Inspired by
* http://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript
*/
(function () {
"use strict";
var extractDataFromClient, definePropertySupported;
@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 August 22, 2025 16:05
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 February 7, 2025 00:13
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)