zsh wonderful use of dirs,popd,pushp, cd ~5

February 20th, 2010

I’ve never got the hang of popd & pushd they seemed a bit pointless. zsh however has extended their abilities eg:-

> dirs -v    # number and list your recent directories one per line

> cd ~5     # cd to directory 5 in the directory stack

> cd -<tab>    # the tab complete lists the directory stack then type a digit to select the one you require (saves you having to do a dirs -v in the first place

I have to work in very complicated directory structures so this will be fantastically useful.

#don’t forget the zsh cd substitute command

> cd olddir newdir

eg you are in

/inetpub/wwwroot/www.livesite.co.uk/products/

> cd live test

/inetpub/wwwroot/www.testsite.co.uk/products/

shell tips

Using Git for Document/Software Version Control

January 27th, 2010

I had been using my own ad-hoc system for years but recently started using CVS to maintain a history of my file and document changes. I was quite happy with CVS but everyone told me I should be using Git instead.  Git seems to be simpler and more intuitive. I can set up git for a folder or project very quickly. You just need the following 5 commands to get going

git init       (set up git for the current directory)
git add *.php   (add all your php files or whatever)
git commit -m “first version”    (also need to commit all your existing php files)
vi index.php (make a few changes)
git commit -a -m “Added new date feature”   (do this periodically to maintain version control)

gitk is a simple TK Gui which allows you to review you versions etc. I am delighted to have version control, all I have to do is remember to do a > git commit -a -m “Added new date feature” every now and again (eg daily)

Coding Tips , , ,

Viewing Remembered Password in Firefox

January 18th, 2010

You know the frustration of being able to log into a website because your browser has
remembered the password but you have forgotten it and so cannot login from another pc.
Well FireFox will show them to you

options->security->Saved Passwords then click Show Passwords

You may want to consider the security implications as well, to disable this feature while
retaining the ability of the browser to remember passwords

go to

options->security-set master password

I personally never let a browser remember say my PayPal password

Uncategorized , ,

copy a file while modifying a value inside it

January 14th, 2010

The sed does the filtering, you should be able to see how to adapt this to your own requirements

So I want to duplicate init.php while changing the value of a flag inside it for each copy

cat init.php | sed s/flag=2/flag=3/ > dir3/init.php
cat init.php | sed s/flag=2/flag=4/ > dir4/init.php

If you see the first comment Bawdo suggests rightly that this is a UUOC

sed “s/flag=2/flag=4/”  init.php > dir4/init.php

I’ve always underused sed unfortunately

which then can written (zsh)

for i in {3,4}; sed s/flag=2/flag=$i/ init.php > dir$i/init.php

sed stands for stream editor and therefore cannot do an in place edit this is where perl thrives

perl -p -i -e ‘s/\surname\b/form_surname/g’    *.php

or safer

perl -p -i.bak -e ‘s/\b23\b/34/g’  fred.php  (creates a backup of each file eg fred.bak)

Uncategorized

Forgetting How You Solved a Problem the First Time

January 13th, 2010

Today I had to update a 12 year old Higgledy-piggledy Microsoft Access Database application to work with the year 2010 instead of 2009 amongst other things . The original designer had needlessly hard-coded the current year’s and previous year’s date anyway I had some notes from when I did it 12 months ago which described what values need changing, but could I find where those values were defined? My notes were not specific enough. The REAL PROBLEM was that last year I must have altered these values without too much of a sweat and so not taken much trouble to note down exactly.

Fortunately I remembered the wonderful stackoverflow.com website. I posed my question and got several useful pointers in a few minutes and these helped me find the solution which was to set the option search whole project.

This is actually a generic problem in life when we realize that we’ve been doing something automatically and been unconscious of how we did it.

Uncategorized

Using Ubuntu to Delete Windows 7 Trojans

December 26th, 2009

My broadband service provider informed me that my network IP address was issuing massive amounts of spam email. To my horror I realised it was my own PC. I’d recently done a lot of work double checking my PC with both Sophus and AVG so I thought I was clean. The Service provider recommended that I use Avast and that I do a DOS Level Search from Boot. The advantage of doing this is that viruses and Trojans have a lot less chance of hiding themselves somewhere in Windows. Well Avast spotted quite a few problems including an iframe Trojan in a back-up of a website but nothing that solved my problem. Well I ran avast several times and then it asked to do another Boot search and then alerted me to a trojan in a driver file micbd.sys c:\windows\System32\drivers\micbd.sys unfortunately the Trojan would not let me delete it from DOS or from Windows whatever, so I used my old trick I booted from a Ubuntu CD this gave me access to the Windows File System and I deleted the offending micbd.sys driver. Now have fought off a couple of Trojans recently I can give you a clue in both cases the first thing I noticed was that the virus checker listed the eventual file as UNOPENABLE

So two tips you may find useful:-

  • Use a Ubuntu DVD to rescue, backup, or repair a damaged Windows System (do not install Ubuntu boot from the CD)
  • When looking for a Trojan or Virus on your Windows PC be very suspicious that your virus checker marks as inaccessible

trojans

PHP : Read XML File with simplexml_load_file Test Script

December 16th, 2009


<?php
/* create test.xml from following lines
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Fred</to>
<from>Joe</from>
<heading>Reminder</heading>
<body>Meeting Tomorrow</body>
</note>
*/
error_reporting(E_ALL);
if (!function_exists('simplexml_load_file')) exit('<br>function does not exist');
if (file_exists('test.xml'))
{
$xml = @simplexml_load_file('test.xml');
echo "<pre>";var_dump($xml);
}
else { exit('<br>Error could not locate XML file'); }
?>

Uncategorized

LED Lighting Taking Over the World

December 13th, 2009

LEDs are taking over in the following sectors:-

  • LED Flat Screen Televisions are actually LCD TVs which use LEDs for backlighting.
  • LED Flashlights or Torches now totally dominate this sector
  • LEDs for general lighting
  • LEDs for Street Lighting
  • LEDs for Traffic Lights

LEDs are taking over because they are incredibly reliable with a life usually easily longer than the expected life of the equipment. They also are more efficient causing less heat dissipation problems. They are very popular for helping to reduce global warming and other Green issues.

Learn more about LED Flashlights here.

Uncategorized

Hereis Document for PHP: Great for Generation of HTML

November 19th, 2009

The great thing about hereis documents is that in most cases you don't have to backslash quotes, your "html" thus retains its visibility
echo <<<__HTML__

<li><a href=”$pressdir$file”>$file</a>
__HTML__;

$html.= <<<__HTML__
<li><a href=”$pressdir$file”>$file</a>
__HTML__;

return <<<__HTML__
<li><a href=”$pressdir$file”>$file</a>
__HTML__;

it can also cope with arrays if you use the following syntax ${my_array['postcode']}

return <<<__HTML__
<li><a href=”$multimap_url${my_array['postcode']}”>${my_array['postcode']}</a>
__HTML__;

I see so much ugly tangled php/javascript/html/css code which could be tidied up with the PHP Hereis Document

PHP

Ubuntu 9.10 Karmic Koala them Immediately Update

November 14th, 2009

My daughter upgraded her PC from 9.04 to 9.10 independently. Only hiccup it lost the Windows Network Printer however I Googled a bit and found to you needed to upgrade Samba if your Printer was on a Windows 7 PC (our case), so I went to System->Administration->Update Manager. There was a whole bunch of packages in there I selected all of them and did the update. I was then able to Find and Add the Network Printer via the Samba option.

Ubuntu seems to be bathed in clarity and elegance in comparison with Windows even the much vaunted Windows 7. I think this is because Microsoft is a large corporation, I have worked for many years for such organizations where the engineers would find their choices and suggestions overridden by non-technical managers.

ubuntu

cialis for sale cialis order order cialis cialis price cialis uk cialis sale sale cialis cialis tabs cialis soft generic cialis cialis generic indian cialis levitra vs cialis soft cialis soft tab cialis online cialis professional cialis purchase cialis cheap cialis on line cialis in canada buy cialis on line buy cialis professional cheap cialis cheapest cialis cialis brand