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′])
[...]
AquilaX’s development blog
Category Archives: PHP
Point in triangle
Pythagorean triple in PHP
Pythagorean triple is every integer a, b and c for which a2 + b2 = c2 or in other words the a, b, and c are the sides of a right triangle. To generate triples in PHP, you can use the following function:
function CalcTriple($n){
$res = array();
[...]
Banner widget for Wordpress
I spent almost two hours, looking for Wordpress widget, which supports multiple instances and can embed banners into the sidebar. It looks like the solution is dead simple. Just use an instance of the default Text Widget and paste the HTML code for the banner inside.
Get band’s top songs from last.fm
Last.fm is great service. It provides a lot of information, which I find particularly useful for scenata.com. This is an example on how to get band’s top listened songs with the Audioscrobbler’s Webservices API using PHP’s XML Parser. The XML feed is formed as follows:
http://ws.audioscrobbler.com/1.0/artist/artistname/toptracks.xml
The function to use is
function GetFromLastFm($bandname)
and it returns an [...]
Prime numbers in PHP
This is quite fast (but unfortunately memory consuming) algorithm for generating all prime numbers up no n:
$n = 100; //this is the upper limit
for ($i = 2; $i <=$n; $i++){
$primes[] = $i;
}
foreach ($primes as $num){
if ($num != 1){
[...]
Live RSS Feed page in Wordpress
Iko has an idea of showing Live RSS feeds in Wordpress Pages. Here is my solution to accomplish this task.
Wordpress supports Page templates, on which this solution is based.
Locate page.php in your template’s direcotory.
Copy the file and rename it to something like rsspage.php, and then open it for editing
Add or modify header comment of [...]