How to pretty print JSON from CLI
Software engineers frequently have to deal with JSON and inspect or manipulate it.
There are two easy ways of pretty-printing JSON from command-line to aid in visual inspection. The first requires no installation, and the second requires a minimal installation but also provides syntax highlighting and manipulation capabilities.
Method 1: Using Python - Nothing to Install
Optional: Add alias to .bashrc
alias json='python -mjson.tool'
Example:
$ echo '{"cool": { "story" : { "bro" : [1, 2, 3] } } }' | json
{
"cool": {
"story": {
"bro": [
1,
2,
3,
]
}
}
}
Reference: http://www.restlessprogrammer.com/2013/03/how-to-pretty-print-json-from-command.html
Method 2: Using JQ - Minimal Install
Mac install via Homebrew: brew install jq
Ubuntu install apt: sudo apt-get install jq
$ echo '{"cool": { "story" : { "bro" : [1, 2, 3] } } }' | jq .
{
"cool": {
"story": {
"bro": [
1,
2,
3
]
}
}
}
Reference: https://stedolan.github.io/jq/
If you start learning to code in your mid 20s, can you make a good living off it?
I know of several people who start learning to code in their mid 20’s, and are doing fine now.
However, it’s very subjective what a “good living” is.
Compared to the rest of society, programmers (anyone who writes code) and software engineers (a subset of programmers, with more emphasis on “engineer”) might make a relatively higher salary.
However, just as with any field, there are different grade levels, and how well you do depends on what level you are able to attain, and that has a correlation to how much time you spend working on your craft.
If you work hard and dedicate yourself to software engineering now, you can probably make a decent living in 2–3 years. Whether that will exceed your earning capacity in whatever other endeavors you may try, or are currently in, varies widely depending on your individual background, circumstances, opportunities, and experiences (and ability to grow in all of those).
I think it may take 10–20 years of smart and hard work to get to the top tier of any field, software engineering included.
If you’re able to keep your head down and stay focused, go for it. If you’re easily distracted by others around you and are discouraged by others who seemingly effortlessly have more success than you, this may not be the path for you.
I have one friend who was working in the field of tech and executive recruiting, who was considering a switch to software engineering when he was already in his early thirties. I quoted to him a proverb, “Do you see a man skilled in his work? He will stand before kings; He will not stand before obscure men,” and he decided to stay the course and excel in what he was already good at. Fast-forward two years and he’s now crushing it as an executive recruiter, making much more impact than he would have, compared to if he had switched his career to software engineering.
IntelliJ ProTips™: Start the IntelliJ JVM process with additional memory
Assorted tips and tricks for IntelliJ
Start the IntelliJ JVM process with additional memory
-
Open the application once, normally, after a new install before editing this file.
a. Otherwise, the signatures won’t match and the OS will think that the package has been tampered with, and security settings will prevent launching of the application. You will then have to delete the entire application and reinstall it. -
Quit IntelliJ (Cmd+Q)
-
Edit
/Applications/IntelliJ IDEA.app/Contents/bin/idea.vmoptions
a.emacs "/Applications/IntelliJ IDEA.app/Contents/bin/idea.vmoptions"
or
vi "/Applications/IntelliJ IDEA.app/Contents/bin/idea.vmoptions" -
Increase the following settings from their defaults (note: only works if your machine has sufficient RAM):
a.-Xms2048m
b.-Xmx4096m
c.-XX:ReservedCodeCacheSize=1024m -
Start up and enjoy your upgraded IntelliJ on steroids.
-
Note: These steps must be repeated after every upgrade.
Other options listed here: http://tomaszdziurko.pl/2015/11/1-and-the-only-one-to-customize-intellij-idea-memory-settings/
Enriched objects
random: my new favorite coding adjective recently is “enriched”
val enrichedObj = obj ++ someAdditionalStuffs
reminiscent of / inspired by https://en.wikipedia.org/wiki/Enriched_uranium
Universal Directives for Shell Scripts
When writing shell scripts or other types of executables, you often put a directive at the top of the file to indicate which kind of interpreter to use.
#!/bin/python
Oh wait, that didn’t work?
#!/usr/bin/python
Okay, that worked on my Mac. But why all the guesswork? There is another command that is better.
Introducing env. Use it as a directive like so:
#!/usr/bin/env python
And if it’s a bash script:
#!/usr/bin/env bash
env is kinda like which. It takes the first argument and figures out the full path of that, and uses it as the directive
man env to read more about it.
Basically using #!/usr/bin/env INTERPRETER makes your script more portable
portability (adj.)
the ability to run your script anywhere, on any OS/platform
The holy grail goal of programming/CS = write once, run everywhere
It is somewhat circular in that it depends on env living inside of /usr/bin/, but I believe it is a convention that is much more rarely broken than where python or bash lives.
convention (n.)
another CS vocab word.
The quality of being predictable, doing expected things.e.g you walk into a dark room, you expect the light switch to be near the doorway opposite of the door hinge, not a mousetrap clamping down on your fingers when you reach along the wall.
