Update web directory after commit in SVN

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 05-03-2010

0

Hi,

some new tips about subversion :D

if you need to update a web directory after someone make a commit just follow this guide: http://subversion.apache.org/faq.html#website-auto-update

i wanted to post this why it take me some time to figure out that a simple bash script don’t going to work and even if it worked with some tricks, i always getting a merge and not an update of the repository :P

some thing that the faq don’t mention is how to compile the program, if you are a newbie and don’t know how to do it, just run this command

gcc your_file_name.c -o your_binary_name

i hope it helps :D

Regards.

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Foreach objects in smarty

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 05-03-2010

0

Hi,

recently i changed how a REST API sent the info from xml to JSON, that mean that now the arrays was converted into objects after the json_decode(). don’t was too much problem till i see that my smarty templates don’t worked anymore :(

the change of each file don’t was an option and the convert from objects to arrays is wasting resources in nothing, so i made a hack in the smarty main class :D

basically in the file Smarty_Compiler.php at line numero 1203 i added this if():

if(is_object($from)){
$output .= “\$_from = $from;”;
$output .= “foreach(\$_from as $key_part=>$item){“;
}else{

and in the else, you wrap all the other code to parse arrays :D

now the foreach will parse objects and arrays :D

i hope it helps.

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Weird php bug? : “” == 0

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 18-01-2010

0

Hi,

just happened something weird, i have a sentence like this:

if($var!=”"){

}

the thing is that the var sometimes get the value of 0, and for some reason it returned false (something that never happened to me before in 3 years programming in php). anyway i understand that can be considered as normal, but i wondering if is a bug :s (why it don’t happened before )

the solution?

if($var!==”"){

}

i hope has been useful :D

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

serialize array with javascript (php compatible, associative arrays and mootools)

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 04-10-2009

0

Hi,

one of the task i was need to do, was to write a javascript funtion to serialize a array, so can be sent through ajax.

the task wasn’t easy, why searching on the web i only found partially working functions (some that only proccess numerical arrays, other even’t didn’t worked, and wasn’t recursive) but serching i come up with the perfect javascript serialize function ever :D

in resume it can:

  • parse numerical arrays
  • associative arrays
  • mixed arrays
  • multidimensional arrays
  • it detect if the index or values of the element it’s int or string and parse it accordingly
  • mootools compatible (read below what i mean with  this

so i dont want you wait anymore, here it’s the function:

function serializeArray(ArrayElem)
{
var cont=”";
var counts=0;
var jj;
var res = “”;

for(jj in ArrayElem)
{
//if mootools it’s included, this hack prevent that the function parse also the prototype objects
if(jj==”$family”){
res = ‘a:’+counts+’:{‘;
res += cont;
res += ‘}’;
return res;
}
if(isInt(jj)){
cont += ‘i:’+jj+’;';
}else{
cont += ’s:’+jj.length+’:”‘+jj+’”;’;
}
if(isArray(ArrayElem[jj])){
cont += serializeArray(ArrayElem[jj]);
}else{
if(isInt(ArrayElem[jj])){
cont += ‘i:’+ArrayElem[jj]+’;';
}else{
cont += ’s:’+ArrayElem[jj].length+’:”‘+ArrayElem[jj]+’”;’;
}
}
counts++;
}

res = ‘a:’+counts+’:{‘;
res += cont;
res += ‘}’;

return res;
}

function isArray(obj) {

return obj.constructor == Array;

}

function isInt(myNum) {
// get the modulus: if it’s 0, then it’s an integer
var myMod = myNum % 1;

if (myMod == 0) {
return true;
} else {
return false;
}
}

i going to explain some things about this function:

  1. the isInt() function it’s very simple, i dont know if it can fail with some weird value, but at least it’s fast and cross browser compatible
  2. i’m using a counter and not the length propertie of the array why with associative array it return 0
  3. as you see, there it’s a hack for mootools, that it’s it make it “compatible”, whiteout that hack the function also parse all the native properties and elements added at the moment when you add mootools to the document. i didn’t know any other form to stop it, so if you know something advise :D
  4. in the php that receive the serialized array, remember to use stripslashes if the magic quotes are ON and maybe you going to need to use html_entity_decode() (at least that was my case) to convert the doble quotes character to signs.

i hope it help you, it’s very easy to use and understand and can save you some hours of work :D

Regards,

Shadow

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Import big xml to oscommerce or mysql database

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 02-10-2009

0

Hi,

recently i have needed to do a script that parse a big xml file and insert it to a oscommerce database. i wanted to write this post why can be useful if you are doing something like this and maybe with other CMS system or database schema :)

the script no only need to insert the products, also download the images, check if the product already ,xist and update the product with the info of the xml. i don’t going to describe the trivial process of check for the product, make the queries etc.. if you are seeing this post you are run with some of the 2 essential problem:

1)out of memory error

2)session timeout, php execution time limit or 500 internal error

so, here are the soltuion for your problems :)

1) out of memory error

this it’s happen why surely you are usng the xml_parse() to parse the xml. this function always going to give you a out of memory error why need to load all the document in the memory to use it.

the solution it’s simple, use XMLReader this going to allow to load all the xml file and let you review each element of the xml. the documentation it’s very clear of how to use it and with some of testing, in a few hours you should have working your parse function :) . the only “problem” can be it’s that’s only available from php version biggers that 5.1.2, i don’t think so but maybe you can run with some problem in some host :)

2)session timeout, php execution time limit or 500 internal error

well, this error can be fixed but going to be you more effort and ugly code but i didn’t thinked any other posible solution for this :s

if you have a php execution limit error, simply add: set_time_limit(0); this this going to let you run the script forever. of course this isn’t safe, why if you have a bug or something, can be running forever and consumming so much memory than you going to have your shosting account suspended, so be sure to test everything before you run it live :)

after you set the execution time to 0, if you still have a timeout error or a 500 internal error it’s surely happening by the mysql queries. the xml parse it’s very fast with XMLReader but the real time take the mysql queries and if you are using oscommerce and need to check too much thing going to be a nightmare :P

the only solution i come up for this, was to re-execute the script till i procesed all the xml. basically i have parse the xml into a multidimensional array like this:

$rows[$rownumber][elements]

so, i process all the xml (in this time i processed a 3MB xml) to a array, send it to a function that update the DB and processing it in 200 rows parts. after the part finished, i keep the number of rows processed and printed:

echo “processed…. $numberofrows”;

echo ‘<meta http-equiv=”refresh” content=”4;url=xmlimport.php?f=’.$filename2.’&cont=’.$continue.’&start=’.$finished.’” />’;

i used a meta and not a header() why with header it still crashed with a 500 internal error.

so, when the script load again in the function that parse the xml, i set:

if($_GET['cont']==true){

for($i=0;$i<$_GET['start'];$i++){

$xml->read();

}

}

with that, i have moved the pointer of the xmlReader object to the last inserted row, and then start to parse the rest. it continue till the rows to parse are none and the script stop :)

i hope this help someone to resolve this problem :)

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Learning php: Lesson 1

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 16-07-2008

0

Hi,

i dont know how much lines of code i write in my life, surely i wrote more than 1000 files of php of 300 lines each, at least… for that, i want to share my knowledge about this marvelous languaje, and for that, we need to start form the beginning.:D

i try to post 1 entry per day, i hope in 15 or 20 days, you can learn with my tutorial, all the basics and advanced things about the web develoment with php.

well, now, start with the lesson:

Tips to make a joomla component

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 14-07-2008

0

Hi,

working like a freelance developer you are forced to make several things, using several tools,apis, codes and framework. for a experienced developer, it’s easy to make code for a new platform, if the documentation it’s available and it’s clear.

in the past few days i has been doing a component for joomla, and it’s not hard, but has been some difficult to find some specific information about the framework. for this, i want to use this post explain the principal function and how it work :D

note:

in the bottom you going to find a hello world component like a example of all what i’m talking here.