Thursday, 8 January 2015

Python Basic Data Types

There are  very useful samples from here

Numeric operation

  • When integers are divided, integer division is used, discarding the fractional part. When at least one of the input numbers is floating point, floating division is done preserving the factional part.
  • The print operation automatically adds spaces between the items which is prints, and places a newline at the end.
  • The multiple assignment computes all values on the right before assigning anything, an extension of the usual rules for a single assignment. 
  • Lines to be continued by putting a backslash at the end of the first part or the line break in contained in a grouping pair.

About Strings
  • Quotes are used for create strings.
  • Triple quotes create multi-line strings.
  • String literals may be concatinated by a space.
  • Any string expression may be concatinated by a + (Java style).
  • String length can be obtained by function len(string)
  • String with backslash can be combined for different escapes, like '\n' is new line.
  • Raw string starts with r.

String operations

  • String can be treated as an array with characters and index starts with 0.
  • Use brackets to extract substrings, like string[1], string[0:5], string[:5], string[8:].
  • The last character is not part of the range.
  • The '*' operator repeats strings.
  • Negatives index back from the right.
About List
  • List is defined within a bracket and separated with coma.
  • List also can be extracted by using the same way as presenting the string characters. The ranges can be called as 'slice'.
  • Individual items in the list can be replaced. Slice also can be replaced and size of list can be changed due to the replacement.
  • Sublist is allowed, which means lists in a list.








Wednesday, 3 December 2014

Python to start

Good news.

Python 2 and python 3 are not compatible. Therefore it is better to start with python 3. Under Ubuntu I start python by python3 and then I get into the interactive mode. Not useful at all.

How to start coding? I need an IDE. To install one for python3, apt-get install idle-python3.4 and it installs.

The first line of the code starts with
#!/path python

Should I start?

Django where to start

Ubuntu 14.04 has python 2.7 and python 3.4 installed.

To install Django with python3, we need pip3. Use command

sudo apt-get install python3-pip

Then install django

pip3 install django

Still a bit confused. Will try it later.





Wednesday, 22 October 2014

Get MD5 hash of a string

echo -n string | md5sum

MySQL database backup and restore

Backup commandline

mysqldump -u root -p dbtobackup >dbtobackup.sql

Restore commandline

  • Log into mysql
  • Create database
  • Use database
  • Source dbtorestore.sql

Wednesday, 8 October 2014

Restart the posts again. Hopefully I can keep on doing it.

Monday, 16 January 2012

php not display under public_html

First of all make the apache server with qualified domain name.

1. Enable UserDir module.

2. Edit /etc/apache2/httpd.conf

AddType application/x-httpd-php .php

# Use for PHP 5.x:
#LoadModule php5_module modules/libphp5.so
AddHandler php5-script php

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php

AddType text/html php

3. Add following at the end of /etc/apache2/apache2.conf

Include /etc/apache2/sites-enabled/
AddType application/x-httpd-php .php
UserDir /home/*/public_html