git add files by pattern

By all unstaged files

-> ga --dry-run --verbose .

By file extension

-> ga --dry-run --verbose *.md
-> ga --dry-run --verbose \*.md

By some part of file name

-> ga --dry-run --verbose *moon*

Example

git-add-with-file-with-pattern
Demonstration of git add file with patterns
Advertisements

Setting locales so that terminal in Mac OS would display Unicode character

locale

Output:

LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

We can set the LANG variable by

export LANG=en_US.UTF-8

Or you can also add that line into the file ~/.bash_profile, and then source ~/.bash_profile

Different ways to output Christmas tree [from fileformat] in terminal:

perl -CS -E 'say "\x{1F384}"'
echo -e "\xF0\x9F\x8E\x84"

To display Christmas tree in git log

Turn out that because less program is not up-to-date in Mac OS. Hence we need to update it.

http://www.recursion.org/2016/6/19/displaying-emoji-in-git-log

 

Grape Error Formatter

I was working with Grape API, and I use a custom error formatter. Since we are working on generating error objects according to JSON API specification format:

Here is an official example [source]

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/vnd.api+json

{
  "errors": [
    {
      "status": "422",
      "source": { "pointer": "/data/attributes/first-name" },
      "title":  "Invalid Attribute",
      "detail": "First name must contain at least three characters."
    }
  ]
}

d But we also want to add

So even though the field jsonapi is not required, we would like to have it in our response. So our response would be like this:

{
"jsonapi": {
"version": "1.0"
},
  "errors": [
    {
      "status": "422",
      "source": { "pointer": "/data/attributes/first-name" },
      "title":  "Invalid Attribute",
      "detail": "First name must contain at least three characters."
    }
  ]
}