Jump to content


Check out our Community Blogs

amrosama

Member Since 15 Aug 2007
Offline Last Active Sep 22 2015 05:37 AM
-----

#680438 Books, online tutorials or both?

Posted by amrosama on 14 September 2015 - 12:46 AM

I think it totally depends on how you like to learn, if you are not having fun or being amused while you learn you wont learn anything.

 

I myself like to read a book with good looking cover for several chapters then jump into implementation and go through code (lots of knowledge in reading others code even if not well written) then I jump back to book to revise.

 

Sometimes, I read the full index of the the book for later.


  • 1


#628940 'ajaxrequest' Is Null Or Not An Object

Posted by amrosama on 03 May 2012 - 01:49 AM

its in line
var ajaxRequest; // = remoteRequestObject();
it needs to be
var ajaxRequest = remoteRequestObject();
:)
  • 1


#610124 Permissions vs User Creating the database

Posted by amrosama on 27 September 2011 - 12:40 PM

I would do the following:
when the user runs the install file, I check if I have permissions to create the database by creating a dummy database and deleting it, if it worked then I would give him 2 options; automatically let the script create the database or manually specifying database name that is already created.
of course if the script is not allowed to create the database I would ask the user to do it.

Not to mention that you must ask the user for username and password for the database access...
  • 1


#581933 Girls

Posted by amrosama on 27 November 2010 - 01:35 PM

women are awesome I would do anything for my future female wife
  • 1


#552239 Multiple event calendars on the same page?

Posted by amrosama on 18 April 2010 - 03:45 PM

welcome back to the thread :amr:
you can follow an easier approach here.
you have done great so far. i think you just need to fire the events.
the best approach to do so is to do it directlly in the function that prints the actual calendar. for example when printing a certain date you check if its special or not if yes add "onclick" or "onmouseover" event with the "getImportantDate (day)" you wrote.
for example :
for (i = monthStart; i < 7; i++) {
        document.write ("<TD onmouseover='getImportantDate ("+i+")'>" + dayCount + "</TD>");
        dayCount++;
    }
that would work but becareful:
-this will loop through "importantDates" array when mouse moves over any "TD" even if its date is not special. so i would recommend that you add that event only if that date is special by making a function "is_special(day,month)" (or something like that)
-in your "getImportantDate" you forgot to check for the month too :)

let us know if that worked well for you
  • -1


#526903 need help with php script

Posted by amrosama on 21 November 2009 - 02:06 PM

no thats the correct username
hmm, did you set the user privileges correctly
  • -1


#518099 How often do you visit Codecall?

Posted by amrosama on 23 October 2009 - 12:07 PM

CC is no1 on my speed dial
i check newposts every 5 minutes when im using a pc with internet
sometimes i keep clicking "New Posts" link till it says you have to wait 4 seconds between each search
but im only interested in javascript/HTML/PHP/General/Member projects category threads

Attached Thumbnails

  • asd.JPG

  • 1


#516440 Ajax with Mootools: making a product rating(JS only)

Posted by amrosama on 16 October 2009 - 07:22 AM

Ajax with Mootools
hi codecallers,
this tutorial will be about using the Mootools JS library with ajax, if you dont know a thing about ajax you will do just fine with mootools. but you need to have know some javascript to keep up.


when to use Mootools library with ajax?

-when you already have the mootools core library loaded in the page for other uses
-when you are tired of cross-browser errors and dont care about the size
-when you use it for more than once in a single page, for example you dont load 120kb of JS file just to move a picture around. make the best out of mootools when its already loaded with the page
-check this blog out

im using core builder to generate a mootools JS file, what classes will i need?
you will need these 2 classes for ajax:
1.Request
2.Request.HTML
theres "Request.JSON" but you will only need it if you want to use JSON instead of ajax.
when you select these 2 the other needed classes will be checked automatically
after you download the mootools-1.2.X-core.js, link it to the page you will use mootools in it like this:
<script type="text/javascript" src="mootools-1.2.3-core.js" /></script>
now you are ready to write some JS.

Request. how to?
theres nothing easier than using mootools to send request.
lets assume that we are using AJAX to let users rate a certain product without refreshing the whole page, for this purpose we will need a PHP (or any server-side language) page to accept the rating of a user and store it in database, and ofcourse a page that will send the AJAX request.
in this code we will write JS script to initialize a Request object and send the rating to the server-side page
var my_request=new Request({
url:'/rate.php',  //page URL
method:'get'   //Method (get or post)
});
my_request.send('rate=5&product_id=69');//data sent
//or you can give the send() function the parameters 
//as an object for better readability
my_request.send({
rate:5,
product_id:69
});
simple eh? you can spare some chars and do this instead:
new Request({
    url:'/rate.php', method:'get'
}).send({
           rate:5,
           product_id:69
    });
you can also specify the GET/POST parameters while initializing the Request object like this:
new Request({
    url:'/rate.php', method:'get'
    data:{
           rate:5,
           product_id:69
    }
}).send();
the code above will succeed in doing what its supposed to do, but that isnt enough for us we want to notify the user that the rating was done successfully or failed because of an error or because he already rated that product.
and thats why i like Mootools when you use regular you write at least 2 functions; sending a request, accepting the response. in mootools you can do all that while initializing the Request object by using these functions:
onSuccess : when the request is sent and received a successful response from the server. it has 2 parameters; responseText and responseXML
onFailure : when the server sends an unsuccessful response
onCancel : when you cancel the Request by sending a new one from the same Request object. or using the "cancel()" function
onException : happens when theres an exception during setting the headers of the request object (rare), in that case you will need to check your data parameter(or object)
onRequest : fires up when you use the "send()" function
onComplete : like onFailure and onSuccess.
now lets use them in our code:
var my_request=new Request({
url:'/rate.php',  
method:'get',
onSuccess   : function(serverResponse){
         //if this part of code was reached then everything is going fine :D
         if(serverResponse==1)alert('thank you for rating this product');
              else   if(serverResponse==0) alert('sorry you cant rate the same product twice');
},
onFailure : function(){
alert('sorry we have an internal error, try again later');
}
});
my_request.send({
rate:5,
product_id:69
});
pretty awesome and easy, right?
as you may have noticed the code above, the server side sends either a "1" or "0"; one for rating successful and 0 for an error and produces the appropriate "alert()" message, but what if we want to use the response text to update a DIV's(or other element) innerHTML, which is a very common thing to do with ajax. thats why we have the "Request.HTML" object

using the Request.HTML:
from its title you can tell that this object deals with HTML elements, it can be used to load the content of a certain HTML DIV from the server-side. for example fetching a part of the page that wasn't loaded initially.

how to use it
its same as the regular Request n its usage but theres 2 extra things:
1. update:
check this code:
new Request.HTML({
url:'/rate.php', method:'get',
update: $('confirmMessageDiv'),
onFailure : function(){
alert('sorry we have an internal error, try again later');
}
}).send({rate:5,product_id:69});
really simple, in the "update: $('confirmMessageDiv')" we used the DIV id that we will update it's content, in this one we assume that the server-side page processes the rate and sends back a confirmation message as text(or HTML)
be careful this doesn't support JS like any regular AJAX request
2."Element.load()":
you will love this:
$('confirmMessageDiv').load('/rate.php',data:{rate:5,product_id:69});
this replaces all the previous code in just a line :amr:

theres one last trick:
$('someFormId').send('url.php');

this one takes a form ID and sends it in ajax.

thats all, if you liked it +rep me
check Amrosama.Codecall.net - Power of the moo-stash! Mootools for mootools classes :amr:
  • 2


#511134 PHP: Currently Active Users

Posted by amrosama on 27 September 2009 - 03:51 AM

hi all,
in this tutorial ill show you how to show the users that are logged on to your website like the one in codecall home page.theres several techniques that you can use to do so, i choose to use this one for simplicity.

Overview:
it will work by storing the last time a user accessed a page on your website in a table called "navigation" by placing a simple query on the top/beginning of all pages on your website, then to show the currently active users we make a query to show the records in table "navigation" in the last <X> minutes.

Navigation table:
the table that will contain a list of usernames with last time the user accessed a page on the website:
CREATE TABLE  `navigation` (
  `username` varchar(50) NOT NULL,
  `time` datetime NOT NULL,
  PRIMARY KEY (`username`)
) 
as you can see it only has 2 fields Username, time. you can add more fields if you want to like IP address or page URL the user accessed.
becareful this table can get huge if you dont specify a primary key (user), and insead of using regular insert statements we will use replace into or update.

Navigation script: (navigate.php)
if(isset($_SESSION['username'])){
	$user=$_SESSION['username'];
	$date=date('c');
	mysql_query("replace into navigation (username,time) values('$user','$date')");
}
pretty simple, eh? all it does is checking if theres a username key/variable in the $_SESSION super global array, if theres it means the user is logged in so we can update the navigation table with last time he accessed the website. i used "replace into" because its shorter than update statement and can be helpful if you have more than one primary key (in this case i dont).
i placed this in a seperate script to call it (require/include) from other pages on the website like the index page we will see below

Showing Results: (index.php)
now when a user logs in to your website and open any page with the above script will insert/update the navigation table like this:
| Username  |  Time               |
----------------------------------
| amrosama  |2009-09-02 19:28:13  |
| someuse   |2009-09-02 15:27:36  |
__________________________________
no user will have more than one record, so the query will be really simple:
select username from navigation where time>'$d'
where $d will be the datetime value used to get active users, the whole DIV should look like this:
 <?php 
             $d=date('c',time()-5*60);//last 5 minutes
             $q=mysql_query("select username from navigation where time>'$d'");
             if(mysql_affected_rows()>0){
	             print "<ul>";
	             while($users=mysql_fetch_array($q)){
	             	print "<li>{$users[0]}</li>";
	             }
	             print "</ul>";
             }
?>
to make a date in mysql format i used "date('c')" and it takes a second parameter with the UNIX timestamp. you can get the current time stamp by calling the function "time()" to get the timestamp of 5 minutes ago we do this "time()-5*60" (5minutes X 60 seconds foreach minute)
-the rest should be easy :D, the index.php ,navigation.php and some screens are attached

Attached Thumbnails

  • 2.JPG
  • 1.JPG

Attached Files


  • 6


#506035 Problems with Sessions

Posted by amrosama on 04 September 2009 - 04:48 PM

i think cc server auto-starts the session.
try checking if the session was already started by doing this:

if(!isset($_SESSION)) session_start();

  • 1


#458525 ascii chess to opengl board

Posted by amrosama on 04 May 2009 - 09:35 PM

ASCII Chess to chess table

hi codecallers,
overview:
the purpose of this project is to convert chess board expressed in ascii into an opengl window with the chess pieces according to the ascii files
how it works:
all it does is reading the board.txt file that contains the ascii text it must be like this format:
bRk|bKn|bBi|bQu|bKi|bBi|bKn|bRk|
---+---+---+---+---+---+---+---  
bP |bP |bP |bP |bP |   |bP |bP |
---+---+---+---+---+---+---+--- 
   |   |   |   |   |   |   |   |
---+---+---+---+---+---+---+--- 
   |   |   |wP |   |bP |   |   |
---+---+---+---+---+---+---+--- 
   |   |   |wQu|   |   |   |   |
---+---+---+---+---+---+---+--- 
   |   |   |   |   |   |   |   |
---+---+---+---+---+---+---+--- 
wP |wP |wP |   |wP |wP |wP |wP |
---+---+---+---+---+---+---+--- 
wRk|wKn|wBi|   |wKi|wBi|wKn|wRk|
-notice the "|" at the end of each line
it reads each line and parses it using the "|" sign and converts the contents (bP ) into an int(-6) that represents the piece
pieces are represented in integers like this:
// -,+ -->black or white
                //  1,2,3,4,5,6,7  -->piece type, where 1 means empty cell
                //ex: -2 ==>black knight 
                //    6  ==>white king
the chess pieces are stored into a 2D array, and in the display function each element(chess piece) is drawn with its attributes(the int value) and according to the int value a specific texture is loaded for it
for(int i=0;i<8;i++)
	{
        for(int i2=0;i2<8;i2++)
        { 
            element(x,y,board[i][i2]);
            x+=5;
        }
        y-=5;
        x=-35;
    }

TO DO:
-the black and white cells
-available moves for each piece
-highlighting pieces that are in danger

help?
if anyone can make it better, modify it and post it here. im open for any suggestions or comments

usage:
it works on both windows and linux.
for windows:
you can download the executable and run it perfectly, but place the "board" folder that have the textures in the same place as the exe and the "board.txt" which have the text to be converted
source-code: you can open the project with devcpp using the project file in the attached files, make sure you have the glut package installed
for linux:
-you can compile it by opening the directory that has the project in it "cd asciichess" then make "make" to compile the files. the you can run it from the generated executable called "asciichess"

screenshots:
http://forum.codecal...=1&d=1241501539

Attached Thumbnails

  • screen.JPG

Attached Files


  • 1


#454453 CodeCall: April Newsletter, 09

Posted by amrosama on 16 April 2009 - 01:01 AM

at last!
we should do this more often
  • 1


#432531 IMPORTANT!!

Posted by amrosama on 08 February 2009 - 07:43 AM

This is not news, I knew full well that Jordan overtook me.

When you consider the fact that Jordan has been here since CC started, and I have only been here under a year, I'm actually doing pretty well.


yes you do, glad that we have you here
  • 1


#431391 C++/opengl –part3 : creating simple game

Posted by amrosama on 03 February 2009 - 07:29 AM

its attached to the first post here
heres the link
enjoy
  • 1


#430404 Represent your Life in Code

Posted by amrosama on 30 January 2009 - 11:31 AM

hgaha IN YOUR FACE XAV!
thnx logan
  • 2




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download