I for my sins code in PHP,Perl,ColdFusion using database MySQL and also write JavaScript, XML and battle with CSS and Ajax etc. Often I’m working on these projects in parallel which gets kind of stressful. Anyway I let my standards slip recently and made the following mistakes and suffered for it.
- Not immediately taking my own backup of the files I was working so I could rollback at any time and as importantly prove whether my changes had or had not caused a regression or bug
- Leaving test files lying about, so I later got confused as to which was the actual version
- To my credit have been using git for version control
Coding Tips git, rollback
Vim 7.3 is a stability release integrating hundreds of patches. It does contain however some new enhancements.
The most notable additions since 7.2:
- Persistent undo and undo for reload
- Blowfish encryption, encryption of the swap file
- Conceal text
- Lua interface
- Python 3 interface
Persistent undo is probably the feature which most interests me. This allows you to undo changes you made last time you edited a file; a feature which must be used with some care obviously!. It works by saving the changes in a temporary file. A file is created for each file you modify, to avoid cluttering up your directories you can configure vim to use a special directory.
Download the latest VIM here vim.org/download.php
Windows Users can go directly to this link ftp://ftp.vim.org/pub/vim/pc/gvim73.exe which is the simplest way to upgrade. By the way REMEMBER to backup your .vimrc file!!!
Recently I’ve been using the Cream version http://sourceforge.net/projects/cream/files/Vim which maintains an up-to-date single click install version of VIM with all patches it is already at version 7.3.3. And just to confirm this is the version without Cream.
vim
From A Dos Window
net statistics workstation
Uncategorized
Tip 1:-
I always need several Cygwin Windows open so I was very frustrated by Windows 7 only allowing me to open one Cygwin from the Windows 7 Taskbar. This is because once you click on an icon it disappears from the Taskbar! This is different to the behavior of the previous XP or Vista Taskbar and often prompts users to select the Vista Taskbar compatibility. There is fortunately a work around depress the SHIFT button and then click the existing open icon on the taskbar and voila you will spawn a application window!
Tip 2:-
The Properties Tab is HIDDEN on the Windows 7 Taskbar and had me hating it until I found it. Rightmouse click the relevant Application Icon on the Taskbar then hover over the revealed tab and Right Mouse Click this and there magically is the Properties Tab!!
Cygwin, windows Tips windows 7 taskbar
There are two ways:-
$price=~tr/0-9.//cd; # delete anything but 0-9 and a real dot
$row_array[6]=~s/[^0-9.]//g; # clean up price, remove pound/dollar sign etc
Uncategorized perl, price, regex, regexp
preg_match_all(‘#<b>.+?</b>#i’, $html, $matches);
// ? means non-greedy and is absolutely critical
$match[1], $match[2] contain the results
Non greedy stops the match gobbling everything between the first bold tag and the very last. I’ve never quite understood why greedy is the default behavior of RegExp (Regular Expressions) but I guess there’s a good reason for it.
PHP also has the very useful strip_tags function.
Coding Tips, PHP regex
This for loop is OK
foreach($cargo_data as $cid=>$cargo_record)
{
$cargo_id=$cargo_data[$cid]['cargo_id'];
$section=$cargo_data[$cid]['section'];
…
}
But then later you add a condition cargo_id>6
foreach($cargo_data as $cid=>$cargo_record)
{
if ($cid>6) {$cargo_id=$cargo_data[$cid]['cargo_id'];}
$section=$cargo_data[$cid]['section'];
…
}
Now the bug is that if $cid is less than 6 $cargo_id is not set and will likely inherit the value it was set to in the last loop this type of error may not be immediately noticeable but can cause chaos. In this simple example it is easy to see that their should be an else clause, however the real solution is to systematically initialize all the variables at the beginning of the loop.
Coding Tips
This could easily be done with Perl but here is a zsh solution
I want to convert a textified string to a Title Case Phrase
>
> eg
> fred-goat-dog.jpg to Fred Goat Dog
>
% print ${${(Cs:-:):-fred-goat-dog.jpg}%.*}
Fred Goat Dog
This curiously uses a smiley face though
foo=fred-goat-dog.jpg
echo ${(C)foo:gs/-/ /:r} might be more elegant
From the zsh newsgroup (RD&MM)
and to textify a phrase
s=’Fred Goat Dog’
print ${(L)s:gs/ /-/}.jpg
or
print ${(L)s// /-}.jpg
zsh textified, title case, zsh
I’d put some new files into a folder before remembering to mothball all the old files:-
Here is a zsh solution:-
>mv *.*(^m-1) ./old
Uncategorized