Fixing Windows File Permissions in Linux

David Nash bash 0 Comments

Find all files (not directories) and remove the eXecutable bit. I don’t know what the characters on the end do: find . -type f -exec chmod a-x {} \; Make all directories executable to user, read/writable to groups others (good for when the web server is in ‘others’): find . -type d -exec chmod 755 {} \; Make all files read/write/executable for user, readable for the group and others: find . -type f -exec chmod 644 {} \;

Unix Time in MySQL and bash

David Nash bash, mysql 0 Comments

A quick one today. I was working on a mysql database that used unix timestamp produced by PHP’s time() function. I needed to be able to quickly convert this time to a human-readable format. In bash, date -d @timestamp is a quick way to convert. In a terminal shell eg: # date -d @1224992980 Sun Oct 26 14:49:40 EST 2008 In a MySQL client, you could also use select date(from_unixtime(column_name)) from table_name; Or if you want a little more flexibility in the output, for example outputting 27/02/09, you could do: select date_format(from_unixtime(column_name), ‘%d/%m/%y’) from table_name; This post is one of …

Assorted Handy vim Commands, Part 1

David Nash vim, xhtml 1 Comment

To reverse the order of lines, eg 1-5 : 1,5 g/^/m0 For example, one two three four five becomes five four three two one To remove blank lines : %g/^$/d Delete all lines that don’t contain “string” : %v/string/d

Turn all links in an HTML file into ‘#’

David Nash vim, xhtml 0 Comments

Replace all in the current file instances of: <a href=”link_to_somewhere.html”>link</a> with: <a href=”#”>link</a> :%s/\(a href=”\)\(\S\+\)\(“\)/\1#\3/g This is great if you’ve got a big HTML file that you want to demo to a client where you don’t want the links to do anything when clicked. You could also use javascript to do the same thing – just “return false” for all <a> elements on the page.

vim: Quickly assign POST variables in PHP

David Nash vim 0 Comments

You’ve got a web form with lots of fields, and you want to POST them to a PHP script. Open vim, and list the INPUT tag’s NAME attributes, one per line. <?php firstname lastname address1 address2 state postcode ?> Now with some search-and-replace magic we can save ourself a lot of boring typing. Hit ‘escape’ to get out of insert mode, type a colon (“:”) and copy-paste this: %s/^\(\S\+\)/\$\1 = \$_POST\[\’\1\’\]; I won’t bother explaining it unless someone asks. But what you should end up with is this: <?php $firstname = $_POST[‘firstname’]; $lastname = $_POST[‘lastname’]; $address1 = $_POST[‘address1’]; $address2 = …

Create a MySQL database

David Nash mysql 0 Comments

I generally only need to do this once for each project, which means I don’t do it often enough to remember. Log in to the MySQL server as root, then: create database newdb; grant all on newdb.* to ‘newuser’@’localhost’ identified by ‘newuser’; set password for ‘newuser’@’localhost’ = password(‘newpass’); And you’re ready to go! Replace newdb, newuser and newpass with whatever you like.

Welcome

David Nash General 0 Comments

Welcome to my new site. I plan to post things here about the things that I’m doing, along with tips for other web developers. I’m not worried about sharing my knowledge – it’s all available on the internet anyway. Why not have it all in one place? It’ll be like my own personal notebook – one that everyone can take advantage of. I feel all warm and fuzzy.