Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip Mateescu philipmat

View GitHub Profile
@philipmat
philipmat / IAmUpResponder.cs
Created Sep 11, 2020
Socket responder - Listens on a socket for incoming connections and responds with "I Am Up" html.
View IAmUpResponder.cs
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 Sep 11, 2020
HTTP Listener - creates a netcat-like listener on a local port. Returns 201 to all requests
View HttpListener.cs
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 Sep 11, 2020
Create or Attach SQL Database (for LocalDB) - LINQPad script
View Create LocalDB Databases.linq
<Query Kind="Statements">
<Connection>
<ID>3a5c9133-61a0-4989-b34a-b0b4b3967c7f</ID>
<Persist>true</Persist>
<Server>(localdb)\localdev</Server>
<Database>master</Database>
</Connection>
</Query>
// Example:
@philipmat
philipmat / console.log
Created Feb 15, 2019
Visual Studio Code macOS freeze
View console.log
[main 2019-02-15T22:37:18.094Z] Starting VS Code
[main 2019-02-15T22:37:18.095Z] from: /Users/af59986/Applications/Visual Studio Code.app/Contents/Resources/app
[main 2019-02-15T22:37:18.095Z] args: { _: [],
diff: false,
add: false,
goto: false,
'new-window': false,
'reuse-window': false,
wait: false,
version: false,
@philipmat
philipmat / say.ps1
Last active Dec 9, 2018
say command in Powershell
View say.ps1
[cmdletbinding()]
param(
[Parameter(Position = 1, Mandatory = $true)]
[String]
$message
)
Add-Type -AssemblyName System.Speech
$synth = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$synth.Speak($message)
@philipmat
philipmat / ilog.snippet
Created Feb 22, 2018
Code Snippets for C#
View ilog.snippet
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>ilog</Title>
<Shortcut>ilog</Shortcut>
<Description>Generates a private field to hold a Common.Logging.ILog</Description>
<Author>Philip Mateescu</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@philipmat
philipmat / ConvertTo-Base64.ps1
Last active Nov 17, 2020
ConvertTo-Base64 - Powershell script
View ConvertTo-Base64.ps1
<#
.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.
View Exported-2017-12-27.vssettings
<UserSettings><ApplicationIdentity version="15.0"/><ToolsOptions><ToolsOptionsCategory name="Environment" RegisteredName="Environment"><ToolsOptionsSubCategory name="Documents" RegisteredName="Documents" PackageName="Visual Studio Environment Package"><PropertyValue name="ShowMiscFilesProject">false</PropertyValue><PropertyValue name="AutoloadExternalChanges">true</PropertyValue><PropertyValue name="CheckForConsistentLineEndings">true</PropertyValue><PropertyValue name="SaveDocsAsUnicodeWhenDataLoss">false</PropertyValue><PropertyValue name="InitializeOpenFileFromCurrentDocument">true</PropertyValue><PropertyValue name="ReuseSavedActiveDocWindow">false</PropertyValue><PropertyValue name="DetectFileChangesOutsideIDE">true</PropertyValue><PropertyValue name="DontShowGlobalUndoChangeLossDialog">true</PropertyValue><PropertyValue name="AllowEditingReadOnlyFiles">true</PropertyValue><PropertyValue name="DocumentDockPreference">0</PropertyValue><PropertyValue name="MiscFilesProjectSavesLastNItems">0</PropertyValue>
@philipmat
philipmat / Update-File.ps1
Last active Aug 21, 2017
Unix `touch` in Powershell
View Update-File.ps1
Function Update-File
{
$Usage = "Usage: Update-File [file1 ... fileN]";
# if no arguments, display an error
if ($args.Count -eq 0) {
throw $Usage;
}
# see if any arguments match -h[elp] or --h[elp]
foreach($file in $args) {
if ($file -ilike "-h*" -or $file -ilike "--h*") {
@philipmat
philipmat / MyExtensions.cs
Last active Sep 11, 2020
LINQPad Extension Methods
View MyExtensions.cs
// 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) => {
You can’t perform that action at this time.