Fixing WAMP 2.0 i and not so friendly extensions

WAMP2 is like a defacto standard for developing and testing PHP in a Windows enviroment. Particulary i used to use Wamp 2.0A in a WinXP SP2 platform. Also i use Postgres instead of Mysql, just because Pg owns Mysql big time. But there was a problem...

Also it didnt work in other WAMP versions

Like a year ago i wanted to use the next version of Wamp2... the B version. But I couldn't. Well i could install the Wamp server but there was an error when i wanted to activate the php_pgsql extension, an error like...

PHP Unable to Load the muthaphucking Dynamic Library 'c:\blah\blah\ext\php_pgsql.dll' - The specified module could not be found.


Yup, something like that. So after a lot of search and falses promises in google, i found the solution not only for that postgres extension, but for all other extensions that doesnt want to be loaded dinamically.

The Solution: Make sure that you are using the right php.ini file when you....

Ah Ha..Just kidding, the fast and furious solution is to search for this file libpq.dll in your wamp directory and then copy it to WINDOWS/system32 if youre using win XP(sorry for those using Vista, btw Vista sucks).
Hate & Love this file

And its done, you can now use Postgres with WAMP2 version I (yes version I, not 2.. long story).

I dont know exactly why its works, but it works and that the only thing i want to know. And for fixing others extensions, well u got to look for the access library of that extension and put it on system32, and replace it, if it is the case. Hope it helps someone. =)

I found it looking here., but they fix mysql, so this is my sand grain for the Postgres Project.

PostgreSQL.org Website Design Contest

Yup my favorite database is making a contest to redesign his Website. Of course im givin' it a try so you will see me with one of my design there. This is the first time I go to a contest like this but i will make my best there.

Of course there's a 2000$ prize that make me like much more Postgres, but the initial love is there. The price is divided between 1000$ for the winner Design and 1000$ for makin that Design go online.

My strategy is to create the CSS without hacks, and then use some jquery to make it web 2.0

So if youre a Web Designer you can go ahead and make your best.

Getting seconds from a timestamp PG and My

UPDATE 17nov2010: I Change the URL of my uberfancyfull game, give it a try.. although its in Alpha Stage.

In my game i need to do a lot of date and time calculations which i prefer to do on the database instead of doing it on PHP. But unfortunately (or fortunately?) i had to change my DB from a Postgres DB to a Mysql DB a while ago.. but i finally bought a hosting with Posgtres 8.3.X. So i had been practicing in getting the same data stuff from the two databases.

And here comes the interesting stuff. Do you ever needed to get the difference between 2 timestamps and get it on seconds? Well let me show you the way:

MYSQL Way:
SELECT TIME_TO_SEC(TIMEDIFF(example_time,now())) AS clock FROM movements

Ok let go step by step(uh baby!!):
1) TIMEDIFF(example_time,now()) This will get the difference between example_time and now(). As you know now() get the actual time in the server. So lets say example_time is '2009/10/10 23:10:10' and now() give us '2009/10/10 23:05:05' the result will be '00:05:05'
, Thats ok but we need it in seconds so.
2) TIME_TO_SEC(time) This function get a time value and return that number in secods.. so in our example it will give us 5*60 +5 = 395 seconds.

POSTGRES Way:

SELECT EXTRACT(EPOCH FROM example_time - now())::integer AS clock FROM movements;

Thast totally different from Msql .. let me give you a brief explanation fo the sintax:

1) EXTRACT(EPOCH FROM example_time - now()) The EXTRACT function is a tricky one, it will extract some part of the timestamp invlolved here , in this case the rest of example_time minus now(). Putting EPOCH first make the EXTRACT function transforms the answer of example_time - now() into seconds . Be carefull with putting SECOND instead of EPOCH.. that will extract only the secods of the answer (from 1 to 59), so in our example with EPOCH we will get 395.45.. and with SECONDS we will get 5.45..

2) EXTRACT(...)::integer This will transform our answer into integers so intead of 395.45.. we will get 395.And just btw.. this will not round our answer, it will get just the integer part of the result.


A POSTGRES Frebbie anyone?:
This is a Postgres Function I created to simulate the TIME_TO_SEC() funtion in mysql. USe it free of charge ;):

CREATE OR REPLACE FUNCTION "public"."time_to_sec" (first timestamp, second timestamptz) RETURNS integer AS
$body$
DECLARE
segundos integer;
BEGIN
segundos = EXTRACT(EPOCH FROM first - second)::integer;
return segundos;
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

Thougth of a Numeric ID in Jquery

I have devoted some of my time to create a Web Browser Game. This game has a Map (It is just a table with a lot of CSS to make it look like an Real Battle Map)... Well i started to work on it an created each tag with a numeric ID.. heres some code example:














But when I tried to select a ROW from the table by its ID like $('tr#0'), it doesnt work. So debuggin and debuggin I figured out that using a numeric Id in any TAG make jquery crazy. There are two solutions for fixing this behaviour:

A) Use eq to get the element of your desire: Something like $('tr').eq(1) will make the trick

B) Dont use a numeric ID at all: I think this is the best solution, so instead use something like:







Hope it help somebody with the same problem

Double Border Stuff - Playing with CSS

Yesterday i was in a hurry to create some fast CSS, so a copy&paste frenzy just came in, and i discovered a maybe usefull way for putting double border. Lets look at it more carefully:

Imagine you have a div:


Hi Im unique



Now lets put some css to make it pretty


div#Unique{
background:#0033CC;
border:10px outset #ccc;
color:white;
}


Ok, maybe not sooo pretty,anyway we will have something like this:

Hi Im unique



What if we put some more border options in here, something like:


div#Unique{
background:#0033CC;
border:10px outset #ccc
border-top:15px double outset #ccc;
border-bottom:15px double #ccc;
color:white;
}


Walla!!!. Our DIV get a makeover and finish like this:

Hi Im hell more unique :P


Notice that here this:


div#Unique{
border:red;
}

is equal to say:


div#Unique{
border-left:red;
border-right:red;
border-top:red;
border-bottom:red;
}


So is nothing new but you can create a beatifull effect using only pure CSS.

Better yet i was testing it and its seems like it work on Firefox 3, Opera 9.5 and believe it or not in IE 6.0!!!. That just some kick-ass CSS!!!. Well not really but it may be helfull. See ya next deculture ^^

How to create a Tag Cloud in Blogger

In my quest for a decent tag cloud system for my other blog, i have found this

The Tag Cloud for Blogger create in this page/blog: phydeaux3

I have just tested it in my other blog and it just works!!!. I higli recommend it.

1 Crazy Way to use json - json precharge

So youre a web developer doing some boring stuff with forms, lets put us in this scenario: You have a Typical Web Form generated with PHP. Also in the form you have some mighty select boxes called State and City, so every time you change the State, the City select box change. So What?, you will say,that stuff is ajax for sure. But what happens with the inital load of info, i mean how do you fill the select boxes the first time you access the page?

The Form in all his splendor


Well there where three options... until now ;)

A) Old School Server Madness: Yeah the standard to choose... in 2001. In this scenario the form is created with PHP, and when the selectbox of State change, you send a new almost identical page via GET or POST method with a fresh refill of Cities according to the state you send. This was the old way and i still see that methood going around in some pages. So why not use that?

Well fisrt is slow as hell and well.. AJAX anyone?, but the biggest reason why you should'nt work like that is because the server dont know if what you try to do when you send the POST/GET is getting new cities or sending the complete form filled, so you play with unnecesary hidden variables or check that all the fields are not empty,well just more work for such a simple thing

B)Server Precharge the Data,and Ajax afterward: This scenario is now the standard way to solve this problem, but not the brigthess. Here you fill the first round of cities with PHP and when the select box change, you do it via AJAX, so you send the petition, the server create the city DOM (i mean the options tags with duh.. the options), and then Mr Javascript take charge and put the DOM into the selectbox. So what's wrong with this way? Well nothing is wrong but it can be better.Think again little grasshoper, why build the DOM from the server when you can build it on the client.Imagine if you free the server for all the charge of creating DOM, say goodbye to loops and whiles and if statements. If you know what MVC means this can a way to make things better. So why not send the data in a naked stance to the client and let them write his DOM. Well, let me introduce C guy.

C)Ajax Semigod takes the (pre)charge: This is like the next step, like going from an ATARI 2600, to a BlueGene that kick Gasparov Ass. In this scenario (lots of scenarios in my blog) you send the form empty, and you use javascript to create the DOM based on naked data send from the server using eiher XML that is slow, or using json, that is fast. So json it is. Now when the page finish to load the first time, all the select boxes are empty,so you use ajax to fill them. Well here you get a bonus over the other methods, you put some of the work of the server into the clients (da browsers). So the Server just have to send Data in json, in PHP you do something like this:


< ?php echo json_encode($array_of_cities) ?>

and that's it, you get a jsonized var that you can send to the client.He will do the rest. But wait, isnt this alot of unnecesary calls to the server? I mean that can be done faster if the server draw the first selects boxes and when we need a fresh supplies of cities we ajax it until fullfitness?. Yes but you are creating a new deja vu here, the client and the server are doing the same thing. So was wondering a few days ago a better way todo it, so here it is the:

D)Json Precharge Overdose: Well i guess there are alots of smartguys that have discover this method but , i never see any reference to this so here it is. Its a fusion from B and C.
The first load of the form, you send the page selectboxes unfilled but you also print the PHP cities data (naked data), and make it a global variable in javascript. How ydo you do that?

Well in PHP you do something like this:

< ?php echo "var naked_data= eval('$array_of_cities') "?>
And then when the page load, you create with javascript the options DOM for the city select box using the global variable printed with PHP. The next time you call for fresh data, you just ask for the same fucntion that get you the json and recreate the selectbox DOM again using javascript. If you think in a MVC way, you are just effectively separating the view from the controller. So now you free the server forever of building the page DOM and you dont get unnecesary AJAX call to the server. But this method does have some problems:

  1. The fact that youre using globals variablesin javascript can make your life a living hell in large projects. But not so if you use a javascript framework like jquery, or use object in javascript, so if you have some order in your code, this can help alot.
  2. Using PHP to print javascript code, thats not good, but remember that youre not creating all the javascript in the page. You re just sending data from the server to the client. so the client can work with it.
So next post in my blog wil be putting this topractice usign jquery and php, stay tune