I’m accustomed to having a hot-key in my text editor for inserting a time-stamp. Now I have a plain-text note-taking application that I want to use for managing my time, but it has no bells or whistles. It doesn’t allow the creation of macros and it doesn’t have a time-stamp function.
All is not lost! Using Automator, I created a service which calls a shell script to generate a nicely formatted time-stamp. I haven’t found a way to assign the service to a hot-key, but in many text input areas, a contextual services menu can be brought up with a simple right-click of the mouse.
Simple, nice, and convenient.
Here’s how to do it:
Fire up the Automator application. Create a new “Service” workflow: (click to enlarge)
For the operation, double-click on “Run Shell Script” and set it up as shown in the image below: (click to enlarge)
You’re done! Now you can insert 2011-08-04 16:58:06 time-stamps 2011-08-04 16:58:13 everywhere 2011-08-04 16:58:20.
Note: this is under Snow Leopard / Mac OS X 10.6.8. It probably will work under anything from Leopard onward.
Back a few years ago, I posted a quick’n'dirty tool for generating plausible user data. I had a need for some improvements, so I’m posting the new version here.
The new version supports back-references, composite fields, and SQL output. So, for example, you could do:
and get the following output: -- generated data from ./user-data-maker.pl
INSERT INTO tbl_dealer (id,lname,fname,city,state_code,zip,company) VALUES (0,'Nelson','Leslee','Akron','OH',44311,'Nelson Boats of Akron');
INSERT INTO tbl_dealer (id,lname,fname,city,state_code,zip,company) VALUES (1,'Bowen','Beatriz','Miami','FL',33176,'Bowen Trucks of Miami');
INSERT INTO tbl_dealer (id,lname,fname,city,state_code,zip,company) VALUES (2,'Hammond','Raymond','Ninilchik','AK',99639,'Hammond Motorcycles of Ninilchik');
INSERT INTO tbl_dealer (id,lname,fname,city,state_code,zip,company) VALUES (3,'Kim','Arielle','Columbus','MI',48063,'Kim Ships of Columbus');
INSERT INTO tbl_dealer (id,lname,fname,city,state_code,zip,company) VALUES (4,'Estrada','Warner','Iuka','IL',62849,'Estrada Cars of Iuka');
Nothing earth-shattering, but useful to me. Maybe to you too!
I regularly end up in the situation where I have to fix a crap PHP application.
The latest one has lots and lots of PHP 3.x-era code, that references hashes without quoting the index, e.g.,
$foo = $bar[baz]
Now, the PHP interpreter understands this in actuality. It figures out that since the constant is not defined, the programmer probably meant that the index should be ‘baz’. It does, however, throw a well-deserved warning.
The code I’m trying to fix throws lots and lots of warnings. Rather than wade through all the warnings to find which ones are important, I started with the following:
The thousands of lines of output convinced me bigger guns were needed.
So we got ugly.
find . -name \*.php -exec perl -p -i.bak -e 's/\[([^\$\d\'\''\"]+)\]/\[\'\''$1\'\''\]/g' {} \;
Note that that’s one line, and that WordPress seems to want to change some single quotes into back-ticks. Don’t be fooled!
All those extra backslashes and single quotes are to allow passing single-quotes within the regex, and not have bash consider them problematic.
Also note that this could be catastrophic if you have regular expressions in the code you’re operating on — do a diff with the backup version, and merge back the regexes.
I’m sure there are far more elegant solutions… primary among them, not using crap PHP apps in the first place!
So it’s a familiar problem, where you’re developing a data-driven application, and you want to optimize the queries that will run against your database (I’ll have more interesting stuff on this later). The problem, of course, is that to really optimize those queries, you need a lot of sample data.
So I needed to do some address lookup code against a huge collection of users. But because there was the possibility of having to demo the prototype, I really didn’t want 100,000 users named “Foo McBar” living at “10101 Binary Place.” So, with the help of the almighty Internet, the all-frobnicating Perl, and the all-knowing US Bureau of the Census, I created a quick, semi-flexible script to generate people with plausible names and addresses that, if not Google-mappable, at least had agreement on city/state/zip. The city/state/zip is a collection of 250 random zip codes. If you have good zip code data, you can easily extend this to be complete! Names are generated from the most popular forenames and surnames, with a probabilistic bias towards the most common ones. The script also allows you to specify “pick one of n item” type fields, pick a number from a range, plausible email addresses, not-very-plausible phone numbers with or without extensions, and the ability to export as CSV or tab-delimited.
In principle, this should be easy to adapt to other countries, although you’ll need lists of common first names, surnames, street names, and a way of mapping cities to regions, states, districts, cantons, or whatever’s appropriate.
You can grab a copy of it here. It requires a Perl interpreter with the Text::CSV and Getopt::Long CPAN modules.
Usage: user-data-maker.pl [OPTIONS]
-t, --header : header, a colon-delimited list of column headers
-f, --format : format string, a colon-delimited list of column contents
data types:
fn - first name
ln - last name
a1 - street address
a2 - apartment number
c - city*
s - state*
z - zip 5*
e - email address
pne - phone (US), no extension
pwe - phone (US), with extension
[a,b,c] - one of a, b, or c
{a,b,c} - one of a, b, or c in decreasing probability
[x-y] - a number between x and y, inclusive
* city, state, and zip will be agree to create a valid address
if you need multiple addresses, use the code ! to reset the
synch. The reset works on a left-to-right scan of the format string.
-n, --number : number of records to create
Flags:
-c, --csv : output CSV format (otherwise, tab-delimited).
-v, --(no)verbose : verbose mode (default false)