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 / README.md
Created February 22, 2024 22:23
Installing Markdown Preview on LunarVim on Windows

To install Markdown Preview in LunarVim on Windows, follow these steps:

In config.lua add the following to your lvim.plugins table:

{
    "iamcco/markdown-preview.nvim",
    cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
    ft = { "markdown" }
}
@tahir-hassan
tahir-hassan / info.md
Created January 6, 2023 13:04
WezTerm - Configuration to send Control-w in response to Control-Backspace

On Windows, you should be able to create a .wezterm.lua in $HOME (which is really just $HOMEDRIVE + $HOMEPATH).

Here is a sample .wezterm.lua which sends a Control-w in response to Control-Backspace, useful for deleting a word behind the cursor:

local wezterm = require 'wezterm'
local act = wezterm.action

return {
@tahir-hassan
tahir-hassan / init.lua
Created November 21, 2022 23:35
For NeoVim, converting an init.vim to an init.lua
vim.o.breakindent = true
vim.o.linebreak = true
vim.o.number = true
vim.o.relativenumber = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.expandtab = true
@tahir-hassan
tahir-hassan / Set-PSConsoleReadLineSelectionState.ps1
Created February 27, 2022 23:39
`PSConsoleReadLine` has a `GetSelectionState` method but no `SetSelectionState` method. `Set-PSConsoleReadLineSelectionState` will enable you to set the selection state and also specify if the selection was done backwards or forwards (by default it is forwards).
Function Set-PSConsoleReadLineSelectionState
{
param(
[Parameter(Mandatory)][int]$Start,
[Parameter(Mandatory)][int]$Length,
[ValidateSet('Backward', 'Forward')][string]$Direction='Forward'
)
$startCursorPosition,$selectChar = switch ($Direction)
{
@tahir-hassan
tahir-hassan / AltF4ToExit.ps1
Last active September 8, 2021 00:18
A script that enables you to use Alt+F4 to exit the PowerShell instance.
Set-PSReadLineKeyHandler -Key 'Alt+F4' `
-BriefDescription ExitPowerShell `
-LongDescription "Exits PowerShell" `
-ScriptBlock {
param($key, $arg)
$line = $null;
$cursor = $null;
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $line, [ref] $cursor);
[Microsoft.PowerShell.PSConsoleReadLine]::Delete(0, $line.Length);
@tahir-hassan
tahir-hassan / GetCircleFromPoints.ps1
Created July 18, 2021 17:01
PowerShell code to get a circle from three points on an arc.
class Point {
[double]$X;
[double]$Y;
Point([double]$x, [double]$y) {
$this.X = $x;
$this.Y = $y;
}
[Point]Add([double]$xDelta, [double]$yDelta) {
@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;
@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 / 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 / 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) {