Skip to content

Instantly share code, notes, and snippets.

View TLaborde's full-sized avatar

Thomas Laborde TLaborde

View GitHub Profile
$global:queue = [System.Collections.Queue]::Synchronized( (New-Object System.Collections.Queue) )
foreach($item in $jobInput)
{
$global:queue.Enqueue($item)
}
$global:resultCode = [hashtable]::Synchronized(@{})
function RunJobFromQueue {
function Get-ScreenShot([Int]$TopRightX,[Int]$TopRightY,[Int]$BottomLeftX,[Int]$BottomLeftY, [string]$Name) {
$bounds = [Drawing.Rectangle]::FromLTRB($TopRightX,$TopRightY, $BottomLeftX,$BottomLeftY)
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$screenCapturePathBase = "$pwd\$name.png"
if (Test-Path $screenCapturePathBase) {
Remove-Item $screenCapturePathBase
}
@TLaborde
TLaborde / gist:22359e9029f3bc03872c208406d64d5d
Created April 12, 2016 07:38
Using powershell for "realtime" notification on a dashboard
As requested on reddit, here is some information about how i made a "realtime" dashboard.
Flow
===
1. a task grab data with a scheduled job. It saves the data in json in two places: one static folder, which overwrite existing data, and in a temporary folder, to be a new "event".
2. a websocket deamon (websocketd) run a powershell script listening to changes in the temporary folder. When a change happens, the new data is read and sent thru the websocket
3. the frontend update the data with what came thru the websocket. If the browser does not support websocket, it will instead pull the data from time to time
Grabbing Data and saving as JSON