Skip to content

Instantly share code, notes, and snippets.

@atifaziz
atifaziz / ByteSizeFormatProvider.cs
Last active July 26, 2024 00:41
Custom formatter in F# & C# for formatting byte (file/disk/stream) sizes/lengths (e.g. 1.1MB, 2.3GB, 4 bytes, etc.)
using System;
// Adapted from: http://stackoverflow.com/questions/128618/c-file-size-format-provider
// Credit: http://flimflan.com/blog/FileSizeFormatProvider.aspx
public sealed class ByteSizeFormatProvider : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType)
{
return formatType == typeof(ICustomFormatter) ? this : null;
@atifaziz
atifaziz / json.vbs
Last active July 12, 2024 09:22
JSON Encoder for VBScript
'==========================================================================
' JSON Encoder for VBScript
' Copyright (c) 2013 Atif Aziz. All rights reserved.
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
@atifaziz
atifaziz / globlin.py
Created July 4, 2024 12:55
Python script to filters paths on standard input by pattern
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) Microsoft Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@atifaziz
atifaziz / InteractiveT.cs
Last active June 13, 2024 12:23
Interact Monad, derived from https://fssnip.net/8ay (Interactive computation that asks the user questions)
// Interact Monad, derived from https://fssnip.net/8ay (by Tomas Petricek)
// Interactive computation that asks the user questions
using System;
using System.Diagnostics;
using System.Linq;
static Interactive<Color> GetColor() => new WhatColor<Color>(Interactive.Return);
static Interactive<int> GetNumber() => new WhatNumber<int>(Interactive.Return);
@atifaziz
atifaziz / Export-ExcelProject.ps1
Last active June 7, 2024 22:52
PowerShell script to export VBA project components (classes, modules, etc.) from an Excel workbook
# Copyright (c) 2014 Atif Aziz. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@atifaziz
atifaziz / Unprotect-ProtectedData.ps1
Created March 31, 2017 06:25
Decrypting DPAPI-protected Base64 data from PowerShell
Add-Type -AssemblyName System.Security;
[Text.Encoding]::ASCII.GetString([Security.Cryptography.ProtectedData]::Unprotect([Convert]::FromBase64String((type -raw (Join-Path $env:USERPROFILE foobar))), $null, 'CurrentUser'))
@atifaziz
atifaziz / md5.cs
Created December 24, 2012 10:37
C# program to compute MD5 hash of files specified as command-line arguments
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
static class Program
{
static void Run(IEnumerable<string> args)
@atifaziz
atifaziz / GrepWinVisualStudioIntegration.md
Last active April 6, 2024 02:50
Integrating grepWin into Visual Studio

Integrating grepWin into Visual Studio

The simplest way to integrate [grepWin][grepwin] into Visual Studio is to [add it as an external tool][vsextern]. If you [assign it a keyboard shortcut][kbshortcut] then, well, you've got grepWin at your fingertips and getting to it becomes super fast without needing to resort to the silly old mouse! 🐭

However, simply launching grepWin from within Visual Studio means you still need to provide the starting search path. Ideally you can get grepWin to use the project or solution path automatically. Looking into the extended

@atifaziz
atifaziz / StaTask.cs
Created March 24, 2024 09:51
STA thread as an awaitable task
// Author: Atif Aziz
// License: This code is released by "Author" into the public domain.
using System;
using System.Threading;
using System.Threading.Tasks;
static partial class StaTask
{
public static Task RunAsync(Action action) =>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.