Adrenalin’s Experience

Unix tools I start using in 2010

Posted in Uncategorized by Adrenalin on January 7, 2011

dstat
htop

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
/etc/sysconfig/network-scripts/ifcfg-eth0
add
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"

Ref:
http://www.cyberciti.biz/tips/howto-linux-add-ethtool-duplex-settings-permanent.html
http://www.centos.org/modules/newbb/viewtopic.php?topic_id=19544&forum=40
http://www.dslreports.com/forum/r22221731-Gigabit-NIC-only-working-as-100meg-in-CentOS

Advertisement

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

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

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

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

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 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
# $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 $name

command=/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”

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

Tagged with: , , , , ,