Skip to content

Instantly share code, notes, and snippets.

View dfinke's full-sized avatar

Doug Finke dfinke

View GitHub Profile
function Save-JsonToExcel {
<#
.SYNOPSIS
Saves a JSON string to an Excel file.
.PARAMETER Json
The JSON string to save.
.PARAMETER Path
The path to save the Excel file to.
#>
param(
$config = @{
Preferences = @{
defaultAgent = "StockAgent"
}
WebSearchAgent = @{
Name = "WebSearch"
LLM = New-OpenAIChat 'gpt-4o-mini'
Instructions = "Today is $(Get-Date)"
@dfinke
dfinke / fafo.ps1
Last active November 13, 2024 01:59
function map {
param(
$func,
[Parameter(ValueFromRemainingArguments = $true)]
$arrays
)
$arrays | ForEach-Object {
if ($arrays[0].Length -ne $_.Length) {
throw "All arrays must be of the same length"
$text1 = Read-Host "Enter text"
Set-Clipboard -Value $text1
$text2 = Get-Clipboard
$text2
@dfinke
dfinke / ExcelPlots.ps1
Created September 20, 2024 13:43
Create Excel bar chart using PowerShell by repeating symbols based on values with custom styling
$data = ConvertFrom-Csv @"
Name,UnitsSold
John,100
Jane,200
Tom,120
Jane,300
Jim,150
Mary,250
"@
@dfinke
dfinke / Invoke-GitHubChat.ps1
Last active September 20, 2024 02:02
PowerShell script for querying AI models via GitHub API and retrieving chat completions
$prompt = "capital of france?"
$model = "gpt-4o-mini"
# $model = "o1-preview"
$headers = @{
    "Content-Type"  = "application/json"
    "Authorization" = "Bearer $($env:GITHUB_TOKEN)"
}
$body = @{
@dfinke
dfinke / Get-WorkSummary.ps1
Created September 14, 2024 23:10
PowerShell script lists recent files; AI analyzes your work—instantly see what you've accomplished!
param(
$daysOld = 7
)
$targetDir = $(
'D:\mygit\GPTIdeas\Experiments\Livestream-GPT\'
'D:\mygit\PowerShellAIAssistant-ScratchPad'
'D:\mygit\PSAI'
'D:\mygit\PSAIAgent-Stealth-2\'
'D:\temp\Camtasia\scratch\'
@dfinke
dfinke / Show-ExcelSumProduct.ps1
Last active September 9, 2024 08:35
This script exports CSV data to an Excel file, formats it, and applies a SUMPRODUCT formula.
$sumData = ConvertFrom-Csv @"
ProductName, VendorName, TotalSales
Macbook, Apple
Desktop, DELL
RAM, Lenovo
HDD, HCL
Laptop, IBM
Mouse, Acer
"@
@dfinke
dfinke / Show-GitLikeDiff.ps1
Created August 25, 2024 18:31
Git-like Diff Tool in PowerShell
# Git-like Diff Tool in PowerShell
function Compare-Files {
param (
[string]$OldFilePath,
[string]$NewFilePath,
[int]$ContextLines = 3
)
$oldFile = Get-Content -Path $OldFilePath
@dfinke
dfinke / Compare-PicsUsingAI.ps1
Last active August 10, 2024 17:18
AI-powered image comparison in PowerShell using PSAI module
# Install-module PSAI
# Get OpenAI API key from https://platform.openai.com/account/api-keys
# Set $env:OpenAIKey
function Compare-PicsUsingAI {
param(
$pic1,
$pic2
)