Skip to content

Instantly share code, notes, and snippets.

View mkropat's full-sized avatar
📚
Learning

Michael Kropat mkropat

📚
Learning
View GitHub Profile
@mkropat
mkropat / HexDump.cs
Last active December 23, 2017 04:53
public static string HexDump(byte[] bytes)
{
using (var s = new MemoryStream(bytes))
return HexDump(s);
}
public static string HexDump(Stream s)
{
var result = new StringBuilder();
var buf = new byte[16];
<Query Kind="Program" />
void Main()
{
Console.WriteLine("## firstAction + secondAction ##");
Action<string> firstAction = x => Console.WriteLine($"firstAction({x})");
Action<string> secondAction = x => Console.WriteLine($"secondAction({x})");
(firstAction + secondAction)("derp");
Console.WriteLine();
<Query Kind="Program">
<Namespace>System.Threading.Tasks</Namespace>
</Query>
async Task Main()
{
_lastLog = DateTime.Now;
using (var defaultWatcher = new FileSystemWatcher())
{
defaultWatcher.Dump("default FileSystemWatcher");
<Query Kind="Statements" />
ThreadPool.GetAvailableThreads(out int availableWorkerThreads, out int availableCompletionPortThreads);
ThreadPool.GetMaxThreads(out int maxWorkerThreads, out int maxCompletionPortThreads);
new[] {
new { Name = "Available", WorkerThreads = availableWorkerThreads, CompletionPortThreads = availableCompletionPortThreads },
new { Name = "Max", WorkerThreads = maxWorkerThreads, CompletionPortThreads = maxCompletionPortThreads },
}.Dump();
<Query Kind="Statements">
<Reference>&lt;RuntimeDirectory&gt;\System.Security.dll</Reference>
<Namespace>System.Security.Cryptography</Namespace>
</Query>
var scope = DataProtectionScope.CurrentUser;
var data = Encoding.UTF8.GetBytes("hello, world (privately)");
var encrypted = ProtectedData.Protect(data, null, scope);
@mkropat
mkropat / hexdump.js
Last active November 28, 2019 08:27 — forked from igorgatis/hexdump.js
Simple hexdump in Javascript
function d(str) {
console.log(hexdump(decode(str)));
}
function decode(base64) {
base64 = base64 || '';
return atob(base64.replace(/_/g, '/').replace(/-/g, '+'));
}
function hexdump(buffer, blockSize) {
function Get-WebFile {
param(
[Parameter(Mandatory=$true)]
$Uri,
[string] $OutFile,
[string] $Hash,
[string] $HashAlgorithm = 'SHA256'
)
if (-not $OutFile) {
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\Microsoft.JScript.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Configuration.Install.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Management.dll</Reference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>System.Management</Namespace>
</Query>
void Main()
<Query Kind="Program" />
delegate void SomeDelegate();
static SomeDelegate emptyHandler = delegate {};
event SomeDelegate DefaultSubscriber = () => Console.WriteLine("DefaultSubscriber was called");
event SomeDelegate SubscriberAddedThenRemoved = emptyHandler;
event SomeDelegate DefaultSubscriberWithSubscriberAddedthenRemoved = () => Console.WriteLine("DefaultSubscriberWithSubscriberAddedthenRemoved was called");
event SomeDelegate EmptySubscriber = delegate { };
<Query Kind="Program">
<NuGetReference>WindowsAzure.ServiceBus</NuGetReference>
<Namespace>Microsoft.ServiceBus</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
<Namespace>Microsoft.ServiceBus.Messaging</Namespace>
<Namespace>System.Runtime.Serialization</Namespace>
</Query>
async Task Main()
{