Posts

Showing posts from 2021

Sorting properties (not objects) in PowerShell

Image
This week I had a need for sorting the properties of an object alphabetically. Funny enough, the aptly named "Sort-Object" does not do this, that cmdlet sorts an array of objects by one or more given property names – useful for listing files in a folder, ordered by the files' size, for example. But I had to figure out something else. Take this example, just all the properties of a file in default order. Say I want to sort these alphabetically. First, I need to identify exactly which properties. Get-Member gives you the methods in addition to the properties, I don't want the methods. I just want the different properties, I got those with -MemberType *Property. I want the properties sorted by Name, and then expand the Name. Now, store that in a variable, here named $SortedProps. This variable is now a string array. Now, back to start with the Get-Item of the file. That output gets piped to Select-Object, which has the parameter "Property" that takes a string a

Visualizing TCP connections with Powershell and Graphviz

Image
I've recently been somewhat obsessed with Graphviz, particularly with the PSGraph Powershell Module.  At work I use it as part of the CI/CD of various projects to automatically document the flow of information between functions, servers, etc.  But in this post, I want to show how i start with the ss command (socket statistics), and end up with a graph that shows who you're connected to, and how. First of all, you need a few things: A Linux distro. I use Pop OS. Powershell PSGraph Graphviz (sudo apt-get install graphviz) This is the script that does all the fun: So first, I create a class with the properties I want. Then I run the ss command, and declare an empty array. Then I loop through the output of the ss command, parse it into the individual pieces of information I want, and add it to the array. Then the PSGraph magic. To be honest, I struggle to explain in great detail how it works, but the things to note are: -FromScript are the "start" boxes -ToScript are

Hidden settings in the Raspberry Pi Imager

Image
 So I've written a few micro sd cards over the years for my various Raspberry Pi projects. I always found it a pain to every time enable SSH and Wifi before boot by placing the ssh file and wifi profile on their respective places on the sd card before the first boot. Doing it manually with keyboard and display is even worse. I recently found out about the hidden options of the Raspberry Pi imager , and want to relay this information to my readers.  So when you open the imager, it might look like this: Now, press Ctrl+Shift+X Tadaa! MUCH better, I now look forward to flashing for my next project!

Maxus e-Deliver 3 i Norge har IKKE Android Auto eller Apple CarPlay

 This post will be in norwegian, as it (as far as I know) only applies to the norwegian market. English tldr at the bottom.  Jeg har nylig blitt deleier av en Maxus e-Deliver 3 , og har oppdaget noe som jeg syns må få større oppmerksomhet.  Alle anmeldelsene jeg så rundt denne bilen i forkant, viste at denne har Android Auto og Apple CarPlay. Men når vi kjøpte vår, oppdaget vi at USB-porten tiltenkt dette manglet. Ifølge forhandler ble vi fortalt at bilen er tilpasset det norske markedet og har dermed DAB-radio i stedet for Android Auto og Apple CarPlay...  Det var ingen dealbreaker for oss under kjøpet, men veldig surt å lære først når vi sto der og så bilen med egne øyne i Norge. Så om du vurderer Maxus e-Deliver 3 og den er importert av forhandler, vær klar over dette.  Hvordan DAB er implementert er noe teknisk interessant. USB-porten tiltenkt Android Auto/Apple CarPlay finnes tilsynelatende likevel, om så virtuelt. Jeg har ikke (enda) undersøkt baksiden av dashbordet grundig. Pers

A new car!

Image
My brother and I just bought a new car!  A little background: We've had an 2005-ish Volvo V40 for about 2 years. Cheap, simple car, did what we needed. But it did not pass the recent vehicle inspection, and the repair would cost at least 25 000 NOK. And scheduled next year is some other expensive maintenance. So we started looking for alternatives. We had a few demands for our next car: Electric Cheap Good range for the price Easy to rent out A format/type we need For it to be electric is mostly a principle. We also despise all the greasy maintenance, all the weird fluids and moving parts, having to visit the gas stations etc. It had to be relatively cheap. But the cheapest electric cars have terrible range. So we had to go a bit up in price. Owning a car is in itself a money pit in my mind. So for it to make a bit more financial sense, we're going to rent it out as much as possible. So what's the car? A 2020 Maxus e-Deliver 3! (Photo: Maxus.no) The short body, with the big

Regex Crossword

So today a colleague told me about  regexcrossword.com I'm done with the beginner levels, I think I'm hooked.  Do you like regex and puzzles? Of course you do, try it out!👍

Rusty

Image
This is Rusty. He's a floofy lovable weirdo that enjoys sitting outside and passing out in my lap

Automated Grocery Shopping

Image
I want to share a project I worked on a while ago, that I still use from time to time.  Basically all my grocery shopping is done at Kolonial.no, which is a Norwegian online grocery store that has an api for the shopping cart and products.  I am a cheapskate in many fields, including grocery shopping. And how I shop is somewhat robotic, very predictable and some might say boring and uninspired. But the thought process when I select items, can easily be automated, so I did. The code is on my github .  All the docs are there, so I won't bore you with that here.  But the idea and process is quite simple: I need eggs. Eggs are not a product. Eggs are a category of products . So my shopping list in this code is the category ID of eggs at kolonial.no.  On the same line in my shopping list I can also specify words that should or should not appear in the product name. For example "frittgående" should be in the name. (Norwegian for "free range") Next filter is whether or

Hello World!

I'd like to use this blog as an outlet for my hobbies, activities and thoughts.  Topics I have in mind are Home automation (based on Home Assistant) Cooking Various powershell scripting DIY projects at home Home labbing Cat pictures. The internet seems to like those, and I have access to a cat some times.  Also, this is my first blog. I have no idea what I'm doing.