Skip to content

Instantly share code, notes, and snippets.

View rikwatson's full-sized avatar

Rik Watson rikwatson

View GitHub Profile
@rikwatson
rikwatson / Use Microsoft Approved Verbs.md
Created February 25, 2015 14:09
Coding Standard: All PowerShell commands should have MS approved verbs.

Use Microsoft Approved Verbs

All PowerShell commands should have MS approved verbs. The list of verbs can be obtained from >_ get-verb To verify you can use:

>_ $approvedVerbs = get-verb | foreach {$_.verb}
>_ $myVerbs = get-command -module MyModule | foreach {$_.verb}

Does MyModule export functions with unapproved verbs?

>_ ($myVerbs | foreach {$approvedVerbs -contains $_}) -contains $false

@rikwatson
rikwatson / xinitrc
Last active November 18, 2016 14:13
/boot/xinitrc for Raspberry PI in Kiosk mode
#!/bin/sh
while true; do
# Clean up previously running apps, gracefully at first then harshly
killall -TERM chromium 2>/dev/null;
killall -TERM matchbox-window-manager 2>/dev/null;
sleep 2;
killall -9 chromium 2>/dev/null;
killall -9 matchbox-window-manager 2>/dev/null;
# Clean out existing profile information
function _Confirm-Zip-Entry
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position = 0)]
[string]
[ValidateScript({ Test-Path $_ })]
$zipFilename,
[Parameter(Mandatory=$true, Position = 1)]
function _Extract-DTPROJ
{
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]
[ValidateScript({ Test-Path $_ })]
$solution
)
@rikwatson
rikwatson / clock.html
Created June 17, 2015 14:05
A clock, in a single HTML page. Moves round the screen so no screen burnin
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
window.CoolClock = function(canvasId,displayRadius,skinId,showSecondHand,gmtOffset) {
return this.init(canvasId,displayRadius,skinId,showSecondHand,gmtOffset);
@rikwatson
rikwatson / titleCase.js
Created June 25, 2015 09:53
To Title Case
/*
* To Title Case 2.1 – http://individed.com/code/to-title-case/
* Copyright © 2008–2013 David Gouch. Licensed under the MIT License.
* http://leancrew.com/all-this/2015/06/title-case-in-drafts/
*/
String.prototype.toTitleCase = function(){
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title){
@rikwatson
rikwatson / DebugMessage.ps1
Created July 9, 2015 15:10
Write to diagnosotics debug via .NET
function DebugMessage($message){
[System.Diagnostics.Debug]::WriteLine("myApp:$message")
}
@rikwatson
rikwatson / remote.ps1
Created July 13, 2015 13:15
Remote PowerShell Automation
$cred = Get-Credential
Enter-PSSession -ComputerName my-vm.cloudapp.net -port 5986 -UseSSL -Credential $cred
@rikwatson
rikwatson / pretty-print-json.sh
Created March 29, 2016 09:51
Pretty Print JSON
python -mjson.tool < ugly.json > pretty.json
func fooGuard(x: Int?) {
guard let x = x where x > 0 else {
// Value requirements not met, do something
return
}
// Do stuff with x
x.description
}