Skip to content

Instantly share code, notes, and snippets.

View royashbrook's full-sized avatar

Roy Ashbrook royashbrook

View GitHub Profile
@royashbrook
royashbrook / jiggle.ps1
Created May 5, 2021 12:01
jiggles the mouse a little
#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 13:22
Post a text file to a discord webhook
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 April 19, 2021 14:16
Retrieve async job data using a web server
$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++) {
@royashbrook
royashbrook / random-oh-my-posh-theme-for-profile.ps1
Created April 13, 2021 21:14
Set a random Oh My Posh theme
#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 April 13, 2021 17:21
Set STES so machine won't sleep
# 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(){
@royashbrook
royashbrook / Jiggle.ps1
Created April 13, 2021 17:18
Jiggle the mouse
#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 November 9, 2020 02:01
Google App Script for Stripe Client Keys
// 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 September 16, 2020 14:09
From JSZip to unzipit
//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 September 4, 2020 19:24
Button Handler to download some JSON as CSV
//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 = []
@royashbrook
royashbrook / Animation.js
Last active September 4, 2020 19:38
ChartJS Bar Chart Label Plugin
//comments in blogpost
myoptions.events = []
myoptions.animation = {
duration: 0,
onComplete: function () {
let chartInstance = this.chart
let ctx = chartInstance.chart.ctx
ctx.textAlign = 'center'
function formatLabel(value) {