Thursday 19 December 2013

Quick overview of humans.txt for SEO

humans.txt is a TXT file that contains information about the different people who have contributed to building the website. Click here to access an example from humans.txt. The file is picked up by search engines.
Add a humans.txt to your site and reference it using the tag
<link type="text/plain" rel="author" href="humans.txt" />

Wednesday 11 December 2013

Dynamic progress bar for Twitter Bootstrap using PHP

Twitter Bootstrap offers some very useful progress bars. See
They are based on percentages, so you need to get the length of the shaded bar as a percentage of the whole bar for them to be accurate.

Below is a small example of how to do this with PHP.

$currentVal = 10;
$maxVal = 20;
$percentageVal = ($currentVal/$maxVal)*100;
<div class="progress">
  <div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $currentVal ?>" aria-valuemin="0" aria-valuemax="<?php echo $maxVal ?>"  style="width:<?php echo $percentageVal ?>%;">
    <span class="sr-only"><?php echo $percentageVal ?> Complete</span>

Recursive delete for blogs and forums

Let's say, you've developed a blog or forum and you need to delete some entries. You will also want to delete the responses to those entries. In this example we'll use a table structure like this, where 'refid' is a field used to associate a response with it's referer :
In our PHP we want to go through each blog entry which we'd like to delete and ascertain it's responses identified by 'refid' before deleting it. Thus :
function deleterecursiveblog($id)
    $q = "SELECT * FROM `blog` WHERE `refid`='{$id}'";  
    $result = mysqli_query($con,$q);
      foreach($result as $key)
    $q = "DELETE FROM `blog` WHERE `id`='{$id}'";  
    $result = mysqli_query($con,$q);

Friday 6 December 2013

Bash techniques

I've been doing a lot of work in bash lately. I've been speeding up the time taken to create the website basics. Right now I can create a Twitter Bootstrap/Modernizr website with blogs etc within a couple of seconds by calling my bash script. So, below are some techniques I've learned along the way:
Prep-end all slashes in a web address with backslashes
webdir=`echo $webdir | sed s,/,\\\\\\\\\\/,g`
Get the last substring from a string separated by slashes
Put the contents of a .sql into a database
mysql -u root -p password $dbn < $workingdir"/users.sql"
Change a line within a .ini file
sed -i -e '/DB_NAME =/ s/= .*/= '$dbn'/' config.ini
Hope they help!