Ping from PowerShell: Test-Connection

March 7, 2016 | No comments

Query DNS from PowerShell: Resolve-DnsName

March 7, 2016 | No comments

I just released version 0.4 of my Smart Quotes WordPress plugin. It works with WordPress versions 3.4 and 3.5 now (guess I am a bit behind on these things).

Download “Smart Quotes” (.zip) now

This isn’t really new, but it’s sure worth knowing… The fact that there’s a 128K buffer used to pass arguments to child processes in the Linux Kernel can have the following effect on shell external commands:

When you run commands such as rm spam* the shell (e.g. bash) will expand the “spam*” to a list of names of all files in the working directory that start with “spam”. That list is then passed to the executable /bin/rm using the 128K buffer mentioned above. If you have a large number of files, or the list gets long because of long file names, you may get an error message saying /bin/rm: Argument list too long.

To work around this you can get the list of filenames using find and pipe it to xargs which in turn invokes rm for every single file. There is no limit on the size of a pipe (or at least none that I am aware of for this practical purpose). Here’s the full command:

find . -name 'spam*' -print0 | xargs -0 rm

This differs from similar commands you might find in the -print0 and -0 arguments: These are needed in case you have spaces in your filenames.

For an in-depth explanation of both the 128K buffer and the spaces in filenames issue you may also want to read the May 2004 update in this blog post. (See, I told you it’s not really new.)

Let’s assume you have a value in cell E2 that has several components separated by slashes, e.g. a file path. You may find yourself in the position that you need to truncate the value at the last slash, e.g. get the full path of the folder that your file resides in.

E
2 /path/to/folder/file

The following formula will do the job:

=LEFT(E2,SEARCH("%",SUBSTITUTE(E2,"/","%",LEN(E2)-LEN(SUBSTITUTE(E2,"/",))))-1)

This will return “/path/to/folder”.

Please note that for the formula to work “%” must not be present anywhere in your value. If your value contains “%” you should substitute that in the formula with another character that is not present. (Know your legal characters!)

Update: Works in LibreOffice Calc, too, and I presume OpenOffice Calc will be no different.

In case you’ve ever wondered what the monthly traffic allowance in your web hosting plan means in bandwidth, here’s an easy-to-remember number:

3.19 (month kbit) / (sec GB) – I shall call this the Brian Adkins number

Under the assumption that traffic from a web server only flows in one direction it means that for every GB (gigabyte) of monthly traffic included in your plan you could consume 3.19 kbit/s constantly. Or for every TB (terabyte) of traffic allowed per month you can transmit data at a constant rate of 3.19 Mbit/s.

I have recently released my newest WordPress plugin to the public:

Smart Quotes should appeal to the international audience. E.g. if you’re a German writer and would like to use German book style quotation marks (»…«) even when you type so-called "dumb" quotes or use the <q> element: This plugin is for you!

Right now the plugin comes with shortcuts for Croatian/Hungarian/Polish/Romanian style quotation marks („…”), Czech or German style („…“), Danish (or German books) style (»…«), Finnish or Swedish style (”…”), French style (« … » – with spaces), Greek/Italian/Norwegian/Portuguese/Russian/Spanish/Swiss style («…» – without spaces), Japanese or Traditional Chinese style (「⋯」), but you’re free to manually enter/paste any arbitrary characters or character combinations.

Download “Smart Quotes” (.zip) now

After you’ve installed the plugin go to your Wrting Settings screen where you will find this:

Screenshot of Smart Quotes Settings

Right now the plugin comes in English and with a German translation, but for “Smart Quotes” I’d be particularly interested in adding more languages. Contact me if you think you can help! The .POT file for this one is really small, so I’m thinking it could be a quick fix. – If you have never translated software before: this thread on Lester Chan’s Forums is a good start and it’s specific to WordPress plugins.

I use revision control systems for almost all of my software development, deployment, and server configuration. When using Subversion there is, technically, no difference between a working copy on my personal or development machines vs. a working copy on a production server. (Yes, you need a working copy on the production server, because exports cannot be updated that easily.) However, modifications of the checked out code or config files on a production server can cause problems with the next round of updates. Sometimes you just don’t notice that there are conflicts that need to be resolved.

To make sure I notice when a colleague or I have fallen back into the bad habit of changing things on a production server directly, rather than checking in changes to the repository, I have created a Nagios Plugin: it’s called “check_svnstatus”

Click here to download the plugin and to see an example configuration

I’m using the post-commit hook to send out E-mail notifications when changes are committed to Subversion repositories.

If you search the web you’ll find a ton of scripts in various languages for this purpose. They all do more or less the same thing: create an E-mail message for the commit, including such details as the revision author, number, timestamp, a list of the paths that were changed, and a diff of the changes.

For one particular project I wanted the diff as an attachment, though, rather than inline in the message text. So I ended up writing my own script. It’s a Shell script that should work on most Unix/Linux based systems.

Click here to view the source code and installation instructions

Webduino, the web server library for Arduino, now supports HTTP Basic access authentication. You can download a .zip file of the latest version from GitHub. (Note: The download link does not point to a specific version, but always to the very latest version of Webduino including features and/or bugs that were added/fixed after I wrote this post. Here’s the front page of the GitHub repository.)

Authentication means that you can now protect the web-enabled functions of your Arduino with a username and password.

There is at least one other version of Webduino supporting authentication, written by Claudio Baldazzi. It’s in this post on the original Google Project site of Webduino, with an example here. When I started working on improvements of the Webduino, plus new features for my own use, I considered using Claudio’s version but decided against it for the following reason:

With the Claudio’s version all pages of the Arduino would be protected by the same username and password. However I wanted a way to distinguish different user levels. E.g. Person A should be allowed to see on the web whether the lights are on or off, but only Person B is allowed to flick the switch.

Here’s how I did it.

The WebServer class now has two new methods: httpUnauthorized() sends error 401 back to the client, which in the case of a regular web browser causes the user to see a prompt for username and password. checkCredentials() checks whether a username and password have been sent with the request and whether they are valid, i.e. they have certain values. In a Webduino command function you should first run checkCredentials() and depending on the return value either run your “protected” code, like turning on the lights, or fire httpUnauthorized(). See the methods’ subpages of the API documentation for example code.

« Older entries