JavaScript is a high-level, interpreted scripting language that conforms to the ECMAScript specification. JavaScript has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions.
To some JavaScript is a necessary evil. I think JavaScript code can be elegant and beautiful. As with any programming language, it has its traps and pitfalls. Node.js is a big game changer on the server. And TypeScript helps u to make projects more readable.
On a more personal note: I stopped using semicolons in my scripts as it improves readability of small code snippets.
So far I’ve been using the hubot-pretend package for the testing of the hubot-command-mapper. But as that test package is no longer maintained / updated, I wanted to switch to something that is more in line with what Hubot itself does: hubot-mock-adapter.
I love the replaceAll string API in JavaScript, as it makes replacing a string far more intuitive than the “good old” global regular expression. This week I had to replace strings with the results of async calls. Yeah, that is not supported by any API in standard JavaScript.
At Wehkamp, we use the Hubot Grafana project to make our Grafana dashboard available in Slack. It mainly helps our standby team to make quick assessments on what’s going on with our website. Last year, we saw we could not upgrade the package from 2.5.2 to 3.0.1, because slugs could not be used anymore. But we use slugs and… quite heavily! So we did not upgrade our Grafana v7… until we got hit by the input field bug. We decided to see what we could do to bring our slug feature back to our ChatOps bot!
I always use Prettier to reformat my code in Visual Studio Code. Prettier formats CSS, HTML, JavaScript and TypeScript. Formatting helps code to look consistent and thereby more easily to read. In this blog I try to format all code I publish.
Let’s use a small snippet to convert any article to Markdown. This might come in handy if you want to repost your articles to blogs that support Markdown like DEV.
You have a bunch of online services that let you take screenshots of a site and save them in a folder. While it can be very useful to pay for such a system, it is not so hard to create it. Let’s use Chrome / Chromium with Puppeteer and Node.js (cluster) to take some snapshots in no-time. We’ll use the Puppeteer Cluster package to run multiple threads / workers to grab those screens in parallel. We’ll be using TypeScript.
Have you tried turning it on and off again? The web is a weird place and calls might not always succeed in the right manner. A retry with an exponential back-off mechanism helps your code to be more resilient when it connects to services outside of your control. While there are many packages that can help in this area, it pretty easy to add some utility methods to your project. In this article I’ll show how you can create a general-purpose exponential back-off and retry mechanism using TypeScript and Node.js.
This week we had to exfil some data out of a bucket with 5M+ of keys. After doing some calculations and testing with a Bash script that used AWS cli, we decided to go a more performant route and use s3p. They claim to be 5-50 times faster than AWS cli 😊.
I love the group by SQL command, and sometimes I really miss these SQL-like functions in languages like JavaScript. In this article I explore how to group arrays into maps and how we can transform those maps into structures that work for us. We will leverage TypeScript generics to do transformation on data structures in such a way that the end-result remains strongly typed: this will make your code more maintainable.
Last week I was working on our new cockpit application, which is essentially a list of links to parts of our Wehkamp platform. The old application was not being maintained, as the React-stack is not something that’s in the skill-set of most engineers. We kept the new cockpit simple: plain old HTML. Of course we wanted to support a nice dark-theme as well. This article shows how simple it is to implement dark mode.