Posts RSS Comments RSS

Archive for the 'code snippets' Category

Feed’uri rss - standarde si validare.

Rss feed standards - rss pigeon
Ma gandeam zilele astea ca pentru ca sa fim si noi la zi cu tehnologia si cu “best practice”-urile de la ora actuala ar trebui implementate niste feed-uri pe site-ul Licitatie Porumbei. Asa ca m-am apucat sa citesc standarde si sa ma uit la exemple (link 1, link 2). Am reusit sa construiesc ceva pana la urma, dar vroiam sa verific daca e totul in regula. Am cautat un validator pentru feed-uri si tot testand si modificand am ajuns la o forma valida (se poate testa). Ce mi-a placut la site-ul respectiv e ca are un help foarte bogat si am invatat de acolo mai mult si mai repede decat de pe primele site-uri ce le gasisem pe google. Sistemul de validare e complet si f bine pus la punct. De exemplu m-a atentionat la cateva item-uri la care aveam data 1 ianuarie 1970 (era ceva eroare la formatarea datei in standardul rss) ca, citez, “e putin probabil sa fie data corecta”.
Ce nu am reusit sa invat (decat dupa ce m-am uitat cum e implementat in wordpress) e cum se face sa apara imaginea de feed in “address bar”-ul de la browser.
address bar
Eventually am descoperit ca era vorba despre urmatorul tag pus in < head >
<link rel=’ alternate ‘ type=’ application/rss+xml ‘ title=’ Porumbei La Licitatie ‘ href=’ http://licitatie-porumbei.ro/feeds/rss.porumbei.php ‘ />
Se pot pune mai multe feed-uri daca adaugi mai multe tag-uri de tip <link …. > iar cand vizitatorii dau click pe imaginea din addres bar li se va afisa o lista cu toate feed-urile, in ordinea aparitiei lor in pagina.

Ce e mai greu acum vine doar. Trebuie sa invat vizitatorii cum sa foloseasca un feed-reader, pentru ca in target-ul site-ului nu intra oameni care stau toata ziua la PC. Sunt unii care deabia se descurca sa-si faca un cont.

AJAX - best choice

In ultimii ani evolutia mea (profesionala) se bazeaza pe Internet in proportie de peste 90%. Ocupandu-ma cu programarea (web-development in ultimul timp), caut pe Google solutiile la toate problemele de care ma bat in dezvoltarea unei aplicatii. Chiar si in viata “dinafara PC’ului”, cand am nevoie de o documentare sau un pont rapid in legatura cu un subiect oarecare, tot Internetul e cea mai fiabila solutie. Acelasi lucru se intampla pentru majoritatea care au parte de lucrul cu un calculator in domeniul lor.some logo
Am folosit AJAX in cateva site-uri nu foarte importante iar tehnologia care am utilizat-o a fost o “cârpeala” incropita de mine la repezeala, scurt si la obiect, cu o functie de constructie a obiectului XmlHttpRequest, o functie sau doua de apelare a serverului si unul sau doua fisiere *.php pe post de server. Totusi, nevoia te impinge sa complici situatia chiar daca nu ai nici un chef de “fancy stuff” (oricat ar fi ele de recomandate). Asa ca a trebuit sa aleg un framework “profesional” pentru lucrul cu AJAX.
Prima data am incercat MyAjax, dezvoltat de Raul Ionescu, dar din cauza documentatiei “subtire” m-am gandit sa incerc altceva.
A urmat cautarea pe Google si am dat de site-ul asta:
AjaxPatterns . Contine cam toate bucatile de informatie necesara pentru a construi un site in care ai nevoie de AJAX: Tutoriale, Scule (”Tools”, nu va ganditi la alte prostii), Ponturi (”Tips”), Multe linkuri la documentatie si carti, Linkuri la alte site’uri cu si despre AJAX si o lista cu multe Framework’uri.
xajax
Lista de Framework’uri
Framework’urile sunt foarte frumos organizate, in functie de tipul de aplicatie pt care au fost construite librariile respective. Eu am ales deocamdata xajax din cauza integrarii cu PHP, a simplitatii de utilizare (Learn xajax in 10 Minutes) si pentru ca mi-a placut simetria denumirii ;).

Delphi for PHP - INSERT with QUERY

If you don’t know very well the VCL for PHP and you try to insert a new record using a Query component, you will likely get this error:
Application raised an exception class ADODB_Exception with message ‘mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 0,10′ at line …
A workaround for this is to disable the LIMIT command at runtime or design-time by setting LimitStart and LimitCount to ‘-1′;
An example how to disable this at runtime:

$query = “INSERT INTO table (field1,field2) VALUES(’” . $value1 . “‘,’” . value2 . “‘)”;

$this->Query1->close();
$this->Query1->LimitStart = ‘-1′;
$this->Query1->LimitCount = ‘-1′;
$this->Query1->SQL = $query;
$this->Query1->open();

I got this solution after studying the ECommerce sample project.

Delphi for PHP - I just got an extra day trial licence :)

Two weeks ago, I bought Delphi for PHP. I waited impatiently for the release in 22 march. The release was delayed about one week, but that wasn’t very important. I contacted the reseller to mail me the serial key and license file for the product, but they don’t have it yet. They suggested to download the trial version and use that until I get the mail I asked for. No problem. I went to the download page and I was shocked. 1 day trial? WTF am I gonna do with that? I hoped it was a mistake, a joke. I’ve downloaded (Downloads (keys where required)) it and installed it. I played with it for a while, but not very much because I had other things to do. Next day evening, I’ve opened it again, I’ve put some stuff on a form (text boxes, buttons etc) and suddenly it stopped responding. I thought it has a bug, or something. I closed it, opened it again and I found out that the license had expired (1 day of trial expired :( ). I searched on google how to extend this at least until I get the license from the reseller I bought Delphi for PHP from. I found nothing. I even searched cracks and keygen’s (naughty me :D;). Nothing yet. I was very impatient to get it work because I saw there some cool samples to play with (Web Services, eCommerce). My final solution was to try desperately something very simple that only a noob will think of: get another trial license from codegear. I went to Delphi for php download page, applied for another licence at Keys Only (If you have a CD) link, and got one. It works (2 hours now :D;). I used the same account I got first one from. Is CodeGear aware of this? (if not, shh, don’t tell them yet). I hope this trick will work for others, not only for me.
So, a short recap:
Go to Delphi for php download page.
If you haven’t already got Delphi for php, get the product from Downloads (keys where required).
After one day of trial expired, go to the same page, get a new license from Keys Only (If you have a CD), and you will get another day of testing.
Maybe tomorrow I’ll be able to get a new extra trial day somehow. A new one each day at least until I’ll get the license I payed for :)!

Delphi for PHP

Citeam niste forumuri cand dau de urmatoarea expresie: “Delphi® for PHP”. WTF? Prima data am crezut ca e vreo greseala. Dau un search pe google si gasesc asta. Nu pot sa cred. Nici nu visam la asa ceva. M-am bucurat mai mult decat daca ar fi castigat Steaua in meciul cu Sevilia. Prea multe detalii nu am apucat sa citesc, dar din video’urile demo de pe site, e cel mai tare IDE for PHP ever! Si pe deasupra si singurul RAD for PHP. Nici nu am cuvinte. Ca sa intelegeti cauza uimirii mele, trebuie sa ma confesez: sunt un fan Delphi (folosesc Delphi inca de la versiunea Delphi 3) si de cateva luni de zile m-am reprofilat pe limbaje de web development, printre care PHP si JS.Quick Review: Delphi for PHP contine componente care se adauga la proiect prin drag&drop, code management, suport AJAX si baze de date MySQL & altele etc. I’m happy now :D.
D4PHP1

Nu abuzati de cookies.

Un sfat pentru incepatorii in webdev care vreti sa folositi cookies: nu abuzati de ele. Mai bine zis aveti foarte mare grija ce date puneti in ele si cat de lung setati “expiretime”ul. Am lucrat recent la un proiect in care am folosit un sistem de login free(maaking users) bazat pe cookies. Nevoile m-au facut sa ma apuc sa modific sistemul si la un momentdat salvam in cookie o variabila care imi spunea daca user’ului ii este permis sau nu sa faca anumite operatii pe site (adica era activat sau nu). Problema era ca daca vroiam sa dezactivez userul nu se modifica variabila in cookie pana la urmatorul login (care putea fi chiar dupa 2 saptamani daca era bifata optiunea “remember me”). Uite asa userul meu ramanea activat pana la expirarea cookies’urilor.