Parsia's Den

The knowledge of anything, since all things have causes, is not acquired or complete unless it is known by its causes. - Avicenna

Cheat Sheet

Feb 24, 2016 - 8 minute read - cheatsheet

Often I need to do something that I have done many times in the past but I have forgotten how to do it. This is a page (or a series of pages if it grows large enough) to give me a simple repository of how-tos that I can access online. In this page you may find those commands and tips that I need from time to time (and usually forget when I need them).


Insert xkcd, hur dur!

Compressing a directory using tar

tar -zcvf target_tar.tar.gz directory_to_be_compressed

Decompressing a tar.gz file

tar -zxvf target_tar.tar.gz path/to/decompress/


Dumping the TLS certificate using OpenSSL

echo | openssl s_client -connect HOST:PORT 2>/dev/null | openssl x509 -text -noout

TLS connection with a specific ciphersuite using OpenSSL

openssl s_client -connect HOST:PORT -cipher cipher-name -brief

  • -brief: reduced output
  • cipher-name: A cipher from output of openssl ciphers command

Amazon S3

Syncing a folder with an Amazon S3 bucket using s3cmd

python s3cmd sync --acl-public --delete-removed --rr directory-to-sync/ s3://bucket-name

For example uploading the Hugo public directory to my website:
python s3cmd sync --acl-public --delete-removed --rr public/ s3://

  • --acl-public: Anyone can only read.
  • --delte-removed: Delete objects with no corresponding local files.

Changing the mime-type of CSS file after upload to fix CSS not displaying correctly

python s3cmd --acl-public --no-preserve --mime-type="text/css" put public/css/hugo-octopress.css s3://

My runme.bat to upload my Hugo blog to the S3 bucket
rd /q /s public
rd /q /s public\post
del /s /a .\*thumbs*.db
del /s /a public\categories\*index*.xml
del /s /a public\tags\*index*.xml
python s3cmd sync --acl-public --cf-invalidate --delete-removed -MP --no-preserve --rr public/ s3://
python s3cmd --acl-public --no-preserve --cf-invalidate --add-header="Expires: Sat, 20 Nov 2286 19:00:00 GMT" --mime-type="text/css" put public/css/hugo-octopress.css s3://
rd /q /s public


Shortcut to IE (or WinINET) Proxy Settings

control inetcpl.cpl,,4

VHD File is Open in System (and cannot be Deleted)

You clicked on a VHD file and now cannot delete it. Use this PowerShell command but the path to VHD should be full.

Dismount-DiskImage -ImagePath 'C:\full\path\to\whatever.vhd'

Base64 encode/decode without PowerShell

Use certutil for bootleg base64 encoding/decoding:

  • certutil -encode whatever.exe whatever.base64
  • certutil -decode whetever.base64 whatever.exe


where.exe searches for files. Without any locations, it searches in the local directory and then in PATH.

  • /R searches recursively in a specific location.
  • /T displays file size.
  • /? for help.

Delete file or directory with a path or name longer than the Windows limit

Answer from

mkdir empty_dir
robocopy empty_dir the_dir_to_delete /s /mir
rmdir empty_dir
rmdir the_dir_to_delete

Install “Bash for Windows” without Windows Store

lxrun /install.


List all files (including hidden)

Get-ChildItem "searchterm" -recurse -force -path c:\ | select-object FullName

  • -recurse: recursive. Loops through all directories
  • -force: list hidden files.
  • select-object: Selects each file from last point
  • FullName: Only display file name

Diff in Powershell

Compare-Object (Get-Content new1.txt) (Get-Content new2.txt) | Format-List >> Diff-Output

Output will be in format of

  • InputObject: c:\users\cigital\somefile – line content
  • SideIndicator: => – exists in new2.txt (second file, file to the right)

Pseudo-grep in Powershell

findstr "something" *.txt

will include filename and line (no number AFAIK)

findstr /spin /c:"keyword" *.*

  • /s: recursive - will search through the current directory and all sub-directories
  • /p: skip binary files (or files with characters that cannot be printed)
  • /i: case-insensitive - remove if you want case sensitive search
  • /n: print line number

If you want to search for different keywords (with OR) remove the /c:

findstr /spin "keyword1 keyword2" *.*

will search for keyword1 OR keyword2 in files

grep in command outputs

whatever.exe | Select-String -pattern "admin"

Get-Acl and icacls.exe

Get-Acl -path c:\windows\whatever.exe | Format-List

icacls.exe c:\windows\whatever.exe

time in PowerShell

Measure-Command {python}

Some Git stuff because I keep forgetting them

Create new branch and merge

This works with small branches (e.g. one fix or so). Adapted from a Bitbucket tutorial.

  1. Create new branch - git branch fix-whatever
    This will create a branch of whatever branch you are currently on so make sure you are creating a branch from the branch you want.

  2. Switch to the branch - git checkout fix-whatever

  3. Make changes and commit - git add - git commit
    Make any changes you want to do, then stage and commit.

  4. Push the branch to remote repo [optional] - git push
    This can be safely done because it’s an obscure branch and no one else cares about it.

  5. Go back to the original branch to merge - git checkout master
    Master or whatever branch you were at step one.

  6. Merge the branches - git merge fix-whatever.
    Alternatively squash all commits into one git merge --squash fix-whatever and then git commit -m "One message for all commits in merge".

  7. Delete branch - git branch -d fix-whatever
    We don’t need it anymore. If it was pushed to remote, then we need to delete it there too.

Only clone a certain branch

git clone -b <branch> <remote_repo>

Undo remote git history after push

Because this keeps happening to me.

  1. Reset the head in local repo N commits back. - git reset HEAD~N
    Where N is the number of commits that you want to revert.

  2. Make changes and stage them - git add

  3. Commit the changes - git commit

  4. Force push the local repo to remote - git push -f
    Note this will force the update and erase the commit history online. If not one else is using the repo in between it’s ok.

Update local fork from original repo

  1. See current remotes - git remote -v

  2. Make original repo the new remote upstream -
    git remote add upstream

  3. Now we should see the new upstream with - git remote -v

  4. Fetch upstream - git fetch upstream

  5. Switch to your local master branch - git checkout master

  6. Merge upstream/master into local master - git merge upstream/master

  7. Push changes - git push

Use Notepad++ as git editor on Windows via Cygwin

Create a file called npp with the following content and copy it to cygwin\bin. Modify the path of notepad++ to point to your installation.

'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin "$(cygpath -w "$*")"

Run the following command in Cygwin to set it as global git editor:

$  git config --global core.editor npp

Tab size 4 in Github web interface

Yes I know Github != Git but cba to create a different category.

Add ?ts=4 to end of file URL.

Sublime Text 3

Tips for using the Sublime Text 3 editor.

Fix “MarGo build failed” for GoSublime on Windows

GoSublime’s executable has Go version in it. In most cases, it cannot grab the version on Windows machine and as a result the build will fail like this:

MarGo: MarGo build failed
cmd: `['C:\\Go\\bin\\go.exe', 'build', '-tags', '', '-v', '-o', 
       'gosublime.margo_r17.12.17-1_go?.exe', 'gosublime/cmd/margo']`

Where ? is the go version that is unknown.

Edit this file:

  • %AppData%\Sublime Text 3\Packages\GoSublime\gosubl\

Find these lines:

cmd = ShellCommand('go run sh-bootstrap.go')
cmd.wd = gs.dist_path('gosubl')
cr =
raw_ver = ''
ver = ''     # Edit this to '1'

Edit ver to whatever, I usually do 1. Restart Sublime Text and it should work.

Unfortunately this needs to be done for every new GoSublime version.

Open the same file in a new tab

File > New view into File. Then drag the pane to a second screen/location.

Download Youtube videos with substitles

I love Wuxia (Chinese martial arts if I am not mistaken) series and movies. The following youtube-dl command will download the 56 episode HQ quality Chinese TV series called Xiao Ao Jiang Hu or Laughing in the Wind (also called The Smiling Proud Wanderer or Swordsman).

youtube-dl --ignore-errors --write-srt --sub-lang en --yes-playlist ''

--ignore-errors: continue after errors
--write-srt    : download substitles
--sub-lang     : subtitle language (in this case English)
--yes-playlist : link to a Youtube playlist

Youtube-dl can be downloaded using pip. For example on Windows:
python -m pip install youtube-dl.

Before printing, get to printer physically and use the following instructions:

  1. Open the back.
  2. Press the two green handles down.
  3. Open manual feed in front.
  4. Adjust the paper guide and put the envelope in.
  5. Put the envelope face up (the side that has the addresses should be up).
  6. Insert it until the printer says Please Wait and grabs the paper.

Now open LibreOffice and use these instructions:

  1. Create new document in LibreOffice Writer (Word).
  2. Insert > Envelope.
  3. Enter destination in Addressee.
  4. Check Sender and enter your own address in the bottom textbox.
  5. Select Printer tab.
  6. Select printer and press Setup.
  7. Select the Brother printer and press Properties.
  8. Select the following options:
    • Paper Size: Com-10.
    • Media Type: Envelopes.
    • Paper Source > First Page: Manual.
  9. Print

Tags: tips and tricks

Go Notes

comments powered by Disqus