Skip to content

Instantly share code, notes, and snippets.

View matt40k's full-sized avatar

Matt Smith matt40k

View GitHub Profile
@matt40k
matt40k / csv.ps1
Created November 28, 2017 14:54
Get the number of rows and columns from a CSV file
$file = "C:\tmp\test.csv"
$content = Get-Content -Path $file # -Delimiter ","
$noOfColumns = 0
$noOfRows = $content.Count # -1 # Remove header row
foreach ($line in $content)
{
$occurs = Select-String -InputObject $line -Pattern "," -AllMatches
$noOfOccurs = $occurs.Matches.Count + 1
if ($noOfOccurs -gt $noOfColumns)
{
System.IO.IOException: The write operation failed, see inner exception. ---> System.Net.Http.WinHttpException: The connection with the server was terminated abnormally
--- End of inner exception stack trace ---
at Amazon.Runtime.HttpWebRequestMessage.<GetResponseAsync>d__20.MoveNext() in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\HttpHandler\_mobile\HttpRequestMessageFactory.cs:line 432
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.Runtime.Internal.HttpHandler`1.<InvokeAsync>d__9`1.MoveNext() in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\HttpHandler\HttpHandler.cs:line 175
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.Ta
@matt40k
matt40k / do-basicDroplet.tf
Created September 29, 2017 13:21
Terraform
variable "environment" {
description = "this environment"
default = "poc1"
}
resource "digitalocean_droplet" "web" {
name = "web-1-${var.environment}"
size = "512mb"
image = "ubuntu-14-04-x64"
region = "lon1"
@matt40k
matt40k / ConvertToJsonFunctionBug.ps1
Last active September 16, 2017 22:47
For some reason ConvertTo-Json messes up within a function - what am I missing? Note-Now fixed, this isn't c#, see commits to see fix. (https://gist.github.com/matt40k/fab6ca579c355a0862a0a2ffb8166330/revisions)
$v1
$v2
Function GetJson($value1, $value2)
{
$j = @{"test"=$value1;"test2"=$value2} | ConvertTo-Json
return $j
}
$v1 = "test123"
@matt40k
matt40k / aws_regions.csv
Last active August 16, 2017 16:30
AWS regions and codes
RegionName RegionCode
US East (Ohio) us-east-2
US East (N. Virginia) us-east-1
US West (N. California) us-west-1
US West (Oregon) us-west-2
Canada (Central) ca-central-1
Asia Pacific (Mumbai) ap-south-1
Asia Pacific (Seoul) ap-northeast-2
Asia Pacific (Singapore) ap-southeast-1
Asia Pacific (Sydney) ap-southeast-2

Standard apply updates

sudo apt-get update && sudo apt-get upgrade

Install prep req - Virtualenv, libjpeg and libxml2 dev libraries

sudo apt-get install virtualenv libjpeg-dev libxml2-dev libxslt1-dev

Switch to documents

@matt40k
matt40k / CleanUpWin10.ps1
Created July 3, 2017 11:53
Remove cruddy default apps from Win10
# Remove cruddy default apps
Get-AppxPackage Microsoft.XboxIdentityProvider | Remove-AppxPackage
#Get-AppxPackage Microsoft.XboxGameCallableUI | Remove-AppxPackage
Get-AppxPackage Microsoft.MicrosoftStickyNotes | Remove-AppxPackage
Get-AppxPackage Microsoft.BingWeather | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsCamera | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsAlarms | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsSoundRecorder | Remove-AppxPackage
Get-AppxPackage Microsoft.People | Remove-AppxPackage
$r = Invoke-WebRequest -Uri 'https://fsrm.experiant.ca/api/v1/combined' -Method GET
@matt40k
matt40k / civo.ps1
Last active May 5, 2017 11:36
Basic Civo powershell script - https://www.civo.com/
$api_key = 'PUT YOUR API KEY HERE'
$baseApiUrl = 'api.civo.com'
$apiVer = 'v2'
$apiUrl = "https://$baseApiUrl/$apiVer"
$header = @{}
$header.add("Authorization", "bearer $api_key")
#$header.add("Content-Type", "application/json")
$id = "wp-ubuntu"