RSS Feed
Language :
Email Address : Password :
Action :       Index       Register       Help       Forget Password?
View Entries
    Recent Entries
    Most Popular Entries
    Return to Orinetz
Parent Categories
    General
Sub-Categories
Programming Problems
Programming Troubles
Algorithms
Programming Languages
Web Programming
Database
Orinetz Main Panel
( writer : Fendy )
1 2 3 4 Next >>
CPS protocol for changing multiple web component using AJAX
Friday, May 21st 2010

Having been using both PHP and JavaScript to build this website, I find it funny that this website actually contain no AJAX at all. You can search all part of Orinetz Network and unless after I make a major makeover to this website in the future, you won't find AJAX technique used in the visible part of Orinetz Network.

Yeah I know it is pathetic, but I barely understand AJAX before I get some project to do in Freelancer.com. In fact, I accepted a medium-sized project to make games using AJAX before I know much about AJAX itself. Of course that means I have to learn AJAX really fast and I am glad I can.

When making something as complex as a game, it is often necessary to change several parts of the web-page using a single HTTPrequest. To do this I had made the following CPSresponder function, which every visitor to this blog are free to use.

function CPSresponder(cps)
{ jomed=true;
  cpsa=cps.split(' ');

  n_cpsa=cpsa.length;
  if(cpsa[0]=='ACCEPT')
  { mc=1;
    while (mc+3<=n_cpsa)
    { obj_id=cpsa[mc];
      set_type=cpsa[mc+1];
      set_val=cpsa[mc+2];
      if(obj_id.length>0)
      { comm='document.getElementById(''+obj_id+'').'+set_type+'=''+set_val+'';';

        setTimeout(comm,10);
      }
      mc=mc+3;
    }

  if (mc<2) jomed=false;
  }
  else jomed=false;

  return jomed;
}


The cps input is where you put the output of your HTTPrequest result, or part of it. The format of the cps is:

ACCEPT {element_id} {element_part} {desired_value}

Try the following script to understand how CPSresponder works.

<html>
<head><title>CPS Trial</title>
<script language="JavaScript">
function CPSresponder(cps)
{ jomed=true;
  cpsa=cps.split(' ');

  n_cpsa=cpsa.length;
  if(cpsa[0]=='ACCEPT')
  { mc=1;
    while (mc+3<=n_cpsa)
    { obj_id=cpsa[mc];
      set_type=cpsa[mc+1];
      set_val=cpsa[mc+2];
      if(obj_id.length>0)
      { comm='document.getElementById(''+obj_id+'').'+set_type+'=''+set_val+'';';

        setTimeout(comm,10);
      }
      mc=mc+3;
    }

  if (mc<2) jomed=false;
  }
  else jomed=false;

  return jomed;
}

</script>
</head>
<body>
<table cellpadding=10 cellspacing=5 border=1>
<tr><td width=100>Silver</td><td id="silver_td" width=50 align=left> </td></tr>
<tr><td width=100>Gold</td><td id="gold_td" width=50 align=left> </td></tr>
<tr><td width=100>Platina</td><td id="platina_td" width=50 align=left> </td></tr>
</table>
</body>
<script language="JavaScript">
CPS_sample='ACCEPT silver_td innerHTML <b>5000</b> gold_td innerHTML 6000 platina_td innerHTML 2500';
CPSresponder(CPS_sample);
</script>
</html>


The other step you need is connecting this CPSresponder script to an HTTPrequest.respondText which you can learn more in the AJAX tutorial available in w3schools.com. I learn most of what I know about web programming using online materials. In fact I don't know much about PHP and MySQL even after I graduated from university.

Share   :
Keywords   :   php, javascript, ajax, changing multiple web component
Action   :   Grammatic Suggestion

Views : 393       Views per day : 3.54       Comments : 0

PHP script for Seconds Difference between two datetime
Friday, May 21st 2010

Lately I have been busy working on projects I got from Freelancer.com, that I didn't get enough time to post anything in Orinetz at all. I am still busy with the same project at the moment, but I decided to write something here anyway, since I found something interesting today.

To make long story, I am getting some headache today trying to calculate the second difference between two datetime fields in SQL. The function is required as a part of the queue function in a city building game. I have tried various kind of query function, but no success at all with the SQL.

After chilling my head a little bit, I decided that trying to do the same thing using PHP will be wiser than keep finding out how to do it with SQL. The system is a hybrid between PHP and MySQL anyway and the MySQL is obviously not the programming tool. So here's the CalculateSeconds function I write to look for the difference between two stored dates.

function CalculateSeconds($date1,$date2)
{ list($date1_date,$date1_time)=explode(" ",$date1);
  list($date2_date,$date2_time)=explode(" ",$date2);

  list($date1_y,$date1_m,$date1_d)=explode("-",$date1_date);
  list($date2_y,$date2_m,$date2_d)=explode("-",$date2_date);

  list($time1_h,$time1_m,$time1_s)=explode(":",$date1_time);
  list($time2_h,$time2_m,$time2_s)=explode(":",$date2_time);

  $jd_date_1=gregoriantojd($date1_m,$date1_d,$date1_y);
  $jd_date_2=gregoriantojd($date2_m,$date2_d,$date2_y);

  $date_diff=$jd_date_1-$jd_date_2;
  $time_diff=($time1_h-$time2_h)*3600+($time1_m-$time2_m)*60+($time1_s-$time2_s);

  return $date_diff*86400+$time_diff;
}


Assuming that $date1,$date2 is written in YYYY-MM-DD HH:MM:SS format, this function should works well. The manual for using gregoriantojd can be found here in php.net and this script was partially inspired by a script in developertutorials.com. Also it is advised that you use 24 hours format for the HH part if you want to include this function in your script.

Share   :
Keywords   :   php, sql, second, datetime, difference
Action   :   Grammatic Suggestion

Views : 115       Views per day : 1.05       Comments : 0

Matlab, Maple, PHP and C Code Generator in Orinetz Orbit Simulator
Tuesday, January 5th 2010

As the first step to fulfill my New Year Resolution for 2010, I already installed a Code Generator for Orinetz Orbit Simulator. This Code Generator is capable of automatically generating Matlab, Maple, PHP and C code for simulating the behavior of any planetary system in Orinetz Orbit Simulator.


Users who want to generate a gravity simulation code, only need to open a simulation page like this and click the Data Code button in the right panel below Object.


After the Data Code button was clicked, the Data to Code Generation windows will appear. User may choose which part of codes they want to generate and their preferred programming language. For Maple and Matlab, the code generated will draw the orbit of each object inside the planetary system. The PHP and C codes will generate an ephemeris file in human readable CSV format.

Inner Solar System generated by Matlab

All simulation code generated Orinetz Orbit Simulator are Newtonian-Euler. This means that the simulation doesn't take relativistic effects into account and the algorithm used to integrate the Differential Equation Set is Euler. The simulation initial time (T0), simulation end time (T1) and resolution of the simulation (Dt and NStepPerDT) can be adjusted after the codes are pasted to their respective compiler/script reader.

See Orinetz's Goals and Work Progress for year 2010

Share   :
Keywords   :   orinetz 2010, code generator, orbit simulator, php, c, matlab, maple
Action   :   Grammatic Suggestion

Views : 159       Views per day : 0.64       Comments : 6

Semantic Disagreement between Neuroscientists
Wednesday, December 9th 2009

Today, I got a link to a news item about Cat-Scale Brain Simulator as I browse the recent status of my friends in Facebook. Basically, the news item tells me that Scientists and engineers at IBM’s Almaden Research Center had successfully completed a brain simulator with number of neuron and synapses simulated exceeding the number that a cat have. Thus they called the simulation a Cat-Scale Simulation.

Apparently, another neuroscientist Henry Markram from EPFL, disagree with the term Cat-Scale Simulation and call the simulation as a hoax. His reason was while the number of neuron and synapses simulated do exceed the one a cat have, he claimed that the model of neuron and synapses used in said simulation was oversimplified. Since the model of neuron and synapses used was oversimplified, Henry Markram claimed that the simulation doesn't deserve to be called Cat-Scale Simulation.

As always Devil is in the detail, so I decided to search more detail about the simulation in question. The first source I read was IBM Almaden's Dharmendra Modha's blog. If you read the post The Cat is Out of the Bag and BlueMatter, November 18, 2009 and pay attention to the number of processors (and the power of each) required to simulate the number of synapses mentioned, it is clear that the synapses model used in IBM Almaden's Cat-Scale Simulation is nowhere the complexity of synapses expected by Henry Markram.

While it is true that the model simulated by IBM Almaden is nowhere the complexity expected by Henry Markram, it seems that Henry Markram requirement is far too high by our computing capability standard today. When someone want to build a simulation, they have to be clear about which part of a real world phenomena they want to simulate. Different part of real world phenomena require different modeling techniques. For example, if someone want to simulate how billions of neurons connected by trillions of synapses interact, IBM Almaden's simulation is sufficient for today standard. If someone want to simulate how a small system of neurons and synapses works, then it is better to use Henry Markram's requirement. We simply have no way to have both of them with today computing technology, except if the
Differential Equations mentioned by Henry Markram turn out to be integrable into functions that require little computing power.

In the end, whether IBM Almaden's simulation is a hoax depends on our own perspectives. Practically, it is rarely important whether the Super-Computer system is really capable of simulating a cat behavior. If the Super-Computer system is enough to run the application you want to run, then you can consider to purchase it. Otherwise, do not.

Share   :
Keywords   :   ibm almaden, cat scale simulation
Action   :   Grammatic Suggestion

Views : 130       Views per day : 0.49       Comments : 0
More Projects in Orinetz Network
Friday, July 10th 2009

Recently, I wrote some basic tutorials for PHP in Orinetz InterBlog. This is the programming language I used to make the entire Orinetz Website. These PHP tutorials are actually parts of the project I am currently have in mind for Orinetz, which I am going to explain in this article.

The New Orinetz InterBlog Content Storage System

Although, the PHP tutorials I had written so far are very simple, but it is enough to point several weakness of Orinetz InterBlog system we two days before this post is written.

In the InterBlog system we have before, the content of blog entries are stored inside a varchar(8192) field. This limit the size of a single post up to 8192 characters long. This is not because I don't know about field with text type. But because in my earlier experiment with the Database System, I found no way to make text-type field to store Unicode Characters. But when I tried using varchar(8192), the Unicode strings are stored properly. Since Orinetz was aimed to become a multilingual website, the capability to store Unicode string couldn't be compromised.

The system work well so far, until I realized that a post about simple PHP tutorial take as much as 6000 characters. Considering that the average PHP scripts have the size of over 20 kilobytes and I have to put some coloring tags to ease learning, more advanced tutorials would take more than 8192 bytes in space. It is clear that I have to upgrade the content storing system in Orinetz InterBlog.

Having took advices from several web programming seniors in some web programming forums, I learned that it is not really a wise idea to store big chunk of data inside a database. Database are designed to store relational data, not to store something like images or really long stories. Based on this advice, I started designing a new system for Orinetz InterBlog, where the blog contents are stored inside files instead of database. Now, the database only have to store the name of files where blog contents are stored.

The updating process didn't take a long time. I used a PHP script to transfer all data from the old content storage system to the new one, change some hotlinks management settings and install the new InterBlog PHP scripts.

The new system is already fully functional. If you want to write a content with size exceeding 8192 bytes, you can do so already. Of course, I still have to limit the size of a single post and the maximum number of daily posts to prevent spamming.

Plan for Orinetz Application Market

Orinetz Application Market is a planned web application in Orinetz Network that allow Orinetz contributors to develop web-based applications and earn money as people use those applications (or not if they choose to). These applications would have to be written in PHP, which is one of the reason why I started writing PHP tutorials.

This plan was motivated in part to make Orinetz Network financially independent from Orimath.com, a mathematic solver webstore of mine. Until now, the cost of hosting and domain for Orinetz, was taken from the income I got from Orimath. It is not possible to do this forever though, as I had planned Orinetz to become a bigger website than Orimath. Thus, Orinetz have to become financially independent from Orimath.

Since Orinetz is a descendant of Orimath, I would expect that the earlier applications available in Orinetz Application Market would be Step-by Step Mathematics Solvers ( Orimath Solvers provides the steps used to solve a problem along with the answers ). However users don't pay and purchase the application like in the case of Orimath. In Orinetz Application Market, users would have to purchase a number of points, which number would be decreased as they use the applications available in Orinetz Application Market.

The benefit of this system for users lies in the fact that they can use any application available in Orinetz Application Market, as long as they still have the points. Also note that mathematics is a very wide subject. There are different kinds of problem a student would have to face during their school years. Purchasing a solver application for each specific mathematics problem would be impractical. The fact that Orinetz Network already designed as multilingual also means that those application could be available in many languages.

For the Application Contributor, the benefit would lies in the fact that it is harder to pirate a server side web application than to pirate a desktop application. Anyone can simply copy paste a desktop application to their friends, but you would need a good hacking skill to get a server side web application.

This plan however, is still far from final. I still have to plan out how contributors are going to develop their application, how translators are going to translate those applications, how paying customers could be identified and the type of deals to be made available to customers.

That is my future plan for Orinetz Network. Feel free to comment since I am in a need for more feedback.

Share   :
Keywords   :   orinetz interblog, blogger, content storage, php
Action   :   Grammatic Suggestion

Views : 135       Views per day : 0.32       Comments : 0
1 2 3 4 Next >>