Skip to content

Instantly share code, notes, and snippets.

View craibuc's full-sized avatar

Craig Buchanan craibuc

View GitHub Profile
@craibuc
craibuc / Dossier.postman_collection.json
Created October 30, 2024 13:41
Postman collection for AMCS Dossier's API
{
"info": {
"_postman_id": "ac34d3cd-cf5f-4fcd-a14d-82a67c355a0e",
"name": "Dossier",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "7408972",
"_collection_link": "https://grey-moon-4259.postman.co/workspace/Dossier~6b685c39-5800-43e8-80bf-a86a9fda4011/collection/7408972-ac34d3cd-cf5f-4fcd-a14d-82a67c355a0e?action=share&source=collection_link&creator=7408972"
},
"item": [
{
@craibuc
craibuc / OutlookMacros.bas
Created December 8, 2022 20:23
Empty deleted items and junk folders
'
' macro's entry point
'
Public Sub EmptyJunkTrash()
EmptyFolder (olFolderJunk)
EmptyFolder (olFolderDeletedItems)
End Sub
@craibuc
craibuc / Get-RemoteItem.ps1
Created January 25, 2022 19:57
Recursively retrieve the files and folders from a remote resource.
<#
.SYNOPSIS
Recursively retrieve the files and folders from a remote resource.
.PARAMETER Uri
The URI of the remote item.
.PARAMETER Destination
The path to folder that will contain the files and folders that are fetched from the Uri. Default: ~/Downloads
@craibuc
craibuc / Organize.ps1
Created January 19, 2020 19:51
Organize media files by month and year
# get all media files in the curret directory
Get-ChildItem * -File -Include *.jpg, *.png, *.mp4 |
# sort them by date created (not necessary)
Sort-Object CreationTime |
# process each file
ForEach-Object {
Write-Debug $_.Name
# year and month of file's creation date
$yyyymm = $_.CreationTime.ToString('yyyy-MM')
@craibuc
craibuc / Timespans.sql
Last active January 28, 2016 22:22
Generate timespans that can used in place of UNIONs when working with dates.
/*
Author: Craig Buchanan
Purpose: Generate timespans (date ranges); timespans are aligned with monthly boundaries
Parameters:
:periods - number of timespans to generate
:length - length of each timespan, in months
:offset - spacing between timespans, in months
:ending_on - the most-recent timespan should end on this date; supports date strings (e.g. '12/31/2015') and symbolic values (e.g. 'ME-1')
Revisions:
01/05/16 - CB - created
Write-Host "Executing $($MyInvocation.MyCommand.Name)..."
##
# variables
#
Write-Host "`nSetting environment variables..."
$ProfileFolder = Split-Path -path $Profile
# PS> cd $modules
@craibuc
craibuc / Pivot.snippet
Created January 14, 2015 16:06
Sql Server Management Studio (SSMS) 2012, Pivot, surround snippet.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<_locDefinition xmlns="urn:locstudio">
<_locDefault _loc="locNone" />
<_locTag _loc="locData">Title</_locTag>
<_locTag _loc="locData">Description</_locTag>
<_locTag _loc="locData">Author</_locTag>
<_locTag _loc="locData">ToolTip</_locTag>
<_locTag _loc="locData">Default</_locTag>
</_locDefinition>
@craibuc
craibuc / CTE.snippet
Created January 14, 2015 15:53
Sql Server Management Studio (SSMS) 2012, common-table expression (CTE), surround snippet.
<!--
Purpose: wrap the selected SQL with <alias> AS ( <sql> )
Installation: remove comments; add to C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\SQL\Snippets\1033\Function
-->
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<_locDefinition xmlns="urn:locstudio">
<_locDefault _loc="locNone" />
<_locTag _loc="locData">Title</_locTag>
<_locTag _loc="locData">Description</_locTag>
@craibuc
craibuc / ExportHtml.applescript
Created January 8, 2015 16:10
Export all Excel sheets (tabs) as individual HTML documents
set theSource to choose file with prompt "Choose file:" default location (path to desktop) of type {"XLS", "XLSX"}
set theDestination to (choose folder with prompt "Choose destination folder:" default location path to desktop)
set thePath to (theDestination as text) & "output.HTML"
tell application "Microsoft Excel"
activate
open theSource
tell active workbook
save as active sheet filename thePath file format HTML file format
end tell
--
-- Purpose: Converts a path to a list
-- Parameters:
-- thePath - text - format Users:craibuc:Desktop:foobar.txt
-- Returns: List
-- Usage:
-- on splitPath("Users:craibuc:Desktop:Output:data.xlsx")
-- (*thePath:Users, craibuc, Desktop, Output, data.xlsx, theFile:foobar.txt theName:foobar, theExtension:txt*)
--
on splitPath(theFilePath)