How to run GUI applications with Docker on MacBook


For one of my recent projects where I am required to use Docker on Macbook, I had a hard time figuring out how to run GUI applications with Docker installed on Macbook.


1. Pull your docker image.

2. Install socat on macbook

Steps to install socat is "brew install socat"
Get Homebrew if you dont use it. 

3. Run the following command in a terminal

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

4. Install XQuartz

brew cask install xquartz
open -a XQuartz


4. Find out the IP address you are connected to

ipconfig getifaddr en0


5. Run your docker container using the following command

docker run -it --rm -e DISPLAY=<ip address from previous command>:0 -v /tmp/.X11-unix:/tmp/.X11-unix <Your favoriet docker image>



Efficient ways to use Amazon AWS services.


Use a better compression program.

sudo apt install pgiz

tar -c --use-compress-program=pigz -f {TAR File name} [PATH to tar]

















Edit - I will keep this post updated as I begin to use more of the Amazon AWS services and discover faster ways to perform certain actions. 

How to get video or audio duration of a file using ffmpeg?


Today we will learn How to get the duration of a file using ffmpeg

1. Format Container Duration - [This works for both Video and Audio Files - better to report numbers using this command]

ffprobe -v error -show_entries format=duration \
  -of default=noprint_wrappers=1:nokey=1 input.mp4
 
 
2. Video Stream Duration - [This works only for Videos]
 
ffprobe -v error -select_streams v:0 -show_entries stream=duration \
  -of default=noprint_wrappers=1:nokey=1 input.mp4
 
 
Content author - https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds 

iTunes hidden secret - Song Lovers


For all the song lovers out there using iTunes - there is a secret feature I want to share...

Go to Internet Radio - Under Library section of Music.

Top 40/Pop - Stream -

1. Top 40 Hits All Day.

2. GotRadio ^ Top 40
 

Who needs Subscription to Music service when ITunes is giving such an amazing song collection all day.


To checkout more Music collection - Look at my playlists -

1. YouTube Version

Hindi Songs - Best Collection

English Songs - Best Collection

2. Spotify Same list -

English Songs - Best

Hindi Songs - Best


How to print contents of any database file



  1 import sqlite3 as lite
  2 import sys
  3
  4 def print_db_content(database_to_read):
  5         conn = lite.connect(database_to_read);
  6         cur = conn.cursor()
  7         # http://stackoverflow.com/questions/305378/list-of-tables-db-schema-dump-etc-using-the-python-sqlite3-api
  8         # Below query is equivalent to typing .tables in sqlite command line
  9         query = "SELECT name from sqlite_master where type = 'table'"
 10         tables_list = list(cur.execute(query))
 11         print tables_list
 12         for item in tables_list:
 13                 query = "SELECT * from '" + str(item[0]) + "'"
 14                 print query
 15                 cur = conn.cursor()
 16                 data = list(cur.execute(query))
 17                 for item1 in data:
 18                         print item1

 if __name__ == "__main__":
         if (len(sys.argv)<0):
                 print 'Usage: python print_content_of_database.py [database_absolute_path]'               
         else:
                 database=sys.argv[1]
                 print_db_content(database)

Working effectively with iTerm2


I have been using iTerm in daily work for almost a year now. Along the way, I learned a few handy settings tweaks and shortcut keys to boost my productivity in command-line environment.

Install iTerm2

If you haven’t heard of iTerm, it’s a popular open source alternative to Mac OS X Terminal. Give it a try, download and install it from http://www.iterm2.com.

Fine-Tune Settings

Launch iTerm, open iTerm > Preferences or just Cmd + ,.

Open tab/pane with current working directory

Under Profiles tab, go to General subtab, set Working Directory to “Reuse previous session’s directory”.

Enable Meta key

To enable Meta key for Bash readline editing e.g. Alt + b to move to previous word, under Profiles tab, go to Keys subtab, set Left option key acts as: to “+Esc”.

Hotkey to toggle iTerm2

Under Keys tab, in Hotkey section, enable “Show/hide iTerm2 with a system-wide hotkey” and input your hotkey combination, e.g. I use Ctrl + Shift + L.

Switch pane with mouse cursor

Under Pointer, in Miscellaneous Settings section, enable “Focus follows mouse”.

Handy Shortcut Keys

Here’s a set of shortcut keys I commonly use. You can always look for other shortcut keys in the iTerm menu.

Tab navigation

  • open new tab Cmd + t
  • next tab Cmd + Shift + ]
  • previous tab Cmd + Shift + [

Pane navigation

  • split pane left-right Cmd + d
  • split pane top-bottom Cmd + Shift + d
  • next pane Cmd + ]
  • previous pane Cmd + [
  • open search bar Cmd + f
  • find next Cmd + g

Input to all panes

  • input to all panes in current tab Cmd + Alt + i

Clear screen

  • clear buffer Cmd + k
  • clear lines (Bash command) Ctrl + l

Zooming / Font Resize

  • toggle maximize window Cmd + Alt + =
  • toggle full screen Cmd + Enter
  • make font larger Cmd + +
  • make font smaller Cmd + -

Macbook Keyboard Tips for Windows users

Original Post - https://www.macworld.co.uk/how-to/mac/keyboard-shortcuts-mac-users-copy-paste-option-shortcuts-3504584/

The three most important keys on your Mac can be found to the left and right of the spacebar (for right and left handed use). Unfortunately these three keys seem to cause more confusion than any others.

Using the Option or Alt key on a Mac

There is a great deal of confusion over what Apple referrs to as the Option key. If you'are using a UK keyboard chances are this is called the Alt key so it's no wonder most people don't know where it is.
The Alt (aka Option) key can be found between Control and Command. It has an icon that looks like a slope and a dip with a line above it.
Chances are the first time you hear mention of Option you are following a tutorial and trying to fix something on your Mac. The Alt key is the one you use if you wish to select a boot partition when starting the computer, you also press it when typing certain characters on your keyboard, such as # (Alt-3) or ¢ (Alt-4).
Here's an overview of the hidden characters that you can type using Alt (the keys might be a bit different if you aren't using a UK keyboard as we are).

You may be wondering whether you can use the Alt key ctrl-alt-delete to shut down an unresponsive Mac. Force quitting on a Mac is slightly different to on a PC, here's how to ctrl-alt-delete on a Mac, aka Force Quit on a Mac.

How to type €, #, … and © on a Mac

  • Alt-2 - Euro sign (€)
  • Alt-3 - Hash sign (#) (Sometimes called the 'pound' sign)
  • Alt-: - ellipsis (…)
  • Alt-G – copyright ©

You can also use Alt/Option to do the following:
  • Control-Alt-Command-Power Button - Quit all apps
  • Alt-Shift-Command-Q - Log out of your user account on your Mac
  • Alt-Delete - delete the word to the left of the curser
  • Alt–Left Arrow - move the curser to the beginning of the previous word, add Shift to this to highlight the text
  • Alt–Right Arrow - move the curser to the end of the next word, add Shift to this to highlight the text
  • If you are selecting large sections of text, you can do so by moving the curser to the end of the section you wish to select and pressing Alt-Shift-Up Arrow until all the text is selected. (This only works in some apps).
  • Similarly, Alt-Shift-Down Arrow lets you highlight the text below the curser
  • Alt-Command-F will open the Find and Replace feature if your application has it
  • Alt-Command-T will show or hide the toolbar
  • Alt-Command-C is the key combo to use if you wish to copy a style, or copy the formatting settings to the clipboard
  • And Alt-Command-V will paste those formatting settings onto the text you wish to change
  • Alt-Shift-Command-V will paste and match style - so that the text you paste in has the same style as the text around it, rather
  • than the style bought over from the place you copied it from
  • Alt-Command-D will show or hide the Dock at the bottom of your screen
  • In the Finder, Alt-Command-L is a handy shortcut to open the Downloads folder
  • Also in the Finder, pressing Alt-Command-P will show the path so you can see the precise location of what you are looking at
  • Alt-Command-S will show or hide the Sidebar in the Finder
  • Alt-Command-N will start a new Smart Folder in the Finder
  • If you select a few files in the Finder, you can press Alt-Command-Y to see a full-screen slideshow of those files
  • A shortcut to the Display preferences is to press Alt-Brightness Up (or Brightness Down, aka F1 or F2)
  • While you can open Mission Control preferences by pressing Alt-Mission Control (F3)
  • To duplicate/copy an item in the Finder or on your Desktop, press Alt while dragging it.
  • To create an Alias (a shortcut to a file) you press Alt and Command together while dragging the file from the location in the
  • Finder to another location, an arrow sign will appear indicating that this is a link to the file rather than a copy of it

Using the Command key on a Mac

If you thought that the jumbling of Alt and Option was baffling, there's even more opportuity for confusion when it comes to the Command key. The Command key (cmd) has a legacy that leads to confusion - many older Mac users will refer to it as the Apple key, because in the past there used to be an Apple logo on it, but this logo stopped appearing a while ago when if was decided that there were a few too many Apple logos on Apple products.
The logo you will still find on this key looks like a squiggly square, or a four petalled flower. It was designed by Susan Kare for the original iMac (and based on the Scandinavian icon for place of interest).

The Command (cmd) key works in a similar way to the Control key on a PC. On a Mac you use the Command key where on a PC you would use Control (or Ctrl).
If you were wondering why Ctrl-B didn't make your text bold, chances are you were previously a PC user and didn't realise that Command is the new Control. You might find this useful: How to move from PC to Mac: Complete guide to switching to a Mac from a PC.
Here are a few of the key combinations that use Command:
  • Command-B - Bold
  • Command-I - Italic
  • Command-Z - Undo
  • Command-Q - Quit
  • Command-W - Close window
  • Command-P - Print
  • Shift-Command-P - Page setup (for checking how it will print)
  • Command-S - Save
  • Shift-Command-S - Save As or duplicate the document
  • Command-A - select all

How to copy and paste on a Mac

  1. Select the text you wish to copy - a quick way to do this is to place your mouse pointer over a word and click twice. Once you have the text selected you can drag your mouse across or up, or down, to select more words. Alternatively, if you are selecting a number of words or sentences, or paragraphs, you can click at the beginning of the section, then press the Shift key, and click at the end of the section.
  2. Press Command-C to copy the text (or Command-X if you want to 'cut' the text from where it is currently)
  3. Go to where you wish to Paste the text in and press Command-V
  • Command-C = Copy
  • Command-X = Cut
  • Command-V = Paste

There are lots more useful key combinations that use Command including:
  • Command-F - Find 
  • Command-G - Find again
  • Command-H - Hide the windows of the app you are using
  • Command-M - Minimise the current window and send it to the Dock
  • Command-N - open a New document
  • Command-W - close the current window
  • Command-Space Bar - open the Spotlight search window
  • Command-Tab - to switch between open apps
  • Shift-Command-3 to take a screenshot of the screen (more about taking screenshots on a Mac here: How to take a screenshot on a Mac)
  • Command-Comma (,) - Open preferences for the app you are using
  • Command-T show or hide Fonts window
  • Command-Left Arrow -  move the curser to the beginning of the line
  • Command-Right Arrow -  move the curser to the end of the line
  • Command-Up Arrow -  move the curser to the beginning of the document
  • Command-Down Arrow -  move the curser to the end of the document (Press shift to select the text between the insertion point and the destination in each of these scenarios)
  • Command–Left Curly Bracket - Align Left
  • Command–Right Curly Bracket - Align Right
  • Shift-Command-| - Centre
  • Shift-Command-Minus sign - Decrease font size
  • Shift-Command-Plus sign - Increase font size
  • Shift-Command-Question mark - Open Help menu
  • If you are in the Finder or in a web browser, or any other app that supports Tabs, Command-T will open a new tab.
In the Finder you could try the following:
  • Command-D - Duplicate the file
  • Command-E - Eject the volumne
  • Command-F - Search
  • Command-I - Get Info
  • Shift-Command-D - Open the Desktop folder
  • Shift-Command-F - Open the All My Files folder
  • Shift-Command-H - Open the Home folder
  • Shift-Command-G - Open a Go To folder window
  • Shift-Command-I - Open your iCloud Drive
  • Command-K - Connect to the server
  • Shift-Command-K - Browse the network 
  • Command-L - Make an alias
  • Shift-Command-O - Open the Documents folder
  • Shift-Command-R - Shortcut to the AirDrop window
  • Command-Delete - sends the selected item to the Trash
  • Shift-Command-Delete - Empty the Trash (add the Alt key if you don't want to see the confirmation dialogue)

Using the Control key on a Mac

With the Command key doing the job of the Control key on a PC, what is the point of Control on a Mac keyboard, you may be wondering.
Content continues below
The most common use of Control is to mimic the right click on a mouse or when using the mouse pad (since some Apple mice don't have the right click option).
If you want more tips about How to right-click on a Mac read this.

There are many more uses for Control when used with other key combinations, for example:
  • Control-Command-Power button will restart your Mac
  • Control-Shift-Power button - puts your display to sleep
  • Control–Option–Command–Power button - quits all your apps and shuts your Mac
  • Control-H Delete the character on the left
  • Control-D Delete the character on the right
  • Control-K Delete the text from where your curser is to the end of the line
  • Control-A Move to the beginning of the line (more here: How to find End and Home on a Mac keyboard)
  • Control-E Move to the end of a line or paragraph
  • Control-F Move forward one character
  • Control-B Move backward one character
You can also use the Control key to add a document or folder to the Dock: Go to the Finder and select the item you wish to add to the Dock (or search for it using Spotlight: Cmd-Space, or select it on your Desktop). Then press Control-Shift-Command-T.

What do the F keys do on a Mac?

There are a few other Apple specific keys (depending on your keyboard):
F1/F2 - Brightness Up and Down
F3 – Mission Control (for an overview of all running applications, grouping windows from the same application, and your Spaces)
F4 - Is a shortcut to all the Apps you have on your Mac

F10/F11/F12 – Sound

You can set other F keys to do Mission Control actions. Go to System Preferences > Mission Control and add unused F keys to do functions such as Show Desktop or Dashboard.

How to type letters with accents on a Mac

Some letters can be typed with accents on top, like this é, ä, ö. This is easy to do on a Mac:
  1. Hold the letter down on the keyboard until a bubble menu with all the different options appears
  2. Each accent option has a number below it, tap the number on the keyboard to turn the letter into that accented version, or click on the accented letter with your mouse

How to type special characters, Emoji and maths symbols on a Mac

Emoji Characters on a Mac
You can use the Character Viewer to find special characters, Emoji and maths symbols.
Press Command-Control-Space and by default you will see the Emoji characters. To see the Character Viewer, with  special characters from any font on your Mac, click on the Character Viewer icon in the right corner of the window, or in the menu bar next to the time and date. 
Once you have the Character Viewer open, use the sidebar to view different categories, such as Currency Symbols or Maths Symbols and double-click any item in the main window to insert it into your document.
You can also search for any option using the Search field in the top-right. Enter a term like "cat" to find all the symbols that are cat-like.
The Character Viewer is placed permanently above all other windows, so you can continue typing in your app and view the Character Viewer on top of its document. You can switch between a small and large Character Viewer using the icon to the right of the Search Field.
It is also possible to add the Character Viewer as a Menu bar icon, this enables you to quickly access it from any app. Open System Preferences, choose Keyboard  > Keyboard and select the Show Keyboard & Character Viewers in Menu Bar option. Now you can click on the Character Viewer icon in the Menu bar and choose Show Character Viewer.

How do I add emoji on a Mac?

As we said above, just press Command-Control-Space and you will see a collection of Emoji you can use.
If you have the Character Viewer open you will find a section called Emoji in the sidebar.
Often it's easier to use the Search field in Character Viewer to find Emoji characters.
If you want to read more about using emoji this may be useful: How to use emoji

How to view shortcuts on a Mac

Use the Keyboard Viewer to learn special characters
One neat trick to learning keyboard shortcuts on a Mac is to use the Keyboard Viewer. Enable the Show Keyboard & Character Viewers in Menu Bar option (in System Preferences > Keyboard > Keyboard).
Now click on the Character Viewer icon in the Menu bar and choose Show Keyboard Viewer. A visual representation of the keyboard appears, and as you press keys they will be highlighted. If you hold down the Alt and Shift keys the Keyboard Viewer shows all the special characters on each key. You can use this to learn the special characters on each key.

Keyboard combinations for shutting down or Sleep your Mac

  • Ctrl-Eject = Show the restart / sleep / shutdown dialog
  • Shift-Control-Eject = Will put your displays to sleep
  • Command-Alt-Eject = Will put the computer to sleep
  • Command-Control-Eject = Save/Quit all applications then restarts Mac
  • Command-Alt-Control-Eject = Quit all applications then shuts down the Mac
  • Command-Shift-Q = Log out of your OS X user account (you'll be asked to confirm action)
  • Command-Shift-Alt-Q = Log out of your OS X user account immediately (you won't be asked to confirm action)
  • Command-Alt-esc = Force Quit
  • Command-shift-Alt-esc (for three seconds) = Force Quit the front-most application
Read next: How to lock a Mac

How to use the Application Switcher

Another handy key combo is the one that brings up the Application switcher. This is a handy way to move between different applications you have open.
  • Command-Tab = Move to the next most recently used application from your open applications
  • Command-Shift-Tab = Move backward through a list of open applications (sorted by recent use)
  • Command-~ (Tilde) = Move backward through a list of open applications (only when Application switcher is active)

List of Packages to Install for Anaconda


Anaconda - Package manager used to install packages and run python as a user.

This means that you can run things on server without sudo priveliges.


Steps to installation

Download Anaconda

Run bash <Anaconda.sh>

List of packages to Install are as follows

conda install -c groakat lame
conda install -c conda-forge -y sox libvorbis
conda install -c jjhelmus tensorflow
conda install -c conda-forge matplotlib
conda install numpy pyyaml mkl setuptools cmake cffi
conda install -c conda-forge tqdm
conda install -c conda-forge libsvm
conda install -c geneko pp
conda install pytorch torchvision cuda80 -c soumith

How to use a scheduler - Torque - QSUB


Check the status of your jobs
qstat

qstat - lists all the jobs on the system.

Check status of jobs for a user
qstat -u <username>

Get all details about a particular job
qstat -f <job id>


Delete a job from queue
qdel <job id> 

Numpy Tricks


How to print/display the number in full in an array?
import numpy as np
np.set_printoptions(threshold=np.nan)

Firefox 57 aka Firefox Quantum - The best browser so far from Firefox



Wow, I am amazed at the speed of this amazing browser - Firefox Quantum.

Firefox Quantum has a concept of loading the CSS engine and other changes which makes the browser a breeze to use with.



Firefox Quantum is releasing in November 2017. But why wait - Go ahead and try this browser out here - https://www.mozilla.org/en-US/firefox/channel/desktop/#beta

And for all languages the website links is here - https://www.mozilla.org/en-US/firefox/beta/all/

You will certainly consider leaving Google Chrome after trying the browser out!!!!


Reference:- http://www.zdnet.com/article/mozilla-firefox-57-is-so-fast-were-calling-it-firefox-quantum/

Install Octave with GUI 4.2.1 in Mac OS - Sierra or High Sierra


Hi everyone,

Today, we are going to review how to install Octave 4.2.1 in Mac OS Sierra or High Sierra.

Octave installation with GUI using MacPorts is successful.

How to Install MacPorts - [Refer steps on official MacPorts page ] - https://www.macports.org/install.php

Installation of Octave :-

sudo port selfupdate

sudo port install octave

Use Octave with GUI


What didnt work : -

I tried installing Octave using HomeBrew and it didnt work with GUI. Normal Octave using command line works.

Octave installation which Did not work on GUI :-

brew tap homebrew/science

brew update && brew upgrade

brew install octave

I also tried using

brew reinstall octave --with-qt --with-fltk --with-gui

Which also didnt load using GUI

Commands Reference - http://wiki.octave.org/Octave_for_macOS

Sox of Silence - Original post - http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/

The SoX of Silence


SoX is, by their own definition, the Swiss Army knife of audio manipulation.
And no doubt it’s full of fun with slicing and dicing and playback and recording and filtering and effects capabilities.
But SoX is a command line tool, which means obscure syntax and parameters in order to get things done.
I’ve been trying off and on for months to try to understand the silence filter from within SoX, which allows one to remove silence from the beginning, middle, or end of the audio. Sounds, simple, doesn’t it?  Well, it should be.
silence [-l] above-periods [duration threshold[d|%] [below-periods duration threshold[d|%]]
Removes silence from the beginning, middle, or end of the audio. Silence is anything below a specified threshold.
The above-periods value is used to indicate if audio should be trimmed at the beginning of the audio. A value of zero indicates no silence should be trimmed from the beginning. When specifying an non-zero above-periods, it trims audio up until it finds non-silence. Normally, when trimming silence from beginning of audio the above-periods will be 1 but it can be increased to higher values to trim all audio up to a specific count of non-silence periods. For example, if you had an audio file with two songs that each contained 2 seconds of silence before the song, you could specify an above-period of 2 to strip out both silence periods and the first song.
When above-periods is non-zero, you must also specify a duration and threshold. Duration indications the amount of time that non-silence must be detected before it stops trimming audio. By increasing the duration, burst of noise can be treated as silence and trimmed off.
Threshold is used to indicate what sample value you should treat as silence. For digital audio, a value of 0 may be fine but for audio recorded from analog, you may wish to increase the value to account for background noise.
When optionally trimming silence from the end of the audio, you specify a below-periods count. In this case, below-period means to remove all audio after silence is detected. Normally, this will be a value 1 of but it can be increased to skip over periods of silence that are wanted. For example, if you have a song with 2 seconds of silence in the middle and 2 second at the end, you could set below-period to a value of 2 to skip over the silence in the middle of the audio.
For below-periods, duration specifies a period of silence that must exist before audio is not copied any more. By specifying a higher duration, silence that is wanted can be left in the audio. For example, if you have a song with an expected 1 second of silence in the middle and 2 seconds of silence at the end, a duration of 2 seconds could be used to skip over the middle silence.
Unfortunately, you must know the length of the silence at the end of your audio file to trim off silence reliably. A work around is to use the silence effect in combination with the reverse effect. By first reversing the audio, you can use the above-periods to reliably trim all audio from what looks like the front of the file. Then reverse the file again to get back to normal.
To remove silence from the middle of a file, specify a below-periods that is negative. This value is then treated as a positive value and is also used to indicate the effect should restart processing as specified by the above-periods, making it suitable for removing periods of silence in the middle of the audio.
The option -l indicates that below-periods duration length of audio should be left intact at the beginning of each period of silence. For example, if you want to remove long pauses between words but do not want to remove the pauses completely.
The period counts are in units of samples. Duration counts may be in the format of hh:mm:ss.frac, or the exact count of samples. Threshold numbers may be suffixed with d to indicate the value is in decibels, or % to indicate a percentage of maximum value of the sample value (0% specifies pure digital silence).
The following example shows how this effect can be used to start a recording that does not contain the delay at the start which usually occurs between `pressing the record button’ and the start of the performance:
rec parameters filename other-effects silence 1 5 2%
Huh?
So lets try to clarify some of the mess from the man page.  First a couple of important notes:
  • When specifying duration, use a trailing zero for whole numbers of seconds (ie, 1.0 instead of 1 to specify 1 second). If you don’t, SoX assumes you’re specifying a number of samples.  Who on earth would want to specify samples instead seconds? You got me. Alternatively, you can specify durations of time in the format hh:mm:ss.frac.
  • Use at 0.1% at a minimum for an audio threshold. Even though 0% is supposed to be pure digital silence, with my test file I couldn’t get silence to trim unless I used a threshold larger than 0%. If you’d like, you can specify the threshold in decibels using d (such as -96d or -55d).
  • The realistic values for the above-period parameter are 0 and 1 and values for the below-period parameter are pretty much just -1 and 1. The documentation states that values larger than 1 can be used, but it only really makes sense for files with consistent audio breaks. Just trust me, it’s weird. I’ll get into what those values actually mean in the examples.
Now onto some examples! I’ll be showing you visually what happens to a sound file when we apply the various parameters to the silence filter.
I generated a test sound file with 60 seconds of white noise and then silenced various parts of the clip, leaving me with an audio file that looks like this:
SoX Silence Example (Original File)

Example 1: Trimming silence at the beginning

sox in.wav out1.wav silence 1 0.1 1%
The above-period parameter is first after the silence parameter, and for the sake of this article, it should be set to 1 if you want to use the filter. This example roughly translates to: trim silence (anything less than 1% volume) until we encounter sound lasting more than 0.1 seconds in duration. The output of this command produces the following:
sox in.wav out1.wav silence 1 0.1 1%
We’ve lopped off the silence at the beginning of the clip. For simplicity’s sake, we’ll refer to the 1% threshold as silence from now on.

Example 2: Ignoring noise bursts

sox in.wav out2.wav silence 1 0.3 1%
By changing the duration parameter to 0.3, we tell SoX to ignore the burst of noise at the beginning of the example clip. This produces the following:
sox in.wav out2.wav silence 1 0.3 1%
We can ignore short pops and clicks in audio by adjusting this duration parameter.

Example 3: Stopping recording when no sound detected

sox in.wav out3.wav silence 1 0.3 1% 1 0.3 1%
Now we introduce the below-period parameter it’s respective sub-parameters.  Just like the above-period parameter, just set it to 1 and call it good.  The command above translates to: trim silence until we detect at least 0.3 seconds of noise, and then trim everything after we detect at least 0.3 seconds of silence.
sox in.wav out3.wav silence 1 0.3 1% 1 0.3 1%
This returns a file with just the first 4 seconds of noise (note that we ignore that 0.25 sec burst of noise at the beginning). Where’s the rest of the clip?  Well, it’s gone. Not super practical for post-production of audio, but can be useful when recording live audio, so that SoX stops when it doesn’t encounter sound for a certain number of seconds.
So an aside: if you’re looking to trim silence from the beginning and the end of a audio file, you’ll need to utilize the reverse filter and a temp file like so:
sox in.wav temp.wav silence 1 0.1 1% reverse
sox temp.wav out.wav silence 1 0.1 1% reverse
Don’t forget to delete that temp.wav file when you’re done.
Jakob points out in the comments that you can trim silence from both ends in one fell swoop by chaining the effects like so:
sox in.wav out.wav silence 1 0.1 1% reverse silence 1 0.1 1% reverse

Example 4: Trimming all silence

sox in.wav out4.wav silence 1 0.1 1% -1 0.1 1%
By changing the below-period parameter to -1, we can trim instances of silence in the middle of the clip, by allowing the filter to restart after it detects noise of the specified duration.
sox in.wav out4.wav silence 1 0.1 1% -1 0.1 1%
In my example clip, it’s impossible to detect where the silence used to be, but with an actual podcast or other audio, it should be easier to tell.

Example 5: Ignoring short periods of silence

sox in.wav out5.wav silence 1 0.1 1% -1 0.5 1%
In similar fashion as Example 2, we can instruct SoX to ignore small moments of silence (1/2 second in this example).
sox in.wav out5.wav silence 1 0.1 1% -1 0.5 1%
When trimming silence from podcasts and the like, this prevents you from removing moments when someone stops to take a breath and making the conversation sound too rushed.

Example 6: Shortening long periods of silence

sox in.wav out6.wav silence -l 1 0.1 1% -1 2.0 1%
So what if you wanted to just shorten long moments of silence rather than remove them entirely?  Well, you need to add the -l parameter, but it needs to be placed first, before the other parameters for the filter effect. The example above results in trimming all silence longer than 2 seconds down to only 2 seconds long.
sox in.wav out6.wav silence -l 1 0.1 1% -1 2.0 1%
Note that SoX does nothing to bits of silence shorter than 2 seconds.

Example 7: Shortening long periods of silence and ignoring noise bursts

sox in.wav out7.wav silence -l 1 0.3 1% -1 2.0 1%
Finally, let’s tie it all together by trimming silence longer than 2 seconds down to 2 seconds long, but ignore noise such as pops and clicks amidst the moments of silence.
sox in.wav out7.wav silence -l 1 0.3 1% -1 2.0 1%
As a result you’ll see that we’ve cropped out the 0.25 seconds of noise at the beginning of the clip, but left the 0.5 seconds of noise in the middle.
For actual usage, you’ll probably want to specify something shorter than 0.3 seconds for the duration if you’re just trying to filter out pops and clicks.

Bonus Example 8: Splitting audio based on silence

sox in.wav out.wav silence 1 0.5 1% 1 5.0 1% : newfile : restart
Using SoX’s newfile pseudo-effect allows us to split an audio file based on periods of silence, and then calling restart starts the effects chain over from the beginning. In this example, SoX will split audio when it detects 5 or more seconds of silence. You’ll end up with output files named out001.wavout002.wav, and so on.

Final Thoughts

There you have it.  This is what I know about the silence filter effect in SoX.  Example 7–where we trim some but not all of the silence and ignore pops and clicks–is ultimately what I was trying to figure out when writing this article, but I figure the other examples have got to be a good reference for somebody me.
The above and below-period values are still mostly a mystery to me.  I may address them in another post, but for now, I’m just going to use this as a cheat sheet in case I forget.
And don’t forget to use the trailing zero when specifying whole seconds. Even while writing this I forgot multiple times.
I welcome thoughts, ideas, comments, and corrections. Please.