#git #bash #productivity

Change the date of a git commit

One of the greatest and worst things with git is that you can rewrite the history. Here’s a sneaky way of abusing that, I can’t think of a legitimate reason to do this. As with anything, thanks StackOverflow for all the options I can pick from 👍. Set the date of the last commit to the current date GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)" Set the date of the last commit to an arbitrary date GIT_COMMITTER_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST" ...

  • Hugo Di Francesco
    Author
1 min read
#cdn #dev-decoded #productivity

The step-by-step guide to create a domain redirect with Cloudflare

Be logged into your dashboard. Select the domain you want to redirect from Go to page rules Click “Create page rule” Enter your.domain/* (matches all traffic) for which URLs will have their traffic redirected Click “Add a Setting” Select “Forwarding URL” Select the type of redirect, I recommend 302s since they’re less aggressively cached (so if you ever want to use that domain to do something else other than redirect, you can) Enter your forwarding URL Click “Save and Deploy” You’re done, you’ve just created a redirect from your domain to another one 🙂 ...

  • Hugo Di Francesco
    Author
1 min read
#python #graphql #web development

Python GraphQL client requests example using gql

An example consuming a GraphQL API from Python using gql. Full code example at HugoDF/python-graphql-client-example. This was sent out on the Code with Hugo newsletter last Monday. Subscribe to get the latest posts right in your inbox (before anyone else). $ pip install gql # You should use a virtualenvfrom gql import gql, Client from gql.transport.requests import RequestsHTTPTransport _transport = RequestsHTTPTransport( url='https://graphql-pokemon.now.sh/', use_json=True, ) client = Client( transport=_transport, fetch_schema_from_transport=True, ) query = gql(""" { pokemon(name: "Pikachu") { attacks { special { name } } } } """) print(client. ...

  • Hugo Di Francesco
    Author
1 min read
#hugo #meta #css #deployment

Switching the lights on: Hugo vs Hugo config files

A simple Hugo blog setup The story of getting codewithhugo.com up and running. The tl;dr is the following: I always rave about my blog setup, it’s simple, fast and just works I used Hugo, “The world’s fastest framework for building websites”, a static site generator I used a theme, casper-two, which is a Hugo port of the https://ghost.org/ default theme I deployed to GitHub pages behind Cloudflare. ...

  • Hugo Di Francesco
    Author
8 min read
#Testing #JavaScript #ES6

Abusing Jest snapshot tests: some nice use-cases 📸

There’s some nice use-cases for snapshot tests outside of the well-travelled React/Vue UI component ones. In other words, although React and Vue testing with snapshots is pretty well documented, that’s not the only place they’re useful. As a rule of thumb, you could replace a lot of unit tests that assert on with specific data with snapshot tests. We have the following pros for snapshot tests: - the match data is stored in a separate file so it’s harder to lose track of things, eg. ...

  • Hugo Di Francesco
    Author
6 min read
#tooling #git #ci #bash

Deploy to multiple environments with git and CircleCI

Easily deploying to multiple environments in a simple manner using GitHub, CircleCI and Heroku. Continuous Integration is awesome, but sometimes you need a buffer between auto-deploying things on merge and the production release. To do that with CircleCI requires some git branch-wrangling and a few lines of bash scripting. We’ll imagine a scenario where a deploy is trivial (ie. we’ll pretend we’re using Heroku). For more complicated build steps we should still be able to follow similar principles. ...

  • Hugo Di Francesco
    Author
5 min read
#Redis #tooling

Install just redis-cli on Ubuntu, Debian, Jessie

As part of adding integration tests to an app on CircleCI I ran into the following issues: redis-cli’s API has changed from version 2 to 3 to 4 ie. this works in v4 redis-cli -u ${REDIS_URL} but doesn’t in v2 the “only way” to install redis-cli is through a redis-tools or redis-server install and I only need redis-cli not the server or any other tools What follows is how not to install redis-cli and then how to install redis-cli latest, properly. ...

  • Hugo Di Francesco
    Author
2 min read
#JavaScript #Node #Docker #redis

Bring Redux to your queue logic: an Express setup with ES6 and bull queue

There always comes a point in a web application’s life where an operation is best served in the background, this is where queues come in. There are a few queuing solutions in Node. None of them are ridiculously dominant, eg. Kue, RSMQ, Bee Queue, bull. The issue with Kue, RSMQ and Bee Queue was its use of a done callback as the recommended API. Bull https://github.com/OptimalBits/bull is a premium Queue package for handling jobs and messages in NodeJS. It’s backed by Redis and is pretty feature-rich. Most of all, it leverages a Promise-based processing API which means async/await. We’ll walk through an application that sends webhooks with a given payload to a set of URLs. ...

  • Hugo Di Francesco
    Author
11 min read
#JavaScript #Node

ES6 by example: a module/CLI to wait for Postgres in docker-compose

When using docker-compose, it’s good practice to make anything that relies on Postgres wait for it to be up before launching. This avoids connection issues inside the app. This post walks through how to deliver this functionality both as a CLI and a module that works both as a CommonJS module (require) and ES modules, without transpilation. “A fast, production ready, zero-dependency ES module loader for Node 6+!” is esm’s promise. From this sample project, it’s worked. ...

  • Hugo Di Francesco
    Author
9 min read