Skip to content

Instantly share code, notes, and snippets.

View tahir-hassan's full-sized avatar

Tahir Hassan tahir-hassan

View GitHub Profile
@tahir-hassan
tahir-hassan / Start-UserProcess.ps1
Last active August 23, 2017 14:45
PowerShell wrapper for runas.exe (Start-UserProcess)
# this does not support all the features of runas.exe, but is a first stab
Function Start-UserProcess {
param([Parameter(Mandatory=$true)][string]$Username, [switch]$SaveCredentials, [Parameter(Mandatory=$true)][string]$Program, [string[]]$ArgumentList)
$program = & {
if ($ArgumentList) {
((& { $Program; $ArgumentList }) | foreach { "\`"$_\`"" }) -join " "
} else {
"`"$Program`"";
}
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Showdown and Highlight JS</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.5/styles/default.min.css" />
<style>
xmp.hide {
display: none;
@tahir-hassan
tahir-hassan / anki-showdown-hljs-v1.html
Last active March 28, 2019 13:04
Anki -- Using Showdown and HighlightJS for a solution that works across both Anki Desktop and AnkiDroid (version 1)
<div class="front-content">
{{Front}}
</div>
<script>
function addStylesheet(src, callback) {
var s = document.createElement('link');
s.rel = 'stylesheet';
s.href = src;
s.onload = callback;
document.head.appendChild(s);
@tahir-hassan
tahir-hassan / snippetsformat.xsd
Last active September 30, 2019 12:17
Based on `snippetformat.xsd`, this one allows multiple <Shortcut> elements. Files of this type will be processed to produce many `.snippet` files, one for each <Shortcut> element.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://tahirhassan.blogspot.com/VisualStudio/2005/CodeSnippets"
xmlns="https://tahirhassan.blogspot.com/VisualStudio/2005/CodeSnippets">
<xs:element name="CodeSnippets" xmlns="https://tahirhassan.blogspot.com/VisualStudio/2005/CodeSnippets">
<xs:annotation>
<xs:documentation><!-- _locID_text="CodeSnippets" _locComment="" -->Groups CodeSnippet elements. The CodeSnippets element is the root element of the code snippet XML schema.</xs:documentation>
</xs:annotation>
<xs:complexType>
@tahir-hassan
tahir-hassan / Invoke-XslTransform.ps1
Created October 1, 2019 10:27
PowerShell function `Invoke-XslTransform` for invoking an XSLT
# source: https://paregov.net/blog/19-powershell/24-xslt-processor-with-powershell
function Invoke-XslTransform {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$StylesheetUri
, [Parameter(Mandatory = $true)][string]$InputUri
, [string]$Destination
, [switch]$PassThru
, [switch]$Overwrite
@tahir-hassan
tahir-hassan / CodeSnippetsWithMultipleShortcuts.xsl
Created October 1, 2019 10:41
I like to have code snippets with multiple shortcuts rather than a single one. Therefore I have an XSD, which is a copy and paste of the Microsoft one, but allowing multiple shortcut elements. I have an XSL transformation that processes it into a form that Visual Studio will understand.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="https://tahirhassan.blogspot.com/VisualStudio/2005/CodeSnippets" xmlns:vs="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet" version="1.0">
<xsl:template match="/">
<vs:CodeSnippets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:for-each select="/t:CodeSnippets/t:CodeSnippet/t:Header/t:Shortcut">
<vs:CodeSnippet Format="1.0.0">
<xsl:variable name="shortcut" select="."/>
<xsl:for-each select="..">
<xsl:element name="vs:{local-name()}">
<xsl:apply-templates select="@*|node()[not(self::t:Shortcut)]"/>
@tahir-hassan
tahir-hassan / pull.ps1
Created November 10, 2019 13:05
"Pulling release files"
param()
$projectPath = "C:\_code\Clock\Clock";
$debugDir = "$projectPath\bin\Debug";
$releaseDir = "$projectPath\bin\Release";
$debugClockExe = Get-Item $debugDir\Clock.exe;
$releaseClockExe = Get-Item $releaseDir\Clock.exe;
if ($releaseClockExe.LastWriteTime -gt $debugClockExe.LastWriteTime) {
@tahir-hassan
tahir-hassan / elevate.ps1
Created November 29, 2019 17:19
PowerShell script, when invoked, will open a new elevated window. The idea is to keep this script in a directory to the PATH environment variable.
param()
$ErrorActionPreference = 'Stop';
Start-Process -Verb runAs -ArgumentList '-NoExit','cd',(Get-Item .).FullName powershell
@tahir-hassan
tahir-hassan / OpenPowerShellHere.reg
Last active November 29, 2019 18:11
Explorer Context Menu for opening PowerShell in that directory. This also includes elevated options. Base on https://stackoverflow.com/a/24603961/288393
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenPowerShellHere]
@="Open PowerShell here"
"Icon"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenPowerShellHere\command]
@="powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
[HKEY_CLASSES_ROOT\Directory\shell\OpenPowerShellHere]
@tahir-hassan
tahir-hassan / NetCoreCSOM.AuthenticationManager.cs
Created August 4, 2020 18:59
This `AuthenticationManager` class is based on one found at https://www.c-sharpcorner.com/article/sharepoint-csom-for-net-standard/. It authenticates using a client ID and secret that you can set up within Sharepoint. It uses information found in https://www.anexinet.com/blog/getting-an-access-token-for-sharepoint-online/ to get the token. You n…
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;