Programming as a mental activity

shapeof.com/archives/2020/12/brain-activity_of_people_coding.html

Interesting post and the article there, and something I agree with.

…coding task mainly activated the so-called multiple demand network. This network, whose activity is spread throughout the frontal and parietal lobes of the brain, is typically recruited for tasks that require holding many pieces of information in mind at once, …

I hold the different things required to implement “a thing” in my mind somehow visually. The different items and places of code are in a three dimensional kind of a map in my mind. Difficult to describe this, but this 3D kind-of-a-space is a good enough description. Then I need to keep in my mind information which parts are still not finished, which have issues to solve, and how they connect to each other. This mental map is then somehow connected to the IDE where the action happens in text editors, but that is not my actual “map” of the thing under construction.

Programming is different. If you haven’t tried it because you think you suck at math, you should try anyway. You’d be in good company (I suck at math too).

Agree with this too, personally…

Merging two JSON files

Having two large JSON files with one common element, how can you merge them? Editing by hand not so nice if the files contain hundreds of elements.

For example, you have a large JSON file of locations:

{
  "name": "Oulu",
  "lat": 65.013784817,
  "lon": 25.47209907
},

And then you also have a large JSON file of location codes for the commune:

{
  "name": "Oulu",
  "code": "564"
},

And you would like to merge these into a one JSON file and parse the commune code, name, and location data at one go.

You can do this with jq using the following command:

./jq-osx-amd64 --slurpfile file2 codes.json.txt '
  INDEX($file2[]; .name) as $dict
  | $dict[.name] as $x
  | if $x then . + $x else empty end
'  coords.json.txt > out.json

And as a result, you get your JSON element merged in one file:

{
  "name": "Oulu",
  "lat": 65.013784817,
  "lon": 25.47209907,
  "code": "564"
},

Much faster than copying and pasting or implementing your own JSON merger.