Skip to content

Instantly share code, notes, and snippets.

Avatar

Roy Ashbrook royashbrook

View GitHub Profile
@royashbrook
royashbrook / migrategitfromazuredevopstogithub.ps1
Created May 5, 2021
Migrate git repos from Azure Devops to github
View migrategitfromazuredevopstogithub.ps1
# how i moved all of my git repos from azure devops to github
# prereqs
# azure cli - https://docs.microsoft.com/en-us/cli/azure
# github cli - https://cli.github.com/
# note: you can get away with neither of these if you want
# to manually make some lists and repos yourself
# we'll be creating local clones of everything to work with
@royashbrook
royashbrook / jiggle.ps1
Created May 5, 2021
jiggles the mouse a little
View jiggle.ps1
#no idea why, but i thought this was kind of funny
#get our winform stuff
$null = [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$null = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#move the mouse on x
function Nudge($p){
[System.Windows.Forms.Cursor]::Position = `
[System.Drawing.Point]::New( `
@royashbrook
royashbrook / Submit-TextFile.ps1
Created May 4, 2021
Post a text file to a discord webhook
View Submit-TextFile.ps1
function Submit-TextFile($filePath,$Uri){
$filename = (Get-ChildItem $filePath).Name
$filecontents = Get-Content $filePath -raw
$boundary = [guid]::NewGuid().ToString()
$contentinfo = "Content-Disposition: form-data; name=`"file`"; filename=`"$filename`"`nContent-Type: text/html; charset=utf-8`n"
$body = "--$boundary`n$contentinfo`n$filecontents`n--$boundary--`n"
$params = @{
Uri = $Uri
Body = $body
Method = 'Post'
@royashbrook
royashbrook / GetAsyncJobInfoUsingWS.ps1
Created Apr 19, 2021
Retrieve async job data using a web server
View GetAsyncJobInfoUsingWS.ps1
$sb = {
do{ #pause while server is starting up
$error.Clear()
try{
[Net.Sockets.TcpClient]::new('localhost',8080)
}catch{
Start-Sleep 1
}
}while($error)
for ($i = 0; $i -lt $args[1]; $i++) {
View random-oh-my-posh-theme-for-profile.ps1
#open profile with code $profile or notepad $profile and paste in the following
#note you will need to have installed oh-my-posh already
#see https://ohmyposh.dev/ for details
Import-Module oh-my-posh
function Get-ThemeList{
$themeurl = "https://github.com/JanDeDobbeleer/oh-my-posh/tree/main/themes"
$ProgressPreference = 'SilentlyContinue'
$links = (iwr $themeurl).links
$ProgressPreference = 'Continue'
($links | where title -like *omp.json).title -Replace ".omp.json",""
@royashbrook
royashbrook / Enable-STES.ps1
Created Apr 13, 2021
Set STES so machine won't sleep
View Enable-STES.ps1
# import kernel32 calls we need
# note screen saver will not enable either
# can remove the display required flag to remove that
Add-Type -Name n -Namespace ns -MemberDefinition @'
[DllImport("kernel32.dll")]
public static extern uint SetThreadExecutionState(uint esFlags);
public const uint ES_CONTINUOUS = 0x80000000;
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
public static string StayAwake(){
View Jiggle.ps1
#moves the mouse x location by offset p pixels
function Nudge($p){
[System.Windows.Forms.Cursor]::Position = `
[System.Drawing.Point]::New( `
[System.Windows.Forms.Cursor]::Position.X+$p, `
[System.Windows.Forms.Cursor]::Position.Y )
}
#call nudge every 10ms with pos/neg value of x
function Jiggle(){
@royashbrook
royashbrook / code.gs
Created Nov 9, 2020
Google App Script for Stripe Client Keys
View code.gs
// this is a google script method of getting a client key from stripe
// this means you don't have to get a server to take stripe payments because
// this can be your server. at the time of this script creation, you are
// limited to 20k per month. in order to 'deploy' this you'll have to
// go to https://script.google.com/ and create a new script, replace the
// body of the initial script file with this and then deploy it as a web app
// you'll have to give it the required permissions it asks for the first time
// and ensure you set it up for anonymous access.
// this function will just return the secret key for the client from stripe
@royashbrook
royashbrook / JSZip.js
Created Sep 16, 2020
From JSZip to unzipit
View JSZip.js
//import or add cdn for global, url should be passed in somehow
fetch(url)
.then(r=>r.blob())
.then(JSZip.loadAsync)
.then(zip=>zip.files[Object.keys(zip.files)[0]].async('string'))
.then(JSON.parse)
@royashbrook
royashbrook / downloadjsonascsv.js
Created Sep 4, 2020
Button Handler to download some JSON as CSV
View downloadjsonascsv.js
//bind onclick to downloadcsv.
//o should be the json you want to turn into a table
//h should be a string array for the header row, or this can be null and it will use the keys from the first record
//n is the name of the file, csv will be appended. if omitted it will just be 'data.csv'
export const downloadcsv = (o,h,n = 'data') => {
downloadFile( toCSV(o,h) , n + '.csv', 'text/csv' );
}
const toCSV = (o,h) => {
const a = (v) => `"${v.join(`","`)}"`
let csv = []