Skip to content

Instantly share code, notes, and snippets.

function Add-Numbers($a, $b) {
return $a + $b
}
Describe "Add-Numbers" {
$testCases = @(
@{ a = 2; b = 3; expectedResult = 5 }
@{ a = -2; b = -2; expectedResult = -4 }
@{ a = -2; b = 2; expectedResult = 0 }
@{ a = 'two'; b = 'three'; expectedResult = 'twothree' }
def sumInRange(nums, queries)
sum = 0
startIndices = {}
endIndices = {}
m = 1000000007
queries.each do |q|
startIndices[q[0]].nil? ? startIndices[q[0]] = 1 : startIndices[q[0]] += 1
endIndices[q[1]].nil? ? endIndices[q[1]] = 1 : endIndices[q[1]] += 1
end
@markhallen
markhallen / sanitize_filename
Last active September 19, 2018 12:50
Remove characters that are invalid for file names
[System.IO.Path]::GetInvalidFileNameChars() | % {$text = $text.replace($_,'.')}
@markhallen
markhallen / amplitude_data_tags.js.coffee
Created October 15, 2018 10:35
Use data-log in tags for amplitude.com events
$(document).on 'turbolinks:load', ->
$("a[data-log]").click (event) ->
logEvent = $(this).data("log")
amplitude.getInstance().logEvent(logEvent)
@markhallen
markhallen / Install-Font.ps1
Created October 30, 2018 14:01
Install font files in Windows 10. Font files should be in the same folder as the script file.
$shell = New-Object -ComObject Shell.Application
foreach ($font in $shell.Namespace($PSScriptRoot).Items()) {
if (($font.Path).ToLower() -like "*.ttf" -or ($font.Path).ToLower() -like "*.otf" -or ($font.Path).ToLower() -like "*.ttc") {
if (-not (Test-Path ($env:windir + "\Fonts\" + $font.Path.Split("\")[-1]) -ErrorAction SilentlyContinue)) {
$font.InvokeVerbEx("Install")
}
}
}
<#
.SYNOPSIS
Uninstall an application based on the exact name in Programs and Features
.DESCRIPTION
Will accept a DisplayNamee value that will be searched for in Programs and Features.
.PARAMETER DisplayName
The DisplayName as it found in Programs and Features
.PARAMETER LogPath
[Optional] Full path to the client logs folder
.PARAMETER LogName
Function Remove-ApplicationByDisplayName
{
<#
.SYNOPSIS
Remove an application from Windows
.DESCRIPTION
Will accept a DisplayName value that will be searched for in Programs and Features and will
uninstall the applicationg.
.PARAMETER DisplayName
The DisplayName as it found in Programs and Features
function Get-ArpPropertyByDisplayName {
<#
.SYNOPSIS
Get an application property from Programs and Features
.DESCRIPTION
Will accept a DisplayName value that will be searched for in Programs and Features and will
return the property.
.PARAMETER DisplayName
The DisplayName as it found in Programs and Features
.NOTES
class CommandString {
[String]$Command
CommandString([String]$Command)
{
$this.Command = $Command
}
[String] ToUninstall()
{
<#
.SYNOPSIS
Uninstall a package when the original source media is unavailable locally.
.DESCRIPTION
A new location will be added to SOURCELIST so that Windows Installer can locate the media. The script uses MSI files
located in the current directory or Path and will set an additional SOURCELIST for each before attempting to uninstall.
.PARAMETER Path
[Optional] This is the folder that will contain the Windows Installer source.