❯ Guillaume Laforge

Tips

cURL's --json flag

As cURL was celebrating its 25th birthday, I was reading Daniel Stenberg’s story behind the project, and discovered a neat little feature I hadn’t heard of before: the --json flag! Daniel even blogged about it when it landed in cURL 7.82.0 last year. So what’s so cool about it? If you’re like me, you’re used to post some JSON data with the following verbose approach: curl --data '{"msg": "hello"}' \ --header "Content-Type: application/json" \ --header "Accept: application/json" \ https://example. Read more...

Tip: Visualize output in the Groovy Console

For some scripting tasks, my favorite go-to tool is the Groovy Console, and writing code with Apache Groovy. Usually, you just spill some println calls all over the place to display some textual information. But there’s a little known secret. Not really secret though, as it’s properly documented. It’s possible to display images (like BufferedImage or its parent java.awt.Image) or all sorts of rich components (from the Swing UI toolkit, like JPanel, JLabel, etc. Read more...

Some custom VS Code settings

I regularly use both IntelliJ IDEA and Visual Studio Code as my environments for developing. But like all tools, we often need to personalise them to our liking, to feel at ease, or to be more productive. As we read code more than we write, there are certain settings in your favorite editor to improve your reading experience. Today, I’ll share of the tweaks I’ve made to my VS Code settings. Read more...

Turning a Website Into a Desktop Application

Probably like most of you, my dear readers, I have too many browser windows open, with tons of tabs for each window. But there are always apps I come back to very often, like my email (professional & personal), my calendar, my chat app, or even social media sites like Mastodon or Twitter. You can switch from window to window with CTRL/CMD-Tab, but you also have to move between tabs potentially. Read more...

Workflows Tips and Tricks

Here are some general tips and tricks that we found useful as we used Google Cloud Workflows: Avoid hard-coding URLs Since Workflows is all about calling APIs and service URLs, it’s important to have some clean way to handle those URLs. You can hard-code them in your workflow definition, but the problem is that your workflow can become harder to maintain. In particular, what happens when you work with multiple environments? Read more...

Serverless tip #7 — Create mini APIs with Cloud Functions and Express routing

Requirements: an existing Google Cloud Platform account and project Cloud Functions should be enabled for that project Compared to the previous tip when using Exress’ request path attribute, we can take advantage of Express routing. So to support the following paths: https://us-central1-myproject.cloudfunctions.net/api/customers https://us-central1-myproject.cloudfunctions.net/api/customers/32 https://us-central1-myproject.cloudfunctions.net/api/customers/32/address We can have our functions require Express by adding Express in package.json: { "name": "mini-api-router", "version": "0.0.1", "dependencies": { "express": "^4.17.1" } } Then we can require that dependency in our new functions script: Read more...

Serverless tip #6 — Create a mini web API with Cloud Functions

Requirements: an existing Google Cloud Platform account and project Cloud Functions should be enabled for that project We often use individual HTTP Cloud Functions as a single endpoint, and we pass data to the functions with either query parameters, or via a POST body payload. Although it’s a good practice to keep the scope of a function small, however, you can easily write mini Web APIs for a given function, with different paths for different needs, like with usual Web frameworks. Read more...

Serverless tip #5 — How to invoke a secured Cloud Run service locally

Requirements: an existing Google Cloud Platform account with a project you have enabled the Cloud Run service and already deployed a container image your local environment’s gcloud is already configured to point at your GCP project By default, when you deploy a Cloud Run service, it is secured by default, unless you use the –allow-unauthenticated flag when using the gcloud command-line (or the appropriate checkbox on the Google Cloud Console). Read more...

Serverless tip #4 — Discover the full URL of your deployed Cloud Run services with gcloud format flag

Requirements: an existing Google Cloud Platform account you have enabled the Cloud Run service and deployed already a container image One of the nice things with Cloud Run is that when you deploy your services, you get a URL like https://myservice-8oafjf26aq-ew.a.run.app/, with a certificate, on the run.app domain name, etc. You see the name of the service: myservice, the region shortcut where it was deployed: ew (Europe West), and then . Read more...

Serverless tip #3 — Use the Cloud Run button on your Git repository to deploy your project in a click

Requirements: an existing Google Cloud Platform account a Git or Github repository containing your project your project can have a Dockerfile (but not mandatory) With Cloud Run, you can easily deploy a container image and let it scale up and down as needed, in a serverless fashion: No need to focus on infrastructure (provisioning servers, clusters, upgrading OS, etc.) Your application can scale transparently from 0 to 1, and from 1 to n (no need for a pager when your app is featured on Hackernews) You pay as you go, proportionally to the usage If your project is hosted on Github, for example, how can you help users get started with your project? Read more...