Mathematics skill testing quiz

April 25, 2010 – 18:46

In case you need to practice your basic maths skills, you can use my freshly developed online maths skills quiz.

I have developed it in PHP and it uses Ajax scripting to retrieve new questions. All questions are random, and no results are stored on the server side.

In case you are interested in the source code. Let me know, I will be happy to share it with you.

Good luck !

Fractions in PHP and whole numbers

April 20, 2010 – 18:52

I have been searching for a good PHP class for fraction handling and found Math_Fraction in the PEAR database.
However, it was still lacking a possibility to display the whole numbers of a fraction and I had to rewrite the last function in the Fraction.php file.
Here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function toString($whole=false)
{
    $n = $this->getNum();
    $d = $this->getDen();
    if (($whole == false) || ($n<$d)) {
        return "$n/$d";
    }
    else {
        if ($n==$d || $d==1) {
            return floatval($n / $d);
        }
        else {
            $w = floor($n/$d);
            $n = ($n-($d*$w));
            return "$w $n/$d";
        }
    }
 
}

I have also informed the maintainer about it, so he might update it some time.
Meanwhile I invite you to use this simple, yet effective solution.

Wysyłanie SMS przez bramkę mBox orange.pl – wykorzystanie php+curl

September 18, 2009 – 03:45

Trochę uporządkowałem skrypty i postanowiłem udostępnić skrypt do wysyłania sms’ów przez bramkę mBox orange.pl.

Jestem ciekawy ewentualnych ulepszeń, więc jak coś to proszę podsyłać nowe wersje ;)

UPDATE:
Skrypt został wzbogacony o możliwość wysyłania dowolnie długich wiadomości. Dzieli wpisaną wiadomość na 640 znaków i wysyła funkcją jako osobne smsy.
Ponadto, końcowy stan smsów jest pobierany przez Xpath.

Plik PHPS

Spamassassin + vpopmail + sa-learn + learning from IMAP folders

May 17, 2009 – 00:37

Below is a quick solution to making spamassassin learn from specific IMAP folders. Script represents a daily cron script and I just used sudo vpopmail (has to be the same as your spamd user) to simplify things. You probably should use user specific crontab…

1
2
3
4
5
#!/bin/bash
for F in `find /home/vpopmail/domains -type d -name '.Junk' -print`;
do sudo -H -u vpopmail /usr/bin/sa-learn --spam $F/cur/* &> /dev/null;
rm -f $F/cur/*;
done;

php strpos array

March 26, 2009 – 07:57

I needed a PHP function to check whether a string contained one of the array values. As we know strpos does’t accept input as an array so I had to tweak it  bit. Below is an example of what I did:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function strpos_array($string, $values) {
    $hits = 0; //will give number of values found in a string
    foreach ($values as $try) {
        $pos = strpos($string, $try);
        if ($pos !== false){
            $hits++; // you can do array_push here to get the values
        }
    }
    if ($hits==0) { //if none value from array was found returns false
        return false;
    }
    else { //I just needed a simple true/false boolean
       return true;
    }
}

FPDF polskie wolne czcionki

January 19, 2009 – 13:13

Postanowiłem wreszcie trochę uporządkować czcionki używane do generowania dokumentów pdf oraz obrazków wykorzystujących czcionki ttf. Załączam zestaw gotowej do zainstalowania czytelnej czcionki z pakietu liberation-fonts. Które są upowszechnione na licencji GPL.

Pobierz

Odmiana imion php mysql

January 12, 2009 – 05:26

Postanowiłem udostępnić uzupełniony zbiór odmian polskich imion dla bazy MySQL.

Plik jest gotowy do importu do bazy MySQL, zawiera imiona,  odmianę, płeć oraz ilość sylab występujących w imieniu. Można go wykorzystać na przykład w skryptach php wysyłających życzenia urodzinowe lub pozdrowienia.

W przypadku braku odmiany, proszę wpisać w komentarzach to uzupełnię.

Suhosin and maximum $_POST variables limit

April 23, 2008 – 23:30

I had a problem of more than 200 $_POST variables in one of my php scripts. Something was limiting the script not to process more than 200 in the $_POST array.

After unsuccessfully trying to find some info about how to change it in php.ini or apache.conf I found a solution using Suhosin:

You simply add the following to your php.ini file after loading the suhosin module:

[suhosin]
suhosin.post.max_vars = 2000
suhosin.request.max_vars = 2000

That’s easy now :)

Update: remember to restart Apache after making these changes.

Suhosin – customize php security

April 9, 2008 – 21:46

I was trying to configure my virtualhosts to have different php options regarding shell access. After some research I came up with Suhosin solution, which solved problems with setting disable_functions per virtualhost. Look it up!

March 10, 2008 – 12:36

Formulate and stamp indelibly on your mind a mental picture of yourself as succeeding. Hold this picture tenaciously. Never permit it to fade. Your mind will seek to develop the picture.”

Norman Vincent Peale, Author