Skip to content

Instantly share code, notes, and snippets.

View philipmat's full-sized avatar

Philip Mateescu philipmat

View GitHub Profile
@philipmat
philipmat / Program.cs
Last active October 10, 2023 18:22
DotNet LongTimePattern
Console.WriteLine($".NET Version={Environment.Version}");
Console.WriteLine($"OS={System.Runtime.InteropServices.RuntimeInformation.OSDescription}");
Console.WriteLine($"Long Time Pattern={new System.Globalization.CultureInfo("en-US").DateTimeFormat.LongTimePattern}");
// This file was initially generated by Windows Terminal 1.1.2233.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@philipmat
philipmat / FindFileLockingProcess.ps1
Created July 2, 2021 13:04
Finds process that locks a given file
[cmdletbinding()]
param(
[Parameter(Position=1, Mandatory = $true)] # Position = 1 allow passing without specifying -FileOrFolderPath
[String] $FileOrFolderPath
)
If((Test-Path -Path $FileOrFolderPath) -eq $false) {
Write-Warning "File or directory does not exist."
}
Else {
@philipmat
philipmat / DetermineNetframeworkVersion.ps1
Created July 2, 2021 13:03
Lists all available .NET Framework versions
<#
The sample scripts are not supported under any Microsoft standard support
program or service. The sample scripts are provided AS IS without warranty
of any kind. Microsoft further disclaims all implied warranties including,
without limitation, any implied warranties of merchantability or of fitness for
a particular purpose. The entire risk arising out of the use or performance of
the sample scripts and documentation remains with you. In no event shall
Microsoft, its authors, or anyone else involved in the creation, production, or
delivery of the scripts be liable for any damages whatsoever (including,
without limitation, damages for loss of business profits, business interruption,
@philipmat
philipmat / mac.ahk
Last active July 2, 2021 12:40
Mac keys AHK script
#SingleInstance force
; Revert mouse direction
; #MaxHotkeysPerInterval 400
; WheelDown::WheelUp
; WheelUp::WheelDown
; Allow Shift+Caps to toggle Caps
+Capslock::Capslock
; Remap capslock to control
Capslock::Ctrl
@philipmat
philipmat / ConvertTo-Base64.ps1
Last active November 17, 2020 17:56
ConvertTo-Base64 - Powershell script
<#
.SYNOPSIS
Converts a file to BASE64 encoding and displays the encoded content.
.PARAMETER InputFile
The file to be converted to Base64. Displays the encoded string to output (see -ToJson)
.PARAMETER ToJson
Instead of displaying the raw Base64, it outputs a JSON-formatted object.
@philipmat
philipmat / MyExtensions.cs
Last active September 11, 2020 15:50
LINQPad Extension Methods
// requires:
// Newtonsoft.Json
// System.Data.SqlClient
void Main() {
// Write code to test your extensions here. Press F5 to compile and run.
}
public static class MyExtensions {
public static void ShowSqlPrint(this System.Data.Common.DbConnection thisConnection) {
((System.Data.SqlClient.SqlConnection)thisConnection).InfoMessage += (object obj, SqlInfoMessageEventArgs e) => {
@philipmat
philipmat / IAmUpResponder.cs
Created September 11, 2020 14:43
Socket responder - Listens on a socket for incoming connections and responds with "I Am Up" html.
void Main()
{
IamupResponder.StartListening();
return;
}
/// <summary>
/// Listens on a socket for incoming connections and responds with "I Am Up" html.
/// </summary>
/// <remarks>
/// Inspired by:
@philipmat
philipmat / HttpListener.cs
Created September 11, 2020 14:41
HTTP Listener - creates a netcat-like listener on a local port. Returns 201 to all requests
void Main() {
var cts = new CancellationTokenSource();
var task = StartListener(cts.Token);
do {
Thread.Sleep(1);
} while (true);
cts.Cancel();
@philipmat
philipmat / Create LocalDB Databases.linq
Created September 11, 2020 14:32
Create or Attach SQL Database (for LocalDB) - LINQPad script
<Query Kind="Statements">
<Connection>
<ID>3a5c9133-61a0-4989-b34a-b0b4b3967c7f</ID>
<Persist>true</Persist>
<Server>(localdb)\localdev</Server>
<Database>master</Database>
</Connection>
</Query>
// Example: