Skip to content

Instantly share code, notes, and snippets.

@jerivas
Last active October 19, 2017 04:25
Show Gist options
  • Save jerivas/a2f321bb8fa4d305a481 to your computer and use it in GitHub Desktop.
Save jerivas/a2f321bb8fa4d305a481 to your computer and use it in GitHub Desktop.
Bunch of random useful commands I've encountered/put together

Useful commands

Bunch of random useful commands I've encountered/put together.

Use Liquid Prompt (useful bundle of shell customizations)

https://github.com/nojhan/liquidprompt

Find files by extension and convert newlines with dos2unix

find . -regex ".*\.\(html\|css\|js\|scss\)" | xargs dos2unix

Extract plain text from PSD

strings input.psd | grep "<photoshop:LayerText>" | sed -e "s|^[ \t]*<photoshop:LayerText>||" | sed -e "s|</photoshop:LayerText>||" > output.txt

Quick Django Posgtres DB setup

sudo su - postgres

createuser -DRPS db_user (new user can't create DB, roles and is not superuser; prompt for password)

createdb db_name -O db_user (new DB with the previous user as owner)

Quick Django MySQL setup

mysql -u root -p
create database db_name;
grant usage on *.* to db_user@localhost identified by 'password';
grant all privileges on db_name.* to db_user@localhost ;

Postgres export/import without the postgres user

pg_dump -c -U database_user -h localhost -f dump.sql database_name

psql -U database_user -h localhost database_name < dump.sql

Setup virtualenvwrapper in a Webfaction account

easy_install-2.7 pip

pip install virtualenv virtualenvwrapper

nano $HOME/.bashrc

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
source $HOME/bin/virtualenvwrapper.sh

source $HOME/.bashrc

Rsync some Mezzanine media files

rsync -avz --exclude ".thumbnails*" user@host:/home/user/webapps/app/static/media/uploads static/media/

Zip your git repo

git archive HEAD --format=zip > archive.zip

Ultimate find+grep combo for Django projects

find . ! -path "*/migrations/*" -regex ".*\.\(html\|py\|js\|css\)" -exec egrep --color -Hin "search_term" {} \;

Find and replace multi-line pattern in files returned by find

find . -name "*.html" -exec perl -i -p0e 's@Find with \n newlines@Replace with this@s' {} \;

Replace on all files recursively

find . -type f -exec sed -i s/<target>/<replacement>/ {} \;

Install a .deb from command line

sudo dpkg -i foobar.deb

Automatically install missing dependencies when a .deb installation fails

sudo apt-get -f install

Import a blog via RSS to populate your Mezzanine site

pip install feedparser python-dateutil
python manage.py import_rss --mezzanine-user=admin --rss-url=https://www.djangoproject.com/rss/weblog/
pip uninstall feedparser python-dateutil

Find out Linux distro version

cat /etc/*-release

Download stuff from file and replicate structure

wget -xi urls.txt

Upload your public SSH key to the server (for future password-less logins)

ssh user@example.com "echo `cat ~/.ssh/id_dsa.pub` >> .ssh/authorized_keys; chmod go-w .ssh; chmod 600 .ssh/authorized_keys"

Convert a db from MySQL to Postgres

cd
wget https://raw.githubusercontent.com/lanyrd/mysql-postgresql-converter/master/db_converter.py
mv db_converter.py ~/bin
chmod +x ~/bin/db_converter.py
mysqldump --compatible=postgresql --default-character-set=utf8 -p -r db_name.mysql -u mysql_db_user mysql_db_name
python2.7 ~/bin/db_converter.py db_name.mysql db_name.psql
psql -U psql_user psql_db_name < db_name.psql

Convert video to web-friendly

# MP4 output, H264/AAC
ffmpeg -i quickfox.mkv -c:v libx264 -crf 28 -c:a aac -b:a 256k -strict experimental quickfox.mp4
# WEBM output, VP8/Vorbis
ffmpeg -i quickfox.mkv -c:v libvpx -crf 10 -c:a libvorbis -b:v 1M -qscale:a 7 quickfox.webm
# Extract a 1 frame (at 0.5s) to a PNG
ffmpeg -ss 0.5 -i video.mp4 -vframes 1 frame.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment