Saturday, June 20, 2020

power(shell), corruption & lies: Tee-Object and the clipboard

Really useful powershell for me this morning. I wanted to run some commands, look at the output, and capture the output to the clipboard so I could paste it elsewhere.

Rather than run my command and then use the mouse in the comand window to copy the output to my paste buffer, like some kind of animal, I wanted to have a full powershell solution.

FOOBAR | Tee-Object -Variable c; Set-Clipboard $c

How it works:
  1. FOOBAR is the name of the command (or series of piped commands) that I want to run that write to the console.
  2. Tee-Object -Variable c takes the output from FOOBAR and passes it forward (in this case to the console output) and to the variable $c.  

    Tee-Object is kind of like a plumbing tee where data is sent in two directions. It's normally used to show output on the console and to redirect to a file. 

    Note that you say -Variable c not -Variable $c. 
  3. Set-Clipboard $c sets the contents of the paste buffer with the value in $c.

power(shell), corruption & lies: Directory Info Aggregation

To get a recursive summary of files, folders and sizes from a root directory:

$len=0; Get-ChildItem -Recurse | 
    %{ $_.GetType().Name; $len+=$_.Length } | 
    Group-Object -NoElement | ft -auto; "Total size= $($len / 1Gb) GB"

Output looks like this
Count Name
----- ----
18386 DirectoryInfo
57784 FileInfo
Total size= 25.7907013082877 GB
 
How it works:

  1. $len=0 sets the variable len to 0. No duh here.
  2. Get-ChildItem -Recurse recurses through a directory tree from the current directory. You can use the -Path option for a different root directory.
  3. %{} is the alias of ForEach-Object and is a shorthand way of looping over results that are piped from the previous command
  4. $_.GetType().Name is emitting the type of the directory entry (DirectoryInfo or FileInfo)
  5. $len+=$_.Length is summing up directory entry sizes
  6. Group-Object -NoElement is counting directory entry types from step 4 and printing them out.
  7. ft -auto automatically formats the output so that large numbers are not truncated to ellipsis (...).
  8. "Total size= $($len / 1Gb) GB" prints out the total accumulated size from the $len variable in Gigabytes.

Sunday, June 14, 2020

Spicy Miso Peanut Chickpeas

A chickepa dish that's good enough to eat without an accompanying starch (rice, naan, whatevs). 

I'd have a picture here, but the 2 times I made it, I ate it fast enough so there wasn't time. I could show you a photo of the dirty pan that I cooked it in, but nobody wants to see that.

Also, it's super fast to cook, maybe about 15m.

Ingredients
  1. Oil
  2. Grated ginger (can substitue powder)
  3. Grated garlic (can substitute powder, but do you really not have garlic in your kitchen?)
  4. Miso paste
  5. 1 can chickpeas
  6. chili paste
  7. Coconut or almond milk  
  8. Peanut butter
  9. Soy sauce
  10. Green veg that likes to cook, like bok choi, broccoli or gai lan
  11. Salt
  12. Lime.

Recipe
  1. Cook ginger & garlic in a pan with a little bit of oil over medium until the flavors release, ~ 1 minute.
  2. Prep some miso by putting 1 tbsp in a bit (1/4 cup) of hot water. stir it up so it doesn't get clumpy.
  3. Add soime drained chickpeas to the pan.
  4. Cook them up with the (now liquid) miso.
  5. Add some chili paste, to desired heat level (1/2 tsp?)
  6. Add 1/2 cup of the coconut / almond milk.
  7. Add 1tbsp peanut butter. Smile smugly if it's the natural and organic kind that your kids refuse to eat.
  8. Add some soy sauce, maybe 1bsp or so.
  9. Stir, bring to boil. Unclump that peanut butter.
  10. Add your chopped up green veg. I've been using bok choi with this, but anything that maintains a firmness & a crunch after a boil would be good here. You don't want to overcook this & get it all soggy - it's a texture thing.
  11. Cook it all together until your green veg is done and it thickens a bit. 
  12. Add some salt.
  13. Before your eat, juice half a lime onto your dish - the fresh squeezed lime pairs really well with the peanut, soy & miso flavor.