# Dos command history

One of the nice things of Linux is the command history – it stores typically the last 1000 commands or so and its saved every time you log out.

DOS does have this through the doskey /history command (but only for current session) and you can relatively easily append this to a file:

The tricky bit is having this done for you on log out.

Via a Stack Overflow question on bash_history you can get close, using doskey macros which appends to a file on exit.

This only works for the current session though so you need to create a shortcut that runs the command each time with the following Target:

Then you just have to remember to type exit each time…

### Update

I also found three useful commands – but they’re only for your current session. Hat tip to Nifty Computer Tricks:

F3
get last command
F7
current list (use left/right arrow keys to paste to the command line)
F8
auto-complete (type the first few letters)

### Update 2 – Some extra love for the DOS prompt…

If you’ve got this working then I’ve added some extra basics. First you need to install Git (and I suggest you do it using the Chocolatey package). This includes the best versions of gnu commands compiled natively for Windows.

Add the Git usr bin directory to the path e.g. C:\Program Files\Git\usr\bin.

Put the !.bat and history.bat into the Git usr bin directory too. These assume you are saving the history to %USERPROFILE%\history.log.

Then you’ll be able to do commands like history | grep mysql to list all your mysql commands in history.log with their line numbers. Then call ! 123 to execute the specific line of the history.log file.

### Update 3 – Clink love

Martin Ridgers’ Clink is an awesome tool to behold. That adds the correct ! command to the DOS command prompt. Buuuuuuut… it doesn’t include a history command. So save the above history.bat file to C:\Windows\System32\history.bat (it doesn’t have to rely on GNU Tools / Git) and uncomment history_file=%localappdata%\clink\.history.

# OpenVPN connects to VPN but no internet

For those stumbling down a similar path…

tldr; Check that your Windows Firewall is turned off.

## My setup

• OS: Windows 8.1 64-bit laptop
• OpenVPN: OpenVPN 2.3.4 x86_64-w64-mingw32

My OpenVPN has been working for at least 4 months without problem.

First thing to remind yourself is: When you get the VPN working – copy the OpenVPN log of a successful connection and the ipconfig /all to file so that you know what to compare when it breaks next time.

## Notes

• The VPN connection stopped working yesterday 17/10/2014
• Not exactly sure when
• It had been working at my office
• My Windows 7 desktop has a working VPN setup so I can compare the settings
• The OpenVPN gui suggests a connection has been made but no sites can be pinged (see commands below)
• All attempts at inconfig /renew, ipconfig /flushdns nothing worked
• Only differences between Desktop/Laptop I could find in ipconfig /all and OpenVPN logs was that laptop had IPv6 for the WiFi connection turned off and the following extra fail message UDPv4: No Route to Host in the log
• I tried turning IPv6 back on but that didn’t change anything
• Now the UDPv4 message disappeared – but didn’t reappear when I turned off IPv6 again – so that was a red herring
• Possible suggestion from my history when first setting up my VPN (http://www.rickygao.com/troubleshooting-general-failure-in-ping-or-tracert/) was to turn off IPv6 which is what I’d probably done before – but IPv6 is no problem on my Windows 7 desktop
• Pinging even a specific IP address does not work – this confirms its not a DNS issue
• Pinging localhost 127.0.0.1 does work
• Pinging the IP Address of the connected VPN does work
C:\Users\Ian>tracert google.com
Unable to resolve target system name google.com.

Ping request could not find host google.com. Please check the name and try again.


## Solution

Eventually found a solution that was to turn off the windows firewall, which came from this unbuntu forums post which eventually spotted that it was an iptables firewall issue.

## Post mortem

• I thought I’d turned off my firewall and it doesn’t explain why the VPN stopped working
• Best guess is a Windows update changed something in the firewall the caused the problem
• A failed update for Windows Malicious Software Removal Tool for Windows 8, 8.1 and Windows Server 2012, 2012 R2 x64 Edition - October 2014 (KB890830) – this was successfully installed the next day but didn’t help
• A successful Definition Update for Windows Defender - KB2267602 (Definition 1.185.3528.0)

# Google Docs to Markdown to WordPress

I’ve started a fairly standard process of writing a Google Doc when I’m trying to learn something technical that I don’t understand and then if its half useful posting it to WordPress.

I know I could then copy paste the code from there to WordPress – but I’m a fan of writing WordPress posts in Markdown. For one reason, I need to switch all the titles to be one level lower in WordPress than Google Docs and its simpler to do that in Markdown. Also and code I put into Courier font in Google docs gets converted to code in Markdown, but gets lost when copying and pasting.

So I’ve found that there’s a script to export Google Docs. There is an annoying issue in that you have to re-do the steps everytime you want to export a document to Markdown. To get around this, I suggest that you just have one document that you use for converting to Markdown and copy/paste each Google Doc into that. Upon running the script from the Script Editor you get emailed a markdown version of your document.

Then copy & paste the markdown syntax into WordPress.

# Windows Netbeans Composer notes

This is for installing the main packages that Netbeans suggests in the Tools > Options > PHP (tab)

I’m running the following setup currently [21st April 2015]:

• Windows 8.1 (64-bit)
• Netbeans 8.0.2
• The version of Composer doesn’t really matter
• PHP 5.3.28 (It’s sooo last decade, I know…)

## tldr;

Just the commands:

composer global require "phpunit/phpunit=4.6.*"
composer global require "phpunit/phpunit-skeleton-generator=*"
composer global require "squizlabs/php_codesniffer=*"
composer global require "phpmd/phpmd=@stable"
composer global require apigen/apigen:~2.8


Then the files to call are in C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\

## Global packages

running composer global installs the packages into %APPDATA%\Composer (or ~/.composer/ in Linux)

### PHPUnit

From the installation instructions (https://phpunit.de/manual/current/en/installation.html) do:

composer global require "phpunit/phpunit=4.6.*"

This installs PHPUnit to C:\Users\[username]\AppData\Roaming\Composer\vendor\phpunit and puts the binary to use in Netbeans in C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpunit.bat

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpunit.bat into Netbeans Tools > Options > PHP (tab) > Frameworks & Tools (tab) > PHPUnit section.

#### Skeleton Generator

From the installation instructions (https://github.com/sebastianbergmann/phpunit-skeleton-generator) run:

composer global require "phpunit/phpunit-skeleton-generator=*"

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpunit-skelgen.bat into Netbeans Tools > Options > PHP (tab) > Frameworks & Tools (tab) > PHPUnit section.

### PHP_CodeSniffer

composer global require "squizlabs/php_codesniffer=*"

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpcs.bat into Netbeans Tools > Options > PHP (tab) > Code Analysis (tab) > Code Sniffer section.

### Mess Detector

composer global require "phpmd/phpmd=@stable"

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpmd.bat into Netbeans Tools > Options > PHP (tab) > Code Analysis (tab) > Mess Detector section.

### apigen

composer global require apigen/apigen:~2.8

For me this failed see apigen issue #316. The answer to that was to use ~4.0, but that requires PHP >= 5.4

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\apigen.bat into Netbeans Tools > Options > PHP (tab) > Code Analysis (tab) > ApiGen section.

# Translating WordPress plugins

If you didn’t write the plugin – how do you translate it? I found lots of information for plugin developers to make their plugins translatable but not for people that just want to translate it.

## Executive summary / tl;dr

Edit: The Codestyling Localization plugin I suggested previously isn’t available from WordPress directly any more.

Instead there seems to be an equally good plugin Loco Translate that is complemented by the developers own site for translating any application.

Failing that try the ‘Blank WordPress POT’ with POEdit and put that in the plugin’s languages directory. This seems to be a rock solid approach but takes a bit of learning.

If you put your translations in the plugins language directory, you’ll lose your translations when the plugin gets updated. Either keep backups or, if the plugin loads the translations correctly, you can put your translations in the separate wp-content/languages/[plugin-name] directory.

## For worker ants who want to know a bit more

1. The plugin must be translatable (It has been internationalized)
2. You can check this by looking through the plugin code
3. Otherwise just carry on and hope that the developer made it translatable
4. Then you need to create a translation file that converts the English words into your language (localize it)
5. A POT (.pot) file is a skeleton file that contains all the words and phrases in the plugin that can be translated
6. A .po file is a .pot file that has had the translated strings in your language added next to each of the translatable phrases
7. When you save a .po file it also generates a .mo file (where as you can read a .po file in notepad you can’t read a .mo file)
8. WordPress plugins rely on .mo files
9. You first need to find the .pot file
10. Typically this will be in the root of the plugin directory
11. Or it will be in a languages directory
12. If you find it, great. Open it in POEdit, do your stuff and save
13. If it hasn’t been created at all …
14. … Then you need to check in the code (look for load_plugin_textdomain in the main plugin file) to see where/if you should create one and create the .pot file yourself

If you don’t know about editing PO files I suggest following the WordPress instructions on using POEdit.

## For developers to ‘internationalize’ their plugins

I recommend using the Blank WordPress POT file that I mention below in the POEdit revisited section.

## Translation fumbling

### POEdit

Initially I tried the POEdit method recommended in WPMU DEV tutorial

However the POT files that I made never worked – they didn’t pick up the translated words. I think it was because of __() and _e() instead of __ and _e.

### makepot.php

• WordPress
and Tom McFarlin talk about using makepot.php but its confusing if you’re not using Linux
• It requires using the wp-plugin as the project name which I assumed that you changed to the name of your plugin but you don’t – it has to stay wp-plugin
so the required command is (for windows):
• cd path\to\tools\i18n
• php makepot.php wp-plugin path\to\plugins\your-plugin-name
• However I got the following error when running it from windows
• 'msguniq' is not recognized as an internal or external command
• This appears to be because msguniq is a linux command
• Actually this had created the your-plugin-name.pot file in the plugin directory but I just didn t realise because of the error
• If you do want to use makepot.php use grapper’s Github i18n repo which includes all the correct WordPress files rather than the official WordPress subversion directories.

### POEdit revisited

Hidden at the end of the WordPress localization document is the excellent ‘Blank WordPress POT’.

That can be put in the plugin’s languages directory and has instructions for creating the PO files from it:

The pot file include in this folder is ready to use.

1. Double click on it and open it with poedit
2. In poedit goto File → New Catalog from POT file…
3. Select and Open the pot file from the languages folder
4. Enter your name, email address, your language and country (i.e. french fr_FR, german de_DE) to the setting form
5. Click the update button in the main poedit ui.
6. Save the file :
7. For a plugin like filename-xx_XX.po with xx_XX for your language and country.
8. For a theme xx_XX.po
9. That’s it, go to your WordPress blog and see your translation in action. N’joy your blogging!!!

This actually worked first time that I tried it – i.e. it pulled in all the translated strings.

First off you can then save the file as a my-plugin-name.pot file in the languages directory. Then you can add in your translations and save it with the locale xx_XX.po file ending and that should generate the .mo file that you need too.

## Plugins

Edit: The simplest route was via the Codestyling Localization plugin.

But that is no longer available through the WordPress plugins directly – possibly because it isn’t working or from a security issue. It is still available via the developer’s own site though

Instead you can use Loco Translate which appears to be excellent – but I haven’t tried it.

(These are old instructions for Codestyling Localization) Once it is installed:

2. Select your locale and it generates an empty .po file
3. Click ‘Rescan’ to populate the .po file
4. Click ‘Edit’ and ‘generate mo file’ to get the .mo file out

None of this solves the problem that you will lose your translation files once when the plugin is updated.

Copy your .po files into the wp-content/languages/[plugin-name] directory – which might or might not work. If yes, great, if not raise a support query (be nice and give details) with the plugin developer.

This directory is update safe basically because of the translations are loaded with the following priority:

1. wp-content/languages/[plugin-name] (never changed by updates)
2. wp-content/languages/plugins/ (changed with updates)
3. wp-content/plugins/[plugin-name]/languages (changed with updates)

If developers follow this Geert DeDeckere’s excellent guide on loading WordPress language files the right way then there shouldn’t be a problem with using the wp-content/languages directory.

You can also read WooCommerce’s documentation on Making your Localization upgrade safe which recommends either Loco or using /wp-content/languages/woocommerce.

I found these two Support questions useful for learning about handling upgrades:

# TeX fonts for the Web

I love the fonts that come out of LaTeX. However I’ve never seen sites displayed using the same fonts, so I wanted to find if it was available to put on a website.

TLDR; It looks like you can get a very close free font called Latin Modern Roman.

### Self help

This meant a bit of self education to see if I could get the fonts on the web. Donald Knuth created a program Metafont to create the font which is called Computer Modern and is part of the AMS Type-1 fonts. However there doesn’t appear to be any direct web fonts (i.e. .eot + .otf + .woff + .svg) files for Computer Modern. The best I found was the Unicode otf font that you can download for windows.

### Latin Modern

However one ‘Computer Modern woff’ search did bring up a monotype font Latin Modern Mono, which has in its notes:

The Latin Modern fonts are derived from the famous Computer Modern fonts designed by Donald E. Knuth and first published by the American Matematical Society (AMS) in 1997. One of the main extensions is the addition of an extensive set of diacritical characters, covering many scripts based on the Latin character set, mainly european, but not only, most notably Vietnamese.

Then its a short hop to the actual serif font (which doesn’t have those helpful notes, so you don’t find it on the internet). So I give you Latin Modern Roman the Computer Modern font for the web.

### D’Oh

Of course now that I’ve found it, I’ve acutally spotted that there was a link in one of the first places I found, the wonderous stack exchange: http://tex.stackexchange.com/questions/131606/whats-the-font-used-in-the-environment-align-and-packages-amsmath-amsfonts . I’d just followed the first Unicode link instead of reading further.

# Mini Plesk – VirtualHosts in Apache

There is Apache Documentation for setting up Virtual Hosts, good luck if you can implement something sensible direct from that, but otherwise read on.

After umming and ahhing I finally decided to get some proper virtual hosts set up on a webserver of mine. This was brought on by creating a virtual host for a separate domain that completely overtook the default domain even though I didn’t think it should.

I also noticed that there is a sites-available and a sites-enabled directory in the /etc/apache2 directory. So a quick Google search brought up Hosting multiple websites with Apache2.

I followed this guide except for:

1. using an extra vhosts directoryi.e. /var/www/vhosts (to agree with plesk)
2. calling the htdocs directory httpdocs e.g. /var/www/vhosts/mydomain.com/httpdocs (again to agree with plesk)
3. logs directory should be put in /var/www/vhosts/mydomain.com/statistics/logs rather than /var/www/vhosts/mydomain.com/logs
4. To fix a bug I hit (see Trouble Shooting below), I used *:80 in the VirtualHost tag

Here is my domain.com file:

#
# domain.com (/etc/apache2/sites-available/domain.com)
#
<VirtualHost *:80>
ServerName  domain.com

# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/vhosts/domain.com/httpdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/vhosts/domain.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>

# Logfiles
ErrorLog  /var/www/vhosts/domain.com/statistics/logs/error_log
CustomLog /var/www/vhosts/domain.com/statistics/logs/access_log combined
</VirtualHost>


## Trouble shooting

I kept getting the following error after following the guide:

NameVirtualHost *:80 has no VirtualHosts

Took me a while to figure out the problem, but I eventually tracked it down to the fact that there is already a NameVirtualHost defined in /etc/apache2/ports.conf and I had disabled the default site which was the only virtual host defined on *:80. The article wants you to create another file with this directive for * and then only include * for all virtual host definitions.

The Apache documentation is quite scathing about using just *:

To receive requests on all interfaces, you can use an argument of *:80, or, if you are listening on multiple ports and really want the server to respond on all of them with a particular set of virtual hosts, *

So I then did the following:

1. Commented out all code in the conf.d/vhosts.conf file as its not required
2. Put *:80 (not *) in all the VirtualHost definitions for the sites in sites-available

## SSL

The above article doesn’t explain about setting up SSL/HTTPS domains. I think from Plesk 10 onwards both http and https used the httpdocs directory by default, so we just need to copy the existing domain.com file and copy it to doman.com-ssl and then merge in some details from the default-ssl file.

I followed this How To Set Up An SSL Vhost Under Apache2 On Ubuntu article and I ended up with the following domain.com-ssl config file:

#
# https://domain.com (/etc/apache2/sites-available/domain.com-ssl)
#
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName  domain.com:443

# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/vhosts/domain.com/httpdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/vhosts/domain.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>

# Logfiles
ErrorLog  /var/www/vhosts/domain.com/logs/ssl_error_log
CustomLog /var/www/vhosts/domain.com/logs/ssl_access_log combined

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   A self-signed (snakeoil) certificate can be created by installing
#   the ssl-cert package. See
#   If both key and certificate are stored in the same file, only the
#   SSLCertificateFile directive is needed.
SSLCertificateFile    /etc/ssl/certs/domain.com.pem
SSLCertificateKeyFile /etc/ssl/private/domain.com.key

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
#SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#   Note: Inside SSLCACertificatePath you need hash symlinks
#         to point to the certificate files. Use the provided
#         Makefile to update the hash symlinks after changes.
#SSLCACertificatePath /etc/ssl/certs/
#SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

#   Certificate Revocation Lists (CRL):
#   Set the CA revocation path where to find CA CRLs for client
#   authentication or alternatively one huge file containing all
#   of them (file must be PEM encoded)
#   Note: Inside SSLCARevocationPath you need hash symlinks
#         to point to the certificate files. Use the provided
#         Makefile to update the hash symlinks after changes.
#SSLCARevocationPath /etc/apache2/ssl.crl/
#SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/ #</Location> # SSL Engine Options: # Set various options for the SSL engine. # o FakeBasicAuth: # Translate the client X.509 into a Basic Authorisation. This means that # the standard Auth/DBMAuth methods can be used for access control. The # user name is the one line' version of the client's X.509 certificate. # Note that no password is obtained from the user. Every entry in the user # file needs this password: xxj31ZMTZzkVA'. # o ExportCertData: # This exports two additional environment variables: SSL_CLIENT_CERT and # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the # server (always existing) and the client (only existing when client # authentication is used). This can be used to import the certificates # into CGI scripts. # o StdEnvVars: # This exports the standard SSL/TLS related SSL_*' environment variables. # Per default this exportation is switched off for performance reasons, # because the extraction step is an expensive operation and is usually # useless for serving static content. So one usually enables the # exportation for CGI and SSI requests only. # o StrictRequire: # This denies access when "SSLRequireSSL" or "SSLRequire" applied even # under a "Satisfy any" situation, i.e. when it applies access is denied # and no other module can change it. # o OptRenegotiate: # This enables optimized SSL connection renegotiation handling when SSL # directives are used in per-directory context. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire <FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /cgi-bin>
SSLOptions +StdEnvVars
</Directory>

#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>

`

# How To Report A Bug

From Hacker News to the Greatest Bug I Never Fixed to a wonderful comment in the Perl doc forums:

I submitted a proposal to OSCON called “How To Report A Bug” about the social issues involved in reporting and accepting bug reports. Its still pending, but its caused me to do a little writing for it. I came up with this introduction which I feel sums up the problem well. I’m also tickled that one measures bug report frustration in bags of shit.

Developers often treat bug reports like someone dumping a bag of shit on your doorstep, ringing the bell and telling you to clean it up. That’s not what they are. A bug report is someone pointing out that there’s some shit on your doorstep, they stepped in it, and maybe it should be cleaned up.

Either way, nobody likes stepping in shit. And nobody likes cleaning up shit. So the whole interaction starts off on the wrong foot, perhaps the one covered in shit. Your job, as developer or as reporter, is to deliberately steer it back to being a positive one where the developer wants to fix shit and the reporter wants to continue to report shit.