Skip to content

Instantly share code, notes, and snippets.

View philipmat's full-sized avatar

Philip Mateescu philipmat

View GitHub Profile
@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 / Exported-2017-12-27.vssettings
Created December 27, 2017 16:14
Visual Studio 2017 Settings
<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 August 21, 2017 13:30
Unix `touch` in Powershell
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 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 / String Concat.cs
Created July 26, 2017 19:52
Speed of String Concatenation
var s1 = string.Empty;
var s2 = new List<string>();
var s3 = new System.Text.StringBuilder();
var sw = new Stopwatch();
const string Message = "Hello I am string number {0}";
sw.Restart();
for (int i = 0; i < 30; i++) {
s1 += string.Format(Message, i) + "\n";
@philipmat
philipmat / dropfk.sql
Created July 26, 2017 19:50
MSSQL - Drop FK
SET NOCOUNT ON
GO
DECLARE Fkeys CURSOR FOR
SELECT 'ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']'
FROM information_schema.table_constraints
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
OPEN Fkeys
@philipmat
philipmat / Routing.linq
Last active July 22, 2017 13:36
Simple Message Routing: Static vs Dynamic
<Query Kind="Program">
<NuGetReference>Autofac</NuGetReference>
<Namespace>Autofac</Namespace>
</Query>
void Main()
{
var facker = Configure();
// example 1
@philipmat
philipmat / Results.md
Created April 13, 2017 19:53
MSSQL Generated Columns and LINQPad

** TestGenerated Contents **

Id            Value1         SysStartTime                   SysEndTime
1             1              4/13/2017 19:17                12/31/9999 23:59
2             2              4/13/2017 19:17                12/31/9999 23:59

** TestGenerated Columns **

@philipmat
philipmat / manifest_helper.py
Last active October 12, 2016 20:53
Destiny scripting helpers
import requests, zipfile, os, json
def get_manifest():
manifest_url = 'https://www.bungie.net/Platform/Destiny/Manifest/'
#get the manifest location from the json
r = requests.get(manifest_url)
manifest = r.json()
mani_url = 'https://www.bungie.net'+manifest['Response']['mobileWorldContentPaths']['en']
@philipmat
philipmat / namecheap_alias_importer.py
Created July 7, 2016 19:11
NameCheap Alias Importer
#!/usr/bin/env python3
import csv, requests, sys, os, urllib.parse, configparser
from xml.etree import ElementTree
# CSV="Selected List.csv"
CSV=None
CONFIG="config.ini"
EXTERNAL_IP_API="http://myexternalip.com/raw"
EXTERNAL_IP=None
API_KEY="ApiUser={user}&ApiKey={key}&UserName={user}"