Conor Mac Aoidh
http://macaoidh.name
conor@macaoidh.name
 

Search

Archives

  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008

Spam

3,960 spam comments
blocked by
Akismet

Tag Cloud

    bt broadband CMS conor's management system conormacaoidh conor mac aoidh content management system drums fast Fedora fedora 10 furasta furasta cms furasta org gnome guide hello world HTML icsp iPhone jar Java javascript joomla kde Linux Mandriva mc kennas Monaghan Music mysql php Scratch stealing the ceiling The Dominican Affair the pot smoking pirates the strats tutorial Twitter updates web design forum webme webworks weekly tweets Windows wordpress

Ads

PHP – Saving Database Queries

Posted May 18th, 2009 by Conor in in Languages, PHP

This is something I wrote today while building botb SNS – a project that I will have to start blogging about soon! It should be used on large scale projects that have multiple database queries. It will be very useful if you have so many queries that you can’t keep track of them and are afraid of re-querying incidentally. Enough said – down to the code:

<?php
class user{
var $id;
var $name='';
var $username='';
var $email='';

function __construct($id){
$this->id=$id;
}
function about($t){
if($this->$t!=”) return $this->$t;
$q=dbRow(’select ‘.$t.’ from users where id=”‘.$this->id.’”‘);
$this->$t=$q[$t];
return $this->$t;
}
}
?>

You will obviously have to adjust this to suit your database setup. It also requires the following function:

function dbRow($q){
$s=mysql_query($q);
$r=mysql_fetch_assoc($s);
return $r;
}

As you can probably see this example simply echos database information. The main benefit of the class is it will never make the same query twice. Once you ask for the username it is stored within the class so if you ask for it again in the same page it doesn’t have to query the database again. You could look at it as a type of internal page caching. Also it is incredibly easy to use. All you need to do is:

$u=new user($id);
echo 'Query Database: '.$u->about('name');
echo '<br/> From Memory: '.$u->about('name');

Easy as that!

3 responses so far

Furasta Reconstruction

Posted May 4th, 2009 by Conor in in CMS, Web Projects

After a long pause in development I have begun writing the first stable version of Furasta – 0.2. I haven’t really done anything with the project since I set up the website a few months ago. But since then I have been building up experience by examining other open source projects, such as Webme, Wordpress and Joomla. I learnt a lot from those projects and they have contributed a lot of ideas for Furasta!

I have abandoned all of the old code and opted to write the whole thing again from scratch. Considering how long it took me to write v0.1.5, about a month of flat out coding every night, I expect v0.2 to be completed in the same sort of timescale. One thing is for sure – there will be no micro-optimisation this time! After all the effort I put into that last time the damn program was still slow. This time I will invest my executable time in more important tasks, ones that only directly affect what’s going on as you load the page, and perform tasks such as server side caching through AJAX so the user doesn’t notice it.

The project is also going to be available from svn from now on. Since I am writing it from scratch there are only a few files in the svn at the moment and there’s also no installation script. But that will come in time!

http://code.google.com/p/furasta-cms/source/checkout

I am taking a completely different approach to writing the CMS this time. In fact I would go as far as calling it an engine rather than a CMS. Basically what I plan to do is build a solid framework that on it’s own does nothing, but has the ability to do everything. There will be no pages except the essential homepage. Everything, I mean everything that will give this program the characteristics of a CMS will be achieved by the plugin architecture. So for example to edit and display pages, I will create a plugin. Obviously the CMS will have to be shipped with a few default plugins, which it will be possible to disable through a plugin manager plugin! I might be going a bit overboard with this idea but in theory it seems like a good one!

So enough talking, time to start writing!

No responses yet

Twitter Weekly Updates for 2009-05-04

Posted May 4th, 2009 by Conor in in Twitter
  • Installing Google Chrome for Linux. Yes and I know that it’s not available yet :-) #
  • @BuzBuz Thanks for the vids in reply to BuzBuz #
  • I am going to buy conormacaoidh.com tomorrow so that I can start using the #webme Multi User #
  • Downloading a Widespread Panic album and a Firewind album. #
  • iKnights is the best and most addictive iPhone app out there! #
  • Java is very slow. #
  • I wonder is opera available for the iPhone? http://www.opera.com/mobile/ Now that would be cool #
  • @buzbuz thanks for the link on firewind – Just finished downloading 6 of their albums. Great Band #
  • @blacknight any coupon codes for .com? I’m going to buy one tonight! :-) in reply to blacknight #
  • @blacknight haha It’s ok, I just checked the price and their only €6! I thought they were something like €20 or €30!! :-) in reply to blacknight #
  • Just bought http://www.conormacaoidh.com and I will be setting it up tonight hopefully. Can’t wait to get my new MU working :-) #
  • My iKnights code is 199-248-630. I am going crazy for this thing so add me! :-) #
  • #webme MU is brilliant! I am writing a shopping cart so that people can buy websites and have them set up at the click of a button! :-) #
  • @BuzBuz great drummer! and he says at the end that it is too cold for him to play :L in reply to BuzBuz #
  • Great http://conormacaoidh.com is up and running. Need to add some more content 2moro. But the shop is working. Kind of :~| #
  • Sick of my bad graphics on Fedora. I am downloading OpenSuse. Then I will build a fedora sis video driver – in the long term :-) #
  • @BuzBuz Pat Mc Manus? Really? I have one of his CDs – he’s very good! Blues music! I think I saw him play aswell, Are you going to our gig? in reply to BuzBuz #
  • @BuzBuz Oh right… We had to find a replacement guitarist as Shane pulled out at the last minute – personal reasons! in reply to BuzBuz #

Powered by Twitter Tools.

No responses yet

The Kember Identity

Posted May 2nd, 2009 by Conor in in Fedora, Languages, PHP

This morning on twitter I came across something called The Kember Identity. Elliott Kember seems to have thought of something that simply hasn’t occured to the rest of the world. That thing has been aptly named “The Kember Identity”. It’s homepage is located here.

Anyway the Kember Identity is an md5 hash. Each md5 hash contains 32 characters so the KID is the theoretical hash that when it is encrypted it returns itself. At the moment this is a theory as it has not been proven. So Elliott has started a competition to see if anyone can figure out if the KID actually exists and if so what it is.

I have chosen to enter this competition with a PHP script that I wrote just a few minutes ago. It’s fairly simple and I have added a html table in there to clean it up a bit. Instead of computing endlessly this script displays all failed equations as it goes. When it finds the KID it will stop and show it in bright green. I ran the script for a few minutes and got to 200,000 hashes with no luck. Also FireFox froze a few times while running it. The best thing to do is just leave it to do it’s job and don’t do anything else while it is working!

You can view it here: http://files.macaoidh.name/php/the-kember-identity/md5.php


<?php

function encript($str){ return md5($str); }

function generateSum(){ return md5(mt_rand()); }

function loKIDe(){
  $s=generateSum();
  $md5=encript($s);

  echo '<tr><td>'.$s.'</td><td>'.$md5.'</td>';

  if($s!=$md5) return false;
  else{
    echo '<tr style="color:green"><td>'.$s.'</td><td>'.$md5.'</td></tr>';
    return true;
  }
}

echo '
<h1>Finding the Kember Identity...</h1>
<table>
  <tr>
    <th>32 Digit Number</th>
    <th>Md5 Of Num</th>
    <th>Count</th>
  </tr>
';

$num='';

while(loKIDe()==false){
  $num++;
  echo '<td>'.$num.'</td></tr>';
}

echo '</table><br/><br/>  If you are seeing this then the line above is equal';

?>

This script should, in theory, find the KID. But it is really a matter of time. I am going to keep it running all night tonight and see if I have any luck. Kae is thinking of writing a JavaScript version that will spread the load between multiple computers thus reducing calculation time. So the race is on! I hope that I am the first to find this magical, mysterious number!

7 responses so far



Conor's Blog is powered by Wordpress | Template design by Conor Mac Aoidh