Generate some easy to remember passwords

Do not use this for sending sensitive data! For that please use a public key encryption scheme like PGP or GnuPG. This below is suitable for things such as online logins etc.

Obtain word list

Prepare a text file with dictionary words. Here we download some word lists from Scowl.

wget "http://downloads.sourceforge.net/wordlist/scowl-2016.01.19.tar.gz" && \
tar -zxvf scowl-2016.01.19.tar.gz --wildcards --strip-components=2 scowl-2016.01.19/final/english-words.*

We grab the file english-words.10 and english-words.20 which contain a lot of popular words, filter it and remove the words we don’t want. There are other files here too which you can use as well, though they may contain less commonly used words which may be more difficult to remember.

To make a word list from english-words.10 and english-words.20 with 5 chars or more

cat english-words.10 english-words.20 | grep -v "'" | grep -e "....." | uniq | xz -9 -e > words.txt.xz

On Mac OSX, you’ll need to set LANG=C otherwise you’ll get a charset error with uniq.

Count the number of words in the list. For my current test, there is 9481 words.

xz -dc words.txt.xz | wc -l

Generate a 4 word password

Let’s random sort and create a password with 4 words. We’ll capitalise the first letter as well.

On Mac OSX, install coreutils and gnu-sed on Homebrew.

Linux

xz -dc words.txt.xz | sort -R | head -n 4 | sed 's/^\(.\)/\U\1/' | tr -d '\n'

Mac

xz -dc words.txt.xz | gsort -R | head -n 4 | gsed 's/^\(.\)/\U\1/' | tr -d '\n'

Make 10 random 4 word passwords

The above command repeated 10 times.

Linux

for i in {0..9}; do xz -dc words.txt.xz | sort -R | head -n 4 | sed 's/^\(.\)/\U\1/' | tr -d '\n'; echo ""; done

Generate 10 random 3 word passwords

Make 10 random 3 word passwords

Linux

for i in {0..9}; do xz -dc words.txt.xz | sort -R | head -n 3 | sed 's/^\(.\)/\U\1/' | tr -d '\n'; echo ""; done

Mac

for i in {0..9}; do xz -dc words.txt.xz | gsort -R | head -n 3 | gsed 's/^\(.\)/\U\1/' | tr -d '\n'; echo ""; done

How to open Gerber files in AutoCAD with free open source tools

Here is a method for how you can import a Gerber RS-274X file into AutoCAD. There are many commercial software solutions to perform this, but this is how you can do it for free using open source tools!

You’ll need to install and configure (if needed) the following software.

  • gerbv – this is used to view Gerber files, and can also export to a variety of formats (but not DXF or DWG for AutoCAD)
  • pstoedit – converts Postscript files to many different other formats
  • ghostscript – needed by pstoedit

Open your Gerber files in gerbv. This process work for multiple layers as well. You should see your Gerber to make sure it is what it should be.

Export the Gerber set to PostScript. File -> Export -> Postscript…

Optionally, if you don’t need to visually check the Gerber file in gerbv, gerbv supports exporting via the command line, for example:

gerbv -x ps MYGERBER.GTL

Now convert the Postscript (.ps) file to DXF using pstoedit. This is best done on the command line.

pstoedit -f dxf foobar.ps foobar.dxf

Now you should have a .dxf file which you can open in AutoCAD.

Caveats

When working with multiple Gerber files and you export them all at once to one .ps file, and convert them to a single .dxf, all the information comes up in AutoCAD as a single layer, but the original layers can be differentiated by their colours.

However you could manually move different colours to new layers if need be (using QSELECT command in AutoCAD). This probably could be scripted, but that’s a bit beyond my means at the moment.

Moving WordPress blog across domains using the shell

Here’s a rundown, or more accurately a set of personal notes I made, for moving a WordPress blog from one domain name to another. This will also work when moving from one web host to another.

First you’ll need to know some details of your old database:

  • database host name, e.g mysql.yourdomain.com or localhost
  • database name
  • username
  • password

You can find these details in wp-config.php on the old WordPress site.

Create a new database on the new web host, and an appropriate user account which can be used to manage the database. You may need to do this in a web interface, e.g cPanel, as some web hosting companies only allow database creation and deletion via a web interface. Make note of these details of the new database, you’ll need these new details for the new site.

We’ll assume here that on your web host, web served files are stored in a subdirectory named the same as the domain name.

Old Blog

Save WordPress files from the old blog to blog_old.tar.gz:

tar -zcvf blog_old.tar.gz -C OLDDOMAIN.COM .

Save the old database to blog_db_old.sql. Use the details from the old database here.

mysqldump -uUSERNAME -p -h DBSERVER DBNAME --quick > blog_db_old.sql

Check the database dump is okay, we’ll just read the first couple of lines just to make sure all is well.

head blog_db_old.sql

New blog

Now we get to work on the new site. First up the archive of the WordPress files and database dump, move those onto the new server if required.

Write to new database and WordPress directory

Import the dumped SQL file from the old database, into the new database. You’ll need to type in here the details of the new database that was just created, and use a appropriate path to the archive files (the .tar.gz and .sql files).

mysql -h DB_SERVER -uUSERNAME -p DB_NAME < blog_db_old.sql

Extract contents of WordPress install into the new domain.

tar xvf blog_old.tar.gz -C NEWDOMAIN.COM/

Edit wp-config.php and enter in the new database details.

cd NEWDOMAIN.COM
vim wp-config.php

Search and replace operation on database

The database still references the old domain in its URLs. So we need to replace the domain name and URLs in database. There is a PHP script by interconnectit you can use, as a search and replace tool.

Download this handy database search and replace tool, unzip the single PHP file, and rename it:

wget http://www.interconnectit.com/wp-content/uploads/2011/05/searchreplacedb21.zip
unzip searchreplacedb21.zip
mv searchreplacedb2.php sr.php

Visit your new domain http://NEWDOMAIN.COM/sr.php to run the search and replace script.

  1. Select script to obtain database parameters from wp-config.php. Use this option, only if you have already edited wp-config.php on the new site with the new database details.
  2. Select all tables to perform the search and replace in.
  3. Type your search and replace parameters. Search for your old URLs and replace with your new URL. Take note of www. at the start of addresses. Some sites use it and some don’t (normally set in cPanel or equivalent interface). For example when I was moving sites from my old domain to this one, I searched for http://micro.gock.net and replace it with http://agock.com.
  4. Check your web site on the new domain and check all is working fine.

Remove the search and replace script once completed. Don’t leave this script on your web site.

rm sr.php

Alternate method

As an alternate method to using the above PHP script, we could have performed a search and replace on the SQL dump file, or peformed some search and replace commands directly on the databse using SQL queries.

Test web site

After performing the search and replace, the new site should work as normal. All media and user accounts should be as before. Visit your new site and check that it is all working fine.

Redirect the old domain

Once we know the new domain is working okay, we can remove the old files (remember you still backups from earlier). Make sure you’re in the right directory before doing the mass delete!

cd OLDDOMAIN.COM
rm -rf *

Set up a .htaccess file for the old domain.

touch .htaccess
vim .htaccess

Insert the following but replace with your site domain names:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

Test the redirection, by visiting an old URL, your browser should automatically redirect to the new domain name. This will redirect all pages. Search engines crawling your site should recognise this 301 redirect code, and update its indexes appropriately.

Finishing up

You can now delete the old database as well. This can be done via cPanel or similar web host interface, if that is the only method your web host allows.

Copy your old site archive (.tar.gz) and database dump (.sql) somewhere for safekeeping.

If you were using Google Analytics, remember to go and change the settings in there, you are able to change the site name and URL for a Google Analytics account / property. Also fix any linking with Google Webmaster Tools.