Archive for the ‘Tech’ Category

Get the system time from the terminal

Monday, January 30th, 2012 | Life, Tech

Wondering what your system date/time is? Easy!

date

It’s that obvious ;). Don’t mistake it with the command “time”, which won’t return you what you want.

i386 or x86_64 architecture?

Tuesday, January 24th, 2012 | Life, Tech

Wondering if you’re running i386 or x84_64? No problem, there is quick command which will return this information to you.

uname -i

Social Media: For Good or Ill

Thursday, January 19th, 2012 | Events, Humanism, Tech, Thoughts

This month at the Humanist Society of West Yorkshire, Simon Duncan presented a talk on social media – what it is and whether it is a good thing or not. Of course, the answer is yes.

Social media brings us huge benefits, at relatively little cost – and indeed almost no monetary cost, as sites like Facebook are all free. Unfortunately, it tends to take a bad wrap because of people not really thinking their arguments through. You can blame the media a little for this, but I don’t think they shoulder that much responsibility.

Take cyber bullying for example. It’s ace. Kids are going to bully other kids anyway, that is just part of society, at least at the moment. But with cyber bullying – you have a full paper trail of everything that has gone on! If social media has made the bullying situation worse for anyone, it’s the bullies! You can now just take your text messages straight to the school, or even the police. None of this complicated business of having to prove what they said with witnesses.

According to Simon, studies have also shown that using social media actually increases real world interaction. That’s certainly true of me – the main reason I use Facebook is to organise real world events with my friends. As well as plenty of other uses of course, such as keeping in touch with friends I otherwise couldn’t keep in touch with affectively because they’re in a different timezone in a different part of the world.

Other fears include issues like privacy and targetted advertising. Perhaps this has been a problem in the past, but with increased awareness of the situation, companies are now putting in place the tools to effectively manage your privacy and you can quickly and instantly lock down your profile, most of which is restricted to approved friends only anyway. This is arguably far more secure than the records the government has for example, which will probably end up on a USB stick left on a public train.

Targeting advertising is actually a massive benefit to us – because more effective advertising means less advertising. If companies can reach their target audience more effectively, they need to reach less people, so they spend less on blanket advertising. This is evident from the reduction of advertising – remember all the big flashing banners and pop-ups that plagued the internet – most of those have now given way to these small text links on Google and Facebook, and the web is much the better for it.

PDO database layer

Wednesday, January 18th, 2012 | Tech

If you’re not using PDO in your PHP projects yet, you should be.

I finally got round to taking a proper look at it recently, and I’m really impressed. I managed to convert an entire open source project to it in under two hours! Granted, I was helped a lot by the fact that the PDO naming conventions luckily match up with the naming conventions I used in my original data access layer, but still, it was smoother than I expected.

PDO has some great advantages too:

1. It’s cross platform, so you can use it on a number of different database platforms including MySQL, MSSQL, Oracle, Postgres, SQLite and many others! All you do is enter the protocol and login details to the connection and it handles everything else.

2. It has prepared queries so you never need to escape anything again! You simple pass it some SQL with a series of question marks in, and an array of values those question marks represent and all the SQL injection negation is taken care for you.

3. If something goes wrong, it throws an exception rather than producing an error message.

4. It’s easy to extend, to add your own functionality. Just use Class MyPDO extends PDO and you can add extra functionality on top of it.

All in all, it’s a great addition to PHP and one I now wish I had gotten to sooner.

Profiling SQL queries with EXPLAIN

Wednesday, January 18th, 2012 | Life, Tech

If you have a complex SQL query, you might find that performance isn’t exactly ideal. Worse still, you don’t actually know which part of the query it is that is actually taking so long.

Luckily, MySQL comes to the rescue with the ability to explain.

All you have to do is start your query with the keyword EXPLAIN and MySQL will, rather than returning you a recordset of results, will instead provide a break down of everything it has done, including how it made the table joins and what order it did everything in.

EXPLAIN SELECT a INNER JOIN b ON a.col1 = b.col2 WHERE a.col1 > 1 AND b.col2 > 2;

Speeding up inserts with INSERT DELAYED

Thursday, January 12th, 2012 | Life, Tech

If your insert statements are not time critical, you can use insert delayed in your SQL to speed things up. The syntax is as follows.

INSERT DELAYED table (col1, col2) VALUES ('a', 'b');

Insert delayed can be used with MyISAM and Memory, but cannot be used with InnoDB.

The advantage of using insert delayed is that the MySQL server returns a success message straight away so the script can keep going, without it actually having to do the insert. This allows the MySQL server to carry it out when it isn’t busy, and do several at the same time.

It’s appropriate for tables such as logs tables where it doesn’t matter too much if they don’t go in straight away.

Updating views in MySQL

Thursday, January 5th, 2012 | Life, Tech

Yes, you can update views in MySQL! A lot of people seem to be under the impression that you are unable to, but this simply isn’t the case. There are a lot of restrictive rules, which can be found in the MySQL manual, but as a rule of thumb, you can update them, but only one table.

For example, lets say you have a view which links table A and table B.

You can run an update on this view, but only if you are only updating the columns from one table. So you could run a query that updates a number of columns from table A, or you could run a query which updates columns from table B – but you can’t run a query which updated columns in both table A and table B.

If you need to accomplish this, you need to use a join instead.

Shortcut key for Snapz Pro on Mac

Saturday, December 31st, 2011 | Life, Tech

Snapz really annoys me because I paid money for what is supposed to be the best product out there, but it’s actually incredibly hard to use because every time I want to take a screen shot I have to google for the shortcut key. By default, it’s this.

Cmd + Shift + 3

Proof that I invented Facebook

Thursday, December 29th, 2011 | Tech

I always knew that one day I would be able to prove it! While trawling through my old websites, I came across a website that is essentially FaceMash. Now, where do I write off to, to get my money?

List locally modified CVS files

Wednesday, December 28th, 2011 | Programming, Tech

Quick command for listing locally modified CVS files.

cvs -Q status | grep -i locally