By Kevin Hou
3 minute read
Instead of spending time writing code to view JSON or using a JSON viewer app, which can both be incredibly slow with large JSON files, you can use NodeJS to inspect JSON objects. Simply start the Node console:
1$ node 2
Next, you can import the JSON and navigate the tree object to your heart's content.
1>> // Import JSON 2>> require('./path/to/json') 3>> 4>> /* `_` references the last output 5>> * In this case: _ = require(...) 6>> */ 7>> r = _ 8>> 9>> // Traverse JSON tree 10>> r.data 11
Macs contain a built in terminal function called Caffeinate. While one could download the free "Caffeine" app from the Mac App Store, the command line provides an easy alternative. It offers more control and in my opinion is easier to interpret. To activate, simply type:
1$ caffeinate # Indefinite amount of time 2
1-d # Prevent display from sleeping 2-i # Prevent system from idle sleeping 3-s # Prevent system from sleeping (only when plugged in) 4-u # Resets the system timeout and/or will wake the computer 5-t <seconds> # Specifies timeout in seconds from the time the command is run 6
Modify your ~/.ssh/config file and add:
Host aliasName
Hostname some.example.com
Port 2222
User username
Usage: $ ssh aliasName
Pressing <Command> and ; at the same time will open an autocomplete dropdown selection in iTerm.
Searching for command history:
$ history to see all recent commands
Control + r to search through your recent history and use as your current command.
Count how many files are in a given directory:
$ find DIR_NAME -type f | wc -l
Count how many lines of code in a given directory:
$ find . -name "*.*" -exec wc -l {} \;
Show your permission on a directory:
$ ls -ld <directory>
Show the size of the files in a directory:
$ ls -lh
Print certain files all in one column:
1$ ls -1. *.jpg # 1 column, JPGs 2
Mark file as not executable:
$ chmod -x fileName
Copy contents of file to the clipboard:
$ cat file.txt | pbcopy or $ pbcopy < file.txt
Show a mini calendar view:
$ cal
Count number of columns in CSV file:
$ head -1 data_set/background-one.csv | sed 's/[^,]//g' | wc -c
Open URLs without copy pasting:
Command + Click
Delete word:
Control + w
Grepping (Searches for string in directory):
grep -r someString .. Useful doc
It's also helpful to note that you can use regexes on most commands. For example:
1killall -9 prefix_* # All processes that begin with "prefix_" 2rm -f *_vs_* # Forcibly remove all files with names that have "_vs_" in them 3
Paste into a new file:
1$ pbpaste > fileName 2