Skip to content

Instantly share code, notes, and snippets.

// Selected hand-copied text from https://www.youtube.com/watch?v=FjhRkfAuU7I#t=2035
// Article at https://databricks.gitbooks.io/databricks-spark-reference-applications/content/twitter_classifier/index.html
// references this video, but the provided code is different than video.
// The video does a bunch of stuff to obtain and process the tweets, but
// what "val texts = " becomes is simply an array of strings, so I just
// made a text file with one log entry per line (I'm trying to classify logs)
// and did something like:
val texts = sc.textFile("input.log")
<!DOCTYPE html>
<html>
<!-- NOTE: This code started with a copy of index.html from https://bl.ocks.org/mbostock/4063570 which is: -->
<!-- LICENSE: GPL version 3 https://opensource.org/licenses/GPL-3.0 -->
<head>
<style>
<meta charset="utf-8">
.node circle {
fill: #fff;
"`nWalking the XML tree`n"
$WeirdThingy = [xml](Get-Content "test.audit")
$RemoveNodes = @()
# Walk the nodes, match text and add nodes to $RemoveNodes array
$WeirdThingy.check_type.ChildNodes | ForEach-Object {
if ($_.InnerText -match '8.1.1.1') {
$RemoveNodes += $_
# In reply to https://www.reddit.com/r/PowerShell/comments/4a08hk/importcsv_with_as_a_hashtable/
# Public Google Form at https://docs.google.com/a/jimnelson.us/forms/d/1dYmWTcw3c3q9p3HGWGvbNDvXWekUEKQfgsecZOpsV-k
# Results are at https://docs.google.com/spreadsheets/d/1G7J8qCL4gQ_NSYLiGE_3dauSaa75ppzPmcO-Rl7yV6w
[cmdletbinding()]
param(
$SheetKey = "1G7J8qCL4gQ_NSYLiGE_3dauSaa75ppzPmcO-Rl7yV6w",
$MaxRows = 5
# Get the weather
$wttr = Invoke-WebRequest http://wttr.in/
# Regex to match lines with no data in them, including blank lines and decorative borders
$RegExNoData = '^[ ─┌┬┤├┐┼└┴┘]*$'
# This is used to match the phase line and exclude it.
# Also used to create an array of weather data for each date
$PhasesOfDay = @("Morning", "Noon", "Evening", "Night")
function Get-Hype {
param (
[switch]$CleganeBowl,
[switch]$KingsMoot
)
New-Object psobject -Property ([ordered]@{
CleganeBowl = $CleganeBowl
CleganeBowlIsPresent = $CleganeBowl.IsPresent
CleganeBowlBound = $PSBoundParameters.ContainsKey('CleganeBowl')
KingsMoot = $KingsMoot
@midnightfreddie
midnightfreddie / graylog-snippet.ps1
Last active April 18, 2016 13:45
Attempt at manipulating Powershell data for GELF Graylog input, in reply to https://www.reddit.com/r/devops/comments/4f9e7x/scraping_apache_weblogs_and_shipping_them_to/
# This isn't tested much as I don't have the original data, but I've tested varios snippets, and they seem to work
# $GraylogUrl = "http://example.tld:12201/gelf"
$GraylogUdpPort = 12201
$GraylogUdpHost = "example.tld"
$UDPclient = new-Object System.Net.Sockets.UdpClient
$UDPclient.Connect($GraylogUdpHost, $GraylogUdpPort)
$Enc = [system.Text.Encoding]::UTF8
$Uri = "http://midnightfreddie.com/reddit/simpletable.html"
$InfoPage = Invoke-Webrequest -Uri $Uri
# Iterate over each <tbody> which contain all the body rows for each table
$InfoPage.ParsedHtml.getElementsByTagName("tbody") | ForEach-Object {
$Headers = $null
# Might need to uncomment the following line depending on table being parsed
@midnightfreddie
midnightfreddie / SillyCombiningUnicode.ps1
Created May 4, 2016 02:43
Random silliness: Adding a combining glyph to every a-z character in a string.
# Silliness. U0300 - U0036F are combining unicode characters
# https://en.wikipedia.org/wiki/Combining_Diacritical_Marks
$String = "The quick, brown fox jumped over the lazy dog"
$Combining = 0x0300 .. 0x036F | ForEach-Object { [char]$_ } | Sort-Object { Get-Random }
$i = 0
($String.ToCharArray() | ForEach-Object { $_ -replace '[A-Za-z]', "`$0$($Combining[$i++])" }) -join ""
# Dot-source function file
. .\BusinessDays.ps1
Describe 'Get-IsWeekDay' {
@{ Date = "2016-05-15"; IsWeekDay = $false},
@{ Date = "2016-05-16"; IsWeekDay = $true },
@{ Date = "2016-05-17"; IsWeekDay = $true },
@{ Date = "2016-05-18"; IsWeekDay = $true },
@{ Date = "2016-05-19"; IsWeekDay = $true },
@{ Date = "2016-05-20"; IsWeekDay = $true },