There is competition going on in bbGameZone. I decided to participate with small Bulls and cows game:
Here is my submission “CowsNBulls”.
It’s a game I loved playing when I was younger.
Demo: http://posterfans.com/game/
Source code: http://posterfans.com/game/index.php.txt (2013 bytes)
The code can be further optimized, but let’s leave something for Phase 2 Smiley
Total planning + development + bug fixing time [...]
AquilaX’s development blog
Category Archives: PHP
Small Bulls and cows in PHP
Get parameters in Code Igniter
If you want to use GET parameters in Code igniter just for specific controller do use the following line in your Controller’s constructor:
parse_str($_SERVER[’QUERY_STRING’],$_GET);
Also make sure to call your script like this (even if you use mod_rewrite to get rid of index.php):
www.example.com/index.php/controller/method/?par1=1&par2=2
Media Wiki Bot
I needed a bot to quickly modify the pages of wiki.muonlinehelp.com. So I created Mutex which kind of helps do the job. It’s full of bugs with no error handling but works for me.
Usage:
<?
require ‘class.mediawiki.php’;
$mw = new mediawiki(’http://yourwikiurl/api.php’);
$mw->login(’bot_user’, ‘bot_password’);
$mw->editPage(’title’, ‘page_text’);
?>
You can get the source code from here. [...]
Akismet problems
I use Aksimet for comment filtering in two of my projects, scenata.com and diggbg.com. It’s very useful anti spam solution and worked like a charm .. until recently when it started to break the encoding on some of the comments. Fortunately the problem is easy to solve and the solution can be found here.
Perlin noise generator in PHP
Generating Perlin noise requires heavy calculation and PHP (in my opinion) is not the best language for this task but still it can be useful.
The algorithm is an adaptation form this pseudo code.
The class seems to work but I’m not if it works 100% correctly. The tricky part was to deal with the types because [...]
PHP Maze Generator class
I looked for PHP maze generation algorithms today and couldn’t find anything. Fortunately Wikipedia has an article on Maze generation algorithm with source code written in Java. The easiest part was to transfer the code to PHP (it looks like PHP supports the same bitwise operators’ syntax as Java), and the hardest to make it [...]
Callback function to class in PHP
A short sample on how to attach a callback function to PHP class:
<?php
function outside(&$p1, $p2){
$p1 = "This comes from the outside";
echo "Outside: $p2\n";
}
class test{
var $_events = array();
function attach($handler_name, $method_name) {
[...]
Oracle with PHP5 on Linux
Very nice and useful tutorial on how to run Oracle with PHP5 support on Linux (Debian) can be found on http://remorse.nl/weblog/debian_oracle_xe_and_php5/
Note Also be sure to set the NLS_LANG environment variable to the www-data user.
phpMyAdmin change session expire time
To change phpMyAdmin’s default session expire time (1800 s), change the ‘LoginCookieValidity’ setting to whatever value of seconds You like.
From the phpMyAdmin’s wiki’s Config page.
LoginCookieValidity
Define how long (in seconds) a login cookie is valid.
$cfg['LoginCookieValidity'] = 1800;
Maximum value is 2^31-1 , which is around 2.1 * 10^9. This is about 58 years.
If you are on a [...]
Point in triangle
A function in PHP to check if a point is in triangle.
function fAB($t, $x, $y) {
return ($y – $t[’y1′])*($t[’x2′] – $t[’x1′])
-($x – $t[’x1′])*($t[’y2′] – $t[’y1′]);
}
function fBC($t, $x, $y) {
return ($y-$t[’y2′])*($t[’x3′]-$t[’x2′])
[...]