Skip to content

Instantly share code, notes, and snippets.

View TangChr's full-sized avatar

Christian Tang TangChr

View GitHub Profile
@TangChr
TangChr / RemoveOldModules.ps1
Last active April 29, 2021 09:35
PowerShell method to remove old versions of installed modules
function Remove-OldModules
{
Write-Prompt "------------------------------------------" -ForegroundColor Cyan
Write-Prompt "Removing old versions of installed modules" -ForegroundColor Cyan
Write-Prompt "------------------------------------------" -ForegroundColor Cyan
$modules = Get-InstalledModule
Write-Prompt "$($modules.count) module(s) found." -ForegroundColor Yellow
Write-Prompt ""
foreach ($module in $modules)
@TangChr
TangChr / .gitconfig
Last active August 6, 2018 06:18
Adding Visual Studio Code to .gitconfig
[core]
editor = "code --wait"
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = "code --wait --diff $LOCAL $REMOTE"
[merge]
@TangChr
TangChr / Test-IsAdmin.ps1
Last active March 15, 2022 20:52
Check if Command window is running with administrator permissions
function Test-IsAdmin {
try {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal -ArgumentList $identity
return $principal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )
} catch {
throw "Failed to determine if the current user has elevated privileges. The error was: '{0}'." -f $_
}
<#
@TangChr
TangChr / cmd_here.reg
Created July 26, 2016 14:53
Registry: Add "Open in cmd" shortcut to Windows Explorer’s Context Menu
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd_here]
@="Open cmd here"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd_here\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\Directory\shell\cmd_here]
@TangChr
TangChr / aliases.txt
Last active July 20, 2019 16:18
Git Aliases
[alias]
ec = config --global -e
br = branch
sa = !git add --all
ca = !git add --all && git commit -m
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
lrb = !git remote -v
co = checkout
cob = checkout -b
crb = !git cob $1 && git push origin -u
@TangChr
TangChr / .travis.yml
Last active March 2, 2017 15:57
Travis CI: Build and test Jekyll website using HTMLProofer
language: ruby
rvm: 2.3.3
branches:
only:
- master
script: bundle exec rake test
@TangChr
TangChr / clean-jekyll.cmd
Created June 18, 2016 14:19
Batch: Delete all Jekyll-related files and folders created during run time
rmdir _site /s /q
rmdir .sass-cache /s /q
del Gemfile.lock
@TangChr
TangChr / slated-corners.scss
Last active December 17, 2020 15:12
Slated corners with SASS
@mixin slated-top-left($size, $foreground, $background) {
content: '';
position: absolute;
width: 0;
top: 0;
left: 0;
border-top: $size solid $background;
border-right: $size solid $foreground;
}
@TangChr
TangChr / archive.html
Last active June 6, 2016 08:42
Liquid/Jekyll: Monthly Archive
<ul class="post-archive">
{% for p in site.posts %}
<li>
{% assign fdate = p.date | date: '%b %Y' %}
{% if cur_date != fdate %}
{% assign cur_date = fdate %}
<h3>{{ p.date | date: '%B, %Y' }}</h3>
{% endif %}
<a href="{{ p.url }}">{{ p.title }}</a>
</li>
@TangChr
TangChr / session-activator.php
Last active December 11, 2015 23:05
PHP: Enable sessions ($_SESSION) in WordPress plugins and themes
<?php
/*
Plugin Name: Session Activator
Description: Enable the use of sessions ($_SESSION) in plugins and themes.
Version: 1.0.0
Author: Christian Tang
Author URI: http://christiantang.dk
*/
add_action('init', 'session_activator_start', 1);
add_action('wp_logout', 'session_activator_end');