Skip to content

Instantly share code, notes, and snippets.

Stephen Owen 1RedOne

View GitHub Profile
@1RedOne
1RedOne / Foodtrucks.ps1
Last active Mar 3, 2019
Parsing out foodtruck times with PowerShell and REST
View Foodtrucks.ps1
$FoodTruckEvents = Invoke-RestMethod https://www.seattlefoodtruck.com/api/events?page=1&for_locations=51&with_active_trucks=true&include_bookings=true&with_booking_status=approved'
#this endpoint gives us a JSON response with multiple events, so we parse out each event
ForEach ($event in $FoodTruckEvents.events){
#each event seems to be one day, so we resolve the .start_time and make it human readable
$date = Get-Date $event.start_time | Select-Object -ExpandProperty DateTime
#each event could have more than one truck, so we step through them
ForEach ($booking in $event.bookings){
@1RedOne
1RedOne / Readme.md
Last active Jan 17, 2019
Backup of post from reddit
View Readme.md

tribalism

Sure, but if you want to be objective about it you can't deny that one side is more tribal then the other.

@1RedOne
1RedOne / Example.md
Last active Jan 12, 2019
Extracting content from an API from a site
View Example.md

Extracting Content from a site's unpublished API

Imagine that youve found a site that has a perfect list of some info you need, but the site owner's don't have it in a format you can easily use! This happens a lot, but fortunatley for us, if the data can be retrieved and displayed in a web browser, we can normally request that same data directly through a web call instead!

The problem is that the API endpoints we need to hit may not always be published publically.

For instance, this webpage has a lot of good info on beer, but no great way to export it.

https://www.systembolaget.se/sok-dryck/?subcategory=%C3%96l&type=Ale%20brittisk-amerikansk%20stil&style=Imperial%2FDubbel%20IPA&fullassortment=1

@1RedOne
1RedOne / Resolve-UniqueKBRecords.ps1
Created Nov 7, 2018
Search for matching records in a big csv using the .Where Method for speed
View Resolve-UniqueKBRecords.ps1
$csv = ConvertFrom-CSV "ComputerName,KBNeeded
Server01,KB1234567
Server02,KB1234567
Server03,KB1234567
Server04,KB1234567
Server05,KB1234567
Server01,KB3456789
Server01,KB5678910"
$uniquePCs = $csv | Group-Object -Property ComputerName | Select -ExpandProperty Name
@1RedOne
1RedOne / Join-VideoDirectory.ps1
Created Oct 29, 2018
Join Video Files with FFMPEG and PowerShell
View Join-VideoDirectory.ps1
Function Join-VideoDirectory {
$fileArray = New-Object System.Collections.ArrayList
$items = Get-childitem *.mkv,*.vob,*.mp4,*.ts
$itemCount = $items.Count
$i = 0
$cmdScript = ""
ForEach ($item in $items){
$i++
$cmdScript += "ffmpeg -i `"$($item.Name)`" -f mpegts -c copy file-0$i.mpeg.ts`n"
@1RedOne
1RedOne / Lottery.Md
Last active Oct 19, 2018
Why you don't want to win the lottery
View Lottery.Md
@1RedOne
1RedOne / DataGridsAreFun.ps1
Created Sep 20, 2018
WPF Example of using and populating a DataGrid with objects in PowerShell
View DataGridsAreFun.ps1
#Sample for this question on SO https://stackoverflow.com/questions/52405852/link-wpf-xaml-to-datagrid-in-powershell?sem=2
$inputXML = @"
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
@1RedOne
1RedOne / ReadMe.md
Last active Aug 16, 2018
Parsing Malformed HTML via SQL
View ReadMe.md

First off the source HTML has a lot of issues, as we can see here:

'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<STYLE type=text/css> P, UL, OL, DL, DIR, MENU, PRE { margin: 0 auto;}</STYLE>
<META name=GENERATOR content="MSHTML 11.00.10586.35"></HEAD>

<BODY leftMargin=1 topMargin=1 rightMargin=1>
@1RedOne
1RedOne / AddSurNametoUpper.ps1
Last active Aug 8, 2018
A scratch of swapping a dash for a period in AD>
View AddSurNametoUpper.ps1
if ($user.Surname){
"$user has a surname"
$newSurname = $user.Surname.ToUpper()
"changing to $newSurname"
$user | Set-ADUser -Surname $newSurname -WhatIf
}
@1RedOne
1RedOne / Sample.ps1
Created Jul 2, 2018
GUI Post 2 Final XAML
View Sample.ps1
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication2"
mc:Ignorable="d"
Title="FoxDeploy Awesome Tool" Height="416.794" Width="598.474" Topmost="True">
<Grid Margin="0,0,45,0">
<Image x:Name="image" HorizontalAlignment="Left" Height="100" Margin="24,28,0,0" VerticalAlignment="Top" Width="100" Source="C:\Users\Stephen\Dropbox\Docs\blog\foxdeploy favicon.png"/>
You can’t perform that action at this time.