Ping a list of host names and output the results to a csv in powershell

You can use the following code instead (I simply altered the write-host calls to CSV formatting) and execute it with “PowerShell.exe > output.csv” Note that you must execute it from the folder that contains hnames.txt, or simply change the “hnames.txt” to a full path. $names = Get-content “hnames.txt” foreach ($name in $names){ if (Test-Connection … Read more

How to iterate or map over tuples?

Here’s an overly-clever macro solution: trait JoinTuple { fn join_tuple(&self, sep: &str) -> String; } macro_rules! tuple_impls { () => {}; ( ($idx:tt => $typ:ident), $( ($nidx:tt => $ntyp:ident), )* ) => { impl<$typ, $( $ntyp ),*> JoinTuple for ($typ, $( $ntyp ),*) where $typ: ::std::fmt::Display, $( $ntyp: ::std::fmt::Display ),* { fn join_tuple(&self, sep: &str) … Read more

How to render a tree in Twig

I played around with domi27’s idea and came up with this. I made a nested array as my tree, [‘link’][‘sublinks’] is null or another array of more of the same. Templates The sub-template file to recurse with: <!–includes/menu-links.html–> {% for link in links %} <li> <a href=”{{ link.href }}”>{{ }}</a> {% if link.sublinks %} … Read more

Proper way to release resources with defer in a loop?

Execution of a deferred function is not only delayed, deferred to the moment the surrounding function returns, it is also executed even if the enclosing function terminates abruptly, e.g. panics. Spec: Defer statements: A “defer” statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function … Read more