Powershell extension method

We are testing our Powershell Module with Pester. Since the data is some sort of graph we need to work with indexers / lists all the time. After a small brainstorm session we decided on an Extension Method approach.

Reading the post Extension Methods in Windows PowerShell from Bart de Smet we started to develop. After some attempts we ended up with an XML containing the scriptmethod we needed. Important tip is to handle the $args in a special way: assign to local variable to prevent getting lost …

<?xml version="1.0" encoding="utf-16"?>
<Types>
 <Type>
  <Name>Company.RootNode</Name>
   <Members>
    <ScriptMethod>
     <Name>GetById</Name>
     <Script>
      switch ($args.Count) {
       1 { $req = $args[0];[System.Linq.Enumerable]::First($this.Children, [System.Func[Company.Node,System.Boolean]]{ param($x) $x.Id -eq $req })}
 default { throw "No overload for Uses takes the specified number of parameters." }
      }
    </Script>
   </ScriptMethod>
  </Members>
 </Type>
</Types>

You can load the extension method into powershell with the following command, where RootNodeExtensions.ps1xml is the name of the file containing the xml

Update-TypeData -prependPath RootNodeExtensions.ps1xml

Now the RootNode has the extension method GetById, so we can use $root.GetById(“12345″) that returns the first node in the Children property that has the Id==”12345” or throws an exception. Sounds like testing 😉

Posted in Development | Tagged , , , | Leave a comment

Powershell module

Windows PowerShell is a Windows command-line shell designed especially for system administrators. Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.
docs.microsoft.com

powershell-jonatan-pie-234237-unsplash

We are building a system and need to transform-and-load data. This feature must be implemented with data imported from and published to webservices. Time to dust off my Powershell skills from 2015 (open your application to Powershell) and get to work.

With one commandlet we load and transform the data (import-webdata) This writes the new object to the output. Next on the pipeline will be another commandlet that sends the transformed data to the other webservice (publish-structureddata)

To test this we use unittest for the (internal) C# code and Pester for the powershell part and the integration testing. Got to love automation 🙂

Want to start building a Powershell module too? Here are some links:

Posted in Development | Tagged , , | 1 Comment

Elasticsearch

Elasticsearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data so you can discover the expected and uncover the unexpected.
https://www.elastic.co/products/elasticsearch

marten-newhall-226045-unsplash

We are building a system to search for information. Searching (and finding) is what Elasticsearch is made for. It uses apache lucene to store and index documents and runs on java.

The same metadata we put into Neo4J we want to find with Elasticsearch. The heavy lifting of syncing the data is done by the neo4j-to-elasticsearch plugin.

So far we’ve learned that controlling the number of shards in DEV and TEST is a must to get predictable search results. This is caused by the limited amount of documents (only one million) in these environments. Read more

Want to start searching too? Here are some links:

Posted in Tooling | Tagged , | Leave a comment

Neo4j

I am added to a team that is using Neo4j as a datastore. After my last Neo4j experience I had to dust of my skills 🙄 I still don’t think in graphs but am getting there.

monkey string

We store metadata about datasets in a graph. Using some smart logic we try to couple different datasets. For this we needed special functions like shortest path between nodes. Neo4j is great at these.

Neo4j is developed in Java and offers extensibility trough plugins. One of the plugins we plan to use is the UUID, unmutable unique identifier. This adds a solution for the evil ID used by Neo4j.

Looking forward to learning more about graphdatabases? Here are the resources I used:

Posted in Tooling | Tagged , | 1 Comment

Colouring with Google and Bing

We all know google is the synonym to searching (and finding) stuff on the internet. Microsoft has bing for this. Both platforms offer custom searching as an API. So developers can take advantage of the massive resources both companies have and build that into their next awesome new product.

My kids use google to search for images they can print and colour. They just want to search, print and colour. A simple workflow that can be automated using the custom search API.

Print

One of the features is the full page printing of the image. Sometimes the image fills up multiple pages or just a small portion when printed. Using google I found some samples to scale and print an image.

Google vs Bing

Comparing the search API provided by Google and Bing they are very similar. I created the Colouring app with both API’s and my kids were happy with the results from both platforms. Happy customers 😉

Google Cloud platform Bing
Documentation CSE:list Bing Images Search
Pricing €5.00 per 1000 calls €3.37 per 1000 calls (S3)
Free? 100 calls per day 30 days
Other Max results is 10 Max results is 150

As you can see the free option is only available on google. So I went that way first. After hitting the 100 calls limit on google I migrated to the Bing Api with a trial license. Nobody noticed the change since the customer is not interested in the technical details, but in the finished product.

Colouring Surfer

References

Posted in Development | Tagged , , , , , , , | Leave a comment