Tag Archives forwebprogramming

Git remove local branches that don’t exist remote

The quick way:

git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d
git remote prune origin

Use the following to have the branches displayed before you’re asked to delete them.

branches=$(git branch --merged master | grep -v '^[ *]*master$'); \
printf '\n\nBranches to be removed:\n---\n'; \
echo ${branches} | xargs -n1; \
printf '---\n\nRemove the branches above? [Ny] ' \
    &&  read shouldDelete \
    && [[ "${shouldDelete}" =~ [yY] ]] \
      && echo $branches | xargs git branch -d \
      || echo 'aborted' 

source: https://stackoverflow.com/a/16906759

Sort an array in javascript by property of one of the object elements

Say you have an array consisting of objects. And you want to order that array by one of the properties of these objects.

Take this array:

        id: 4,
        title: "Lorem ipsum",
        created: "2020-04-10T14:59:00+00:00"
        id: 2,
        title: "Iptum quanto",
        created: "2020-05-29T13:17:48+00:00"
        id: 1,
        title: "Dolor samet",
        created: "2020-05-29T13:16:20+00:00"
        id: 3,
        title: "Tenari fluptum",
        created: "2020-05-29T13:08:39+00:00"

Let’s sort it by the string created property of each element

const orderedChapters = chapters.sort((a, b) => {
  return a.created.localeCompare(b.created))

OR sort it by the numerical id property of each element

const orderedChapters = chapters.sort((a, b) => {
  return (a.id > b.id) ? 1 : ((b.id > a.id) ? -1 : 0)

POST request turns into GET request

I was firing login request to my API but I could not get it to return the correct response.

Upon investigation, it turns out that the API received a GET request while I issued a POST request with Postman.

The issue? I was sending the POST request to http while the API was listening on https!

It turns out that the request was forwarded to the https address as a GET request…

Solution: send requests to the https address