Skip to content

Instantly share code, notes, and snippets.

@scegg
scegg / HttpContextExtensions.cs
Created July 19, 2021 05:46
Get parameter from both query string and post form
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
namespace SecretNest.Helper
{
@scegg
scegg / HttpContextExtensions.cs
Created July 19, 2021 05:44
Use GZipStream as response in plain Asp.Net Core 5
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
namespace SecretNest.Helpers
{
@scegg
scegg / SecondExtensions
Created March 5, 2021 03:10
Convert second value into time text
using System;
namespace SecretNest.Text
{
internal static class SecondExtensions
{
public static string ToTimeText(this long second)
{
switch (second)
{
@scegg
scegg / SizeTextExtensions.cs
Last active March 5, 2021 03:11
Convert file size value into text
namespace SecretNest.Text
{
internal static class SizeTextExtension
{
/*
<0B
0B
00B
000B
0000B
@scegg
scegg / ReadOnlyListIndexOfExtensions.cs
Created March 5, 2021 03:07
IndexOf of ReadOnlyList
using System.Collections.Generic;
namespace SecretNest.Collections
{
internal static class ReadOnlyListIndexOfExtensions
{
public static int IndexOf<T>(this IReadOnlyList<T> readOnlyList, T element)
{
if (readOnlyList is IList<T> list) return list.IndexOf(element);
@scegg
scegg / sdcopy.sh
Last active October 23, 2020 14:20
Copy from SD cards to another USB disk. https://wp.secretnest.info/archives/12140
#!/bin/sh
# test and mount
function Test_n_Mount() {
sudo mkdir $MountPointTest
for SDDEV in /dev/sd?
do
for PARTITION in $SDDEV*
do
if [ "$PARTITION" != "$SDDEV" ]
@scegg
scegg / ExportRSAPublicKeyExtensions.cs
Last active March 5, 2021 03:11
Add ExportRSAPublicKey() to netfx
static class ExportRSAPublicKeyExtension
{
public static byte[] ExportRSAPublicKey(this RSA rsa)
{
const byte tagSequence = 0x30, tagInteger = 0x2;
var parameter = rsa.ExportParameters(false);
byte[] modulus = AddIntUnsignedMark(parameter.Modulus);
byte[] modulusLength = GetAsn8BitLength(modulus.LongLength);