Monday, September 17, 2012

Share a directory with windows using samba to everybody in the local network

Samba is a free software implementation of the SMB/CIFS networking protocol, originally developed by Andrew Tridgell. it alows people to share files between  Linux machine and Window Machine.

To install samba run tis command:

sudo apt-get install samba

-First let's make sure only your local network can access samba service. Open and edit /etc/samba/smb.conf


interfaces = lo eth0
bind interfaces only = true
lo an eth0 should your network interfaces name run (ifconfig) to get the right names.
-To share a directory with everybody withour login/password: change security to share instead of user than enable guest account:
security = share
guest account = nobody
-Now, you can create a share to be accessible to users:

[public]
    comment = this folder is accessible by everybody
    path = /tmp #path the dir to share
    browseable = yes
    read only = yes
    guest ok = yes
To allow people to write to directory change  read only to no and add the folowing
writable=yes
You can test you configuration using the command
$testparm
If everything is fine, reload samba service to have your new configuration taken into account:
#ubuntu
$sudo /etc/init.d/samba reload
or
$sudo reload samba
#debian
$/etc/init.d/smbd reload
Or just
$reload smbd
That's all, anybody in your local network have now access to the folder /tmp.

Thursday, March 8, 2012

Free stemming API

Assalamualaikum / Hello / Hola / Bonjour,

It's been a while since my last article here, today i'm coming with something really interesting and very useful, i was looking for in while, an api that regroup many stemming algorithms , it support all languages and you can use it just using curl. you give it the word the language an the algorithm and you get the step like magic, and what's very cool is that all algorithms are open source  wow that's really cool! yea you can download it and change it if necessary than use it, isn't cool?
What?
Well if you don't know what the stemming is let me give a short definition: It's the process of reducing a word to it's origin(base) word called stem, it's used in search engine and dictionary.

'play', 'playing' and  'plays' for example have one common base word witch is  'play': more details are http://en.wikipedia.org/wiki/Stemming

You can find the API in this link : http://text-processing.com/docs/stem.html
and here is an example of using it in php:
ps: Of course you need to have curl installed

<?php
function get_stem_word($parameters) {
    $curl = curl_init();

    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";

    curl_setopt($curl, CURLOPT_URL, 'http://text-processing.com/api/stem/');
    curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameters));
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
    curl_setopt($curl, CURLOPT_AUTOREFERER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);

    $result = curl_exec($curl); // execute the curl command
    curl_close($curl); // close the curl connection

    return json_decode($result);
}

$stem_object = get_stem_word(array('text'=>'playing', 'language'=>'english','stemmer'=>'porter'));
$stem = $stem_object->text;
echo $stem;

Parameters:
    text : The word you want it's stem, required;
    language: The laguage of the word, Optional, The default value is english;
    stemmer: the stemming algorithm, Optional,  The default value is porter.

Bounmed,

Friday, March 25, 2011

[PHP : is_writeable — Alias of is_writable()] is this a joke?

I just saw this function in the php.net manual (here) read it and tell me what do you think??

is_writeable

 (PHP 4, PHP 5)
is_writeable Alias of is_writable()

Sunday, February 13, 2011

The favicon appears briefly, then it disappears [Bug firefox]

Firefox have a weird bug related to the change of location.hash value, when you change this value the favicon disappears, I've spent a whole day searching how to fix this, the solution is simple all you have to do is to remove the favicon link then set it again after any change of the location.hash value.
Here’s the jQuery function from  http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/:


function setFavicon() {
  var link = $('link[type=image/x-icon]').remove().attr("href");
  $('<link href="'+ link +'" rel="shortcut icon" type="image/x-icon" />').appendTo('head');
}
and add setFavicon();  after any location.hash=url;


Based on the second comment bellow 



1- You should use quotes in the attribute selector like follow to make it work with new version of JQuery:

$('link[type="image/x-icon"]').remove().attr("href");

2- It's better to test on the rel attribute instead of testing on the type attribute because firstly a Favicon is not necessarily of type ico
and secondly if we follow the HTML standard (http://en.wikipedia.org/wiki/Favicon) a favicon is known by the rel="icon" attribute value:

$('link[rel*="icon"]').remove().attr("href");

Sunday, September 5, 2010

Installing Django on Windows

You hear about the the power of python and his framwork Django, you want to taste the joys of web development using Python technology?

Here's a quick step by step tutorial to install python and Django on your Windows PC:

  1. Download and install Python
  2. Modify The %PATH% environment variable:
    - Windows Vista & 7  :
    Start --> Control Panel --> System and maintenance --> System --> Advanced system settings --> Environment variables --> System variables --> Path
    -Windows XP :
    Start --> Control Panel --> Performance and maintenance --> System --> Advanced --> Environment variables --> System variables --> Path

    - add C:\Python27;C:\Python27\Lib\site-packages\django\bin to the value of the variable path
  3. Download the latest release of Django download page (Django-1.2.1.tar.gz).
  4. Untar the downloaded file, (You can use a GUI-based tool such as 7-zip)
  5. Open a prompt command and change into the directory created in step 4.
  6. Run the command "python setup.py install"
    django is installed
  7. Install Mysql, the easiest way is to use WampServer2 or XAMPP
  8. Installer pymysql
    see my tutorial here
Everything is now installed! You can start having fun with django: http://www.djangoproject.com/documentation/

Saturday, September 4, 2010

Install MySQL 5 for Python 2.6 (and django) on Windows

I've heard a lot about python and his framework Django, But because i love php i never found the time to test python and honestly i didn't fell the need to do. untill this year (2010)  but the start was not very good. I installed puython django i did some tests. wow  thats amazing, very simple , now  i want to add mysql. I did some researches about mysql connectors i found Mysqldb but there is no binary distribution for Python 2.6 damn it!! thats the version i use.

It took me 4 days looking how to install this Mysqldb to no avail.  i found a lot of sulutions no one is working with me
I tried to build it from the source with many ways to no avail. My environment is Windows XP. MySQL 5.0. Python 2.6 (windows version).

Yesterday i received an email from a friend about another mysql connector named "pymysql" it's very easy to install it in three steps:

Step1:
Install Python setuptools (easy_install.exe) if you haven’t installed it. It is required to install pymysql.
To install setuptools
Download these two files and put them into the same directory:
Open a command prompt in this directory and type "python ez_setup.py setuptools-0.6c9-py2.6.egg"

Add the path where easy_install is installed into your environment PATH ({PYTHON_PATH}\Scripts, {PYTHON_PATH} is the path where python is installed).
Step2: 
Install pymysql, it's easy just donwload the latest version of PyMySQL-0.3-py2.6.egg, put it in a directory and open a command prompt, change to this directory. then  run "easy_install.exe PyMySQL-0.3-py2.6.egg" if it doesn't work try an absolute path of easy-install ({PYTHON_PATH}\Scripts\easy_install.exe PyMySQL-0.3-py2.6.egg)
 Step3:
Now you can test it in python just open the "IDLE(Python GUI)" and run the test below:
>>>import pymysql
>>>conn = pymysql.connect(host='localhost', port=3306, user='root', passwd=None, db='mysql')
>>>cur = conn.cursor()
>>>cur.execute("SELECT Host,User FROM user")
>>>for r in cur:
>>>   print r 
>>>cur.close()
>>>conn.close()
 
Step 4 for django: 
 
To use it with django you need one more step:
go to the django directory, exactly in this directory
{..\PythonPath}\Lib\site-packages\django\db\backends\mysql
and simply do a search and replace of MySQLdb with pymysql
in the two files "base.py" and  "introspection.py"


That's it.

 thanks to mouad for the link and to Pete for this great lib.