Zend Framework Gdata API and Cakephp insert a new row to Google spreadsheet
To setup Zend Framework Gdata, see this post on Using the Zend Framework in CakePHP , this helped too.
As reference use: Google Spreadsheets APIs and Tools Developer’s Guide: PHP
In this doc you will see functions like printFeed, that can be found in Spreadsheet-ClientLogin.php it’s a SimpleCRUD implementation for google spreadsheet.
The document key is http://spreadsheets.google.com/ccc?key=HERE&hl=en, you will need it to point to the spreadsheet you want to edit.
Also spreadsheets can have multiple worksheets, you will need the key of the worksheet you want to edit, this key can be get by calling the promptForWorksheet() function.
Also, when adding a new row, you need to give a list of header-row=>value, so the tricky part here is to get the “header-row”. The documentation describe it as:
“the first row of the worksheet as a header row”
“column headers will be converted into valid XML namespaces”
I did just listGetAction() and look up the names of the header-row to use.
So here is the code, hopefully this will give you a fast start and save you time.
class SomeController extends AppController {
var $uses = null; // Don't use any model
function index() {
App::import('Vendor', 'zend_include_path');
App::import('Vendor', 'Zend_Gdata', true, false, 'Zend/Gdata.php');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$user = 'username';
$pass = 'password';
$this->currKey = 'thesheetkey';
try {
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $authService);
$this->gdClient = new Zend_Gdata_Spreadsheets($httpClient);
$this->promptForWorksheet(0); // Put the 0th worksheet of our sheet to $this->currWkshtId
$this->listGetAction(); // Will list all the rows inside the worksheet
$row = array('column1'=>'value','column2'=>'value','columnN'=>'value');
$this->listInsertAction($row);
} catch ( Exception $e ) {
echo $e->getMessage();
}
}
public function promptForWorksheet($wordSheetI=0)
{
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($this->currKey);
$feed = $this->gdClient->getWorksheetFeed($query);
print "== Available Worksheets ==\n";
$this->printFeed($feed);
$input = $wordSheetI;
$currWkshtId = split('/', $feed->entries[$input]->id->text);
$this->currWkshtId = $currWkshtId[8];
}
public function listGetAction()
{
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query->setSpreadsheetKey($this->currKey);
$query->setWorksheetId($this->currWkshtId);
$this->listFeed = $this->gdClient->getListFeed($query);
print "entry id | row-content in column A | column-header: cell-content\n".
"Please note: The 'dump' command on the list feed only dumps data until the first blank row is encountered.\n\n";
$this->printFeed($this->listFeed);
print "\n";
}
public function printFeed($feed)
{
$i = 0;
foreach($feed->entries as $entry) {
if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) {
print $entry->title->text .' '. $entry->content->text . "\n";
} else if ($entry instanceof Zend_Gdata_Spreadsheets_ListEntry) {
print $i .' '. $entry->title->text .' | '. $entry->content->text . "\n";
} else {
print $i .' '. $entry->title->text . "\n";
}
$i++;
}
}
public function listInsertAction($rowArray)
{
//$rowArray = $this->stringToArray($rowData);
$entry = $this->gdClient->insertRow($rowArray, $this->currKey,
$this->currWkshtId);
if ($entry instanceof Zend_Gdata_Spreadsheets_ListEntry) {
foreach ($rowArray as $column_header => $value) {
echo "Success! Inserted '$value' in column '$column_header' at row ".
substr($entry->getTitle()->getText(), 5) ."\n";
}
}
}
}
The same code in the pastebin http://pastebin.com/f12021eb.
PrestaShop activate templates debug
PrestaShop seem to be a good e-commerce software, full of features, but with missing dev documention.
To activate templates debug, edit config/smarty.config.inc.php
And make
$smarty->debugging = true;
After you will refresh a page, themes/debug.tpl will be rendered.
How to convert unicode code point to the character (binary) with PHP
You want to display a unicode code point as the char it actually represent ?
For example, display for U+00CE the Î character it represent. (here is the list of all romanian special characters)
Quite strange, I didn’t find a ready to work code for that instantly (as I usually do)
For our task, we will need the berlioz’s unicode2utf8 (that support 4 bytes utf, initialy I got a function that supported only 3 bytes and got errors, if you need 6 bytes support, see the Unicode_to_UTF function) function.
Here is the trick, unicode2utf8 requires as argument an integers, 00CE in our example (and the unicode notation) is hex, everything we need to do is to apply the hexdec function.
Php code:
echo unicode2utf8(hexdec("00CE")); // Result: Î
// Or the function that will recognize U+ in front of string, and will skip it to show the character
function unicodeCodePointToChar($str) {
if (substr($str,0,2) != "U+") return $str;
$str = substr($str,2); // Skip U+
return unicode_to_utf8(array(hexdec($str)));
}
echo unicodeCodePointToChar("U+00CE"); // Result: Î
Why I would ever need that, you will ask, well I need to implement sphinx’s charset_table convert logic on the user’s string. Here’s the map I used, kindly provided by someone on a pastebin.
So if a user search for “bălan”, he will actually find both “bălan” and “balan”.
Screen cum de schimbat combinatia ctrl+a pe altceva
În screen, by default, ctrl+a e folosit pentru a accesa “modul de comandă”, de exemplu pentru a trece la alt screen.
În bash (a preluat stilul emacs), ctrl+a este folosit pentru a sări la primul caracter, iar ctrl+e la ultimul caracter (tastele end si home nu funciclează chiar bine).
Așa deci are loc un conflict de taste, si cele din bash nu mai lucreaza, ca sa lucreze trebuie de schimbat tastele p/u screen.
În ~/.screenrc
adăugați
escape ^Ee
Acum dacă veți lansa screen, ca să accesați modul de comandă, veți utiliza ctrl+e
Referință: http://answers.google.com/answers/threadview?id=76663
Velib Paris pushpins for Microsoft Autoroute 2002
Yesterday walking around the Paris and searching for velib I thought it were a good idea to have all the points on mine Autoroute map..
Today didn’t found a 2 clicks way to import something, but I still found all the station with latitude and longitude data from http://www.velib.paris.fr/service/carto, but in XML format.
Unfortunately autoroute 2002 seem to be too old for xml, anyway, didn’t take too much with a regular expression I extracted interested columns separated by tabulator character and constructed a cvs file.
Copy it from here http://pastebin.com/pastebin.php?dl=f441c1181
Save this into a velib_pushs.csv, after On the Data menu, click Import Data Wizard, importing from a plain-text file (*.txt, *.csv) select the velib_pushs.csv file, click Next, first column is name, second Address, third Latitude fourth Longitude click finish, now look at the Paris, you should see a lot of pushpins, like here:
Remove FreeBSD non-root process port <1024 limit
Under FreeBSD is easy to remove this limit by changing net.inet.ip.portrange.reservedlow and net.inet.ip.portrange.reservedhigh
FreeBsd tracd “rc.d” script
If you want to run trac as a standalone server for startup you’ll need a /usr/local/etc/rc.d script, by default it is missing.
First google search gave me this http://freebsd.amazingdev.com/blog/archives/000798.html
I have slightly modified this script to play better with pids:
#!/bin/sh
#
# tracd.sh for rc.d usage (c) 2006 Jonathan Arnold, 2008 Nicolae Namolovan
# $Id$# PROVIDE: tracd
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable Tracd:
#
# tracd_enable="YES"
# # optional
# tracd_flags="-d --listen-port=3690"
# tracd_data="/usr/local/path/to/project". "/etc/rc.subr"
# Set some defaults
tracd_enable=${tracd_enable:-"NO"}
tracd_flags=${tracd_flags:-"-d --port=8080 "}
tracd_data=${tracd_data:-"/usr/local/trac"}
tracd_pidfile=${tracd_pidfile-"/var/run/tracd.pid"}name="tracd"
rcvar=`set_rcvar`
load_rc_config $namecommand=/usr/local/bin/tracd
command_args=" --pidfile=${tracd_pidfile} ${tracd_data}"
command_interpreter="/usr/local/bin/python"
pidfile="${tracd_pidfile}"run_rc_command "$1"
And your vars in /etc/rc.conf should look smth. like:
tracd_enable="YES"
tracd_data="/usr/local/trac/project/"
tracd_flags="-dsp 8080 --auth=project,/usr/local/trac/project/conf/users.htdigest, ProjectRealm"
Csup nor cvsup through proxy doesn’t work ? When ssh forward facility come in handy..
Let’s say you have two machines, one with internet, and one without.
On the machine with internet, you have a proxy and a ssh account.
Unfortunately csup nor cvsup cannot work through a proxy, so here where ssh forward facility will come in handy.
Let’s say your csup is configured to update from cvsup4.FreeBSD.org.
Ssh is a magic tool, it can listen a local port, and forward everything through it’s protocol to another machine and there connect to some remote host..
ssh -L 5999:cvsup4.FreeBSD.org:5999 user@machine_with_internet
And we’re done ! %)
Now just run csup with -h 127.0.0.1
Tada !
Hello Vista
Sub Vista mapa Documents and Settings din XP a fost separată in doua mape Users si ProgramData.
Vista la bootare deodata suge ~750mb de ram, asa deci fara cel putin 2gb de ram nici nu riscati sa va ginditi la Vista, ca nici nu-s chiar asa multe beneficii.. Folosesc deja de 4 zile, si numai licenta de pe el ma tine sa nu-l sterg ;o)
http://www.petri.co.il/disable_uac_in_windows_vista.htm solutia cu msconfig e ft comoda. La intrebarea “daca intradevar vreai sa executi ceva” m-a lăsat perplex ;o) Dar totul e bine ce se termina bine.. heh
http://www.ghacks.net/2007/03/28/disable-balloon-tips-in-windows-vista/ mesajele de linga ceas care permanent apar mă irita straşnic, mai ales de la programe custom, dar iaraşi, niste modificari in reestru si totul e ca inainte, huh. Evident cind is in tren stiu ca nu am internet, programe lefie..
http://www.howtogeek.com/howto/windows-vista/fixing-problems-with-synergy-on-windows-vista/ mult iubitul (de 2 zile? huh) nu stiu ce sughita sub vista. Scriu mai incolo cum Synergy a facut ca 1 keyboard si 1 mouse sa lucreze la 2 compuri..
In Vista au aparut ceva similitudini cu symlink-urile de sub unixuri NTFS junction point
Cum de setat remote desktop sau eventual vnc pentru a fi accesibil aproape din orice retea
Se presupune ca compul pe care stau aceste servicii are acces direct la internet, iar problema consta anume in conectare la ele din retelele limitate petru accesare doar a resurselor web si maximum si skype-ul sa mai mearga.
Asa cum hot spot-urile public accesibile cit si retelele unversitare dese ori au limita la porturi care pot fi accesate, configurarea rdp sau vnc sub portul 80(http) sau https(443) va mari de multe ori probabilitatea ca va veti putea conecta din orice colt a globuletului.
Aceeasi “tactica” se poate de aplicat si pentru rularea a altor servici gen proxy etc..
Iar daca va trebuie sa setati ca rdp sa mearga printr-un proxy (el nu are asa optiune), copiati ferm sockscap sau freecap si incercati sa porniti prin ele, am impresia ca rdp nu stiu de ce merge numai prin sockscap (la Adrian asa a fost cazul).

leave a comment