Skip to content

Instantly share code, notes, and snippets.

@nzbart
nzbart / Find.ps1
Created March 26, 2014 02:45
Find an remove unused scss variables through basic heuristic. Not particularly fast, but it seems to work okay.
$ourContent = ls $PSScriptRoot\MyCode -r -fi *.scss | cat
$vars = $ourContent | % {
if($_ -match '^\s*\$([a-zA-Z_-]+)\s*:') {
$Matches[1]
}
} | select -Unique
$allContent = ls $PSScriptRoot -r -fi *.scss | cat
$vars | ? {
$search = "\`$$_[^:]*$"
@nzbart
nzbart / ShowSassTree.ps1
Created March 26, 2014 19:38
Show the hierarchy of sass file imports
param([string][parameter(mandatory)]$ParentFile, [string][parameter(mandatory)]$RootFile, [int][parameter(mandatory)]$Depth, [string][parameter(mandatory)]$IncludePath, [switch]$RenderDotFormat, [switch]$DoNotRecurse)
function RenderImports([string][parameter(mandatory)]$ParentFile, [string][parameter(mandatory)]$RootFile, [int][parameter(mandatory)]$Depth, [string][parameter(mandatory)]$IncludePath, [switch]$RenderDotFormat, [switch]$DoNotRecurse)
{
$ErrorActionPreference = 'Stop'
function GetRelativePath([string][parameter(mandatory)]$ParentFile, [string][parameter(mandatory)]$RootFile)
{
pushd (Split-Path -Parent $ParentFile)
try {
@nzbart
nzbart / CreateModernIEVM.ps1
Created April 7, 2014 03:59
Create a Hyper-V virtual machine for a VHD downloaded from http://modern.ie
$vhd = ls *.vhd | select -ExpandProperty Name
if(!$vhd -or $vhd.GetType().FullName -ne 'System.String') {
throw "Expected to find the VHD in the current directory."
}
$vmName = [System.IO.Path]::GetFileNameWithoutExtension($vhd)
Write-Host "Creating VM called $vmName..."
$newVm = New-VM -Name $vmName -MemoryStartupBytes 1024MB -SwitchName External -VHDPath (Resolve-Path $vhd) -Path . -Generation 1 -BootDevice IDE
$newVm | Set-VMProcessor -Count 2
@nzbart
nzbart / IsAdministrator.ps1
Created July 9, 2014 01:59
Determine whether user has administrative privileges in PowerShell
(New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
@nzbart
nzbart / Plotting a chart with R.Net.r
Last active August 29, 2015 14:12
This sample plots a simple chart to a PNG file using the R statistical program and R.Net. It requires the R.NET.Community NuGet package to be installed.
using RDotNet;
/*
d:/temp/plot.r:
suppressPackageStartupMessages(library(ggplot2))
library(ggplot2)
p <- qplot(Sepal.Length, Petal.Length, data = iris, color = Species)
png(filename=fileName, width=500, height=500)
iislog <- read.delim("Filtered.log", header=TRUE, sep=" ")
iislog <- within(v, { localdatetime=as.POSIXct(paste(date, time)) + 13*60*60 })
h <- hist(
iislog$localdatetime,
freq = TRUE,
breaks=24,
xlab = "Time of day",
ylab = "Requests per hour",
axes = F,
@nzbart
nzbart / GetSqlAgentJobs.ps1
Last active August 29, 2015 14:13
Get list of SQL Agent jobs and their corresponding schedules.
#requires -modules sqlps
#requires -version 3
param([string]$ServerToQuery = ([Environment]::MachineName), [PSCredential]$SqlCredential)
$ErrorActionPreference = 'Stop'
pushd
ipmo sqlps -DisableNameChecking
popd
@nzbart
nzbart / Add-TabExpansion.ps1
Created May 14, 2015 00:19
Chain a PowerShell script block to the tabexpansion2 function, calling the original implementation if the new one doesn't return a result.
function Add-TabExpansion
{
param([ScriptBlock][parameter(mandatory)]$ScriptBlock)
$originalFunction = (gcm TabExpansion2).ScriptBlock
$chainedBlock = {
$userResult = & $ScriptBlock @Args
if($userResult) {
return $userResult
}
@nzbart
nzbart / MapKeys.reg
Created May 15, 2015 12:44
Registry file that maps the right Windows key to the Apps (context menu) key, and the scroll-lock key to the numeric keypad asterisk key (one of the most useful keys on the keyboard). These mappings are useful the the tenkeyless (TKL) Coolermaster CM QuickFire Rapid-i keyboard, which comes inexplicably with two Windows keys, and no Apps key. Not…
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,5d,e0,5c,e0,37,00,46,00,\
00,00,00,00
@nzbart
nzbart / CreateGitIgnores.ps1
Last active September 17, 2015 22:17
Creates more optimal .gitignore files. Run from within your repository, and delete any .gitignore files you are not sure about first. You should make sure that all code is committed first.
$ErrorActionPreference = 'Stop'
$filesToIgnore = git status | ? { $_.StartsWith("`t") } | % { $_.SubString(1) } | ? { !$_.StartsWith("deleted:") }
$filesToIgnore | % {
$fileName = [IO.Path]::GetFileName($_)
$directory = [IO.Path]::GetDirectoryName($_)
if($fileName.length -eq 0) {
#The path is actually a directory
$fileName = [IO.Path]::GetFileName($directory) + "/"
$directory = [IO.Path]::GetDirectoryName($directory)