Adrenalin’s Experience

Unix tools I start using in 2010

Posted in Uncategorized by Adrenalin on January 7, 2011


Linux CentOS how to force 1000megabits ifconfig eth0

Posted in Uncategorized by Adrenalin on January 6, 2011

ethtool -s eth0 speed 1000 duplex full autoneg off
In my case it's peth0.

Other commands:
lspci |grep Ethernet
dmesg |grep eth0
ethtool eth0
ethtool -k eth0
ethtool -S eth0

To make the changes permanent, edit
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"



Zend Framework Gdata API and Cakephp insert a new row to Google spreadsheet

Posted in cakephp by Adrenalin on November 7, 2009

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, 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');
	$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');
		} catch ( Exception $e )  {
		echo $e->getMessage();

public function promptForWorksheet($wordSheetI=0)
	$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
	$feed = $this->gdClient->getWorksheetFeed($query);
	print "== Available Worksheets ==\n";
	$input = $wordSheetI;
	$currWkshtId = split('/', $feed->entries[$input]->id->text);
	$this->currWkshtId = $currWkshtId[8];
public function listGetAction()
	$query = new Zend_Gdata_Spreadsheets_ListQuery();
	$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";
	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";
public function listInsertAction($rowArray)
	//$rowArray = $this->stringToArray($rowData);
	$entry = $this->gdClient->insertRow($rowArray, $this->currKey,
	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

Tagged with: , ,

PrestaShop activate templates debug

Posted in Uncategorized by Adrenalin on November 6, 2009

PrestaShop seem to be a good e-commerce software, full of features, but with missing dev documention.

To activate templates debug, edit config/

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

Posted in Uncategorized by Adrenalin on October 18, 2009

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”.

Tagged with: , ,

Screen cum de schimbat combinatia ctrl+a pe altceva

Posted in unix by Adrenalin on October 3, 2009

Î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

escape ^Ee

Acum dacă veți lansa screen, ca să accesați modul de comandă, veți utiliza ctrl+e


Tagged with: , ,

Velib Paris pushpins for Microsoft Autoroute 2002

Posted in Uncategorized by Adrenalin on June 1, 2008

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, 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

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

Posted in freebsd by Adrenalin on March 24, 2008

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

Posted in freebsd by Adrenalin on March 23, 2008

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

I have slightly modified this script to play better with pids:

# for rc.d usage (c) 2006 Jonathan Arnold, 2008
# $Id$

# PROVIDE: tracd
# 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_flags=${tracd_flags:-“-d –port=8080 “}

load_rc_config $name

command_args=” –pidfile=${tracd_pidfile} ${tracd_data}”

run_rc_command “$1”

And your vars in /etc/rc.conf should look smth. like:

tracd_flags=”-dsp 8080 –auth=project,/usr/local/trac/project/conf/users.htdigest, ProjectRealm”

Tagged with: , ,

Csup nor cvsup through proxy doesn’t work ? When ssh forward facility come in handy..

Posted in freebsd by Adrenalin on February 14, 2008

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

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 user@machine_with_internet

And we’re done ! %)

Now just run csup with -h

Tada !

Tagged with: , , , , ,