Tuesday, December 11, 2012

How to backup and restore a folder in linux shell using tar ?

Let say I wanna back up everything inside the www folder, I go to the folder that contains www folder and I enter:
tar -pczf myBackupfile11Dec2012.tar.gz   www/

What does the -pzf mean ?

       -p, --preserve-permissions
     extract all protection information

       -c, --create
     create a new archive

       -z, --gzip, --ungzip
     filter the archive through gzip

       -f, --file F

How to restore and extract a .tar file in Linux ? 

copy the file to where you want to be extracted

tar xvfz myBackupfile11Dec2012.tar.gz

What does xvfz mean ?

     -x --extract --get

     -v, --verbose

     -f, --file F

     -z, --gzip

Saturday, November 10, 2012

Multiple Domain Names for phpBB3 (same login and cookie )

I had searched everywhere to see if I could have multiple domain names for phpBB a website  multiple with same cookie. without  users getting kicked out after switching the domain name.

I found no solution, even some people on StackOverFlow suggested that it is technically impossible and I should stop searching for it .

The phpBB official documents also said they do not support multiple domain name and there is no solution for that, but I found a phpBB mod that would do the job beautifully !

its called th23 Domain .  This modification allows you to use phpBB across multiple domains (the same forum is accessible via different domains, e.g. via "www.domain.com" and "www.example.de"). 

You can specify sitename and cookie domain to use with your board and the MultiLogin option gives your users the possibility to login to all domains simultaniously. 

Wednesday, November 7, 2012

Key Captcha - The Most Effective Anti-Spam for phpBB3

phpBB is one the oldest and most popular forum software out there,but the biggest problem for it is spam robots . I have tried all the tricks and mods  and spambot countermeasures  for phpBB,  and none of them worked for me .

Even the most sophesticated and most annoying captcha plugins couldn't keep those porn robots away from the forums .

I even tried question-answer plugins, that I made my personal questions and answers , it is very strange those spam robot programmers in india found my answers and added it to their robots , i twas really annoying that I had to make all users posts Pending on my approval .[a very big pain in the neck finding legimate users among 100 porn robot posters]

The Most Effective Anti-Spam for phpBB3 recently I found  Key Captcha which is a free tool and fun and it has been working great for me so far . I am really happy with it . it stops spam for phpBB3

Recently I found  Key Captcha which is a free tool and fun and it has been working great for me so far . I am really happy with it . it stops spam for phpBB3

Monday, October 15, 2012

Solve Chrome's weird behavior for Google Documents page size [bug]

    I used to think Google Drive application is dumb and breaks the pages carelessly, because the PDF version of the documents (or the printed version of them) were never the same with the actual thing I saw on my chrome browser. 

      Today I noticed Google Docs *(1)  works just fine in Firefox and in Chrome for Windows, and it only acts weird on Chrome for Linux. (it has been like this since I have been using Google chrome so it is not matter of version)

     I noticed nobody had reported this bug, I reported the bug with a screenshot hopefully they will solve this issue.

 so if you want your Google documents to print correctly and show the actual page, use firefox**(2) .

* Google Docs or Google Drive Documents. I really liked "Google Docs" name, they should never have changed it to "google drive"

** Firefox is my most trusted browser, it is slower than chrome but I never saw it fail on me. I love you Firefox !

Wednesday, October 10, 2012

How to return time and date in Linux terminal ?

while I was scheduling a script on a server using SSH, I realized every server has its own time zone, that might be different with my time .

Easy way to get time and ate in Linux terminal just enter date :
like this :
root@server [~]# date
Wed Oct 10 19:36:54 CDT 2012
if you want universal time and date:
# date -u
Thu Oct 11 00:39:56 UTC 2012
to get only time  and not date :
# date +"%T"

There are more options like getting the number of the week in the year
# date +"%W"
%H for hour
%m for minute
# date +"%H %m"
19 10
# date +"%H:%m"

For the full list of options read the manual page
man date

Sunday, September 30, 2012

Iterators class example in java

Today I had to use Iterators over a Java List, Java's documentation on Iterator lacks  a good example,here is a  good example about Iterator class.
diagram for iterator class in java

The List and Set collections provide iterators, which are objects that allow going over all the elements of a collection in sequence. The java.util.Iterator interface provides for one-way traversal and java.util.ListIterator provides two-way traversal. Iterator is a replacement for the older Enumeration class which was used before collections were added to Java.

Let say we have an object of ArrayList class name "myList"  . to implement an iterator on a list we should it intialize it on "myList"
Iterator it = myList.iterator();

Iterator methods are :

Returns boolean true or false.
Returns the next object.(with the list's type).
Removes the most recent element that was returned by next.

An iterator might be used as follows:

//initializing a list in Java
ArrayList alist = new ArrayList();

//  Add Strings to alist

for (Iterator it = myList.iterator(); it.hasNext(); ) {
    String s = (String)it.next(); 

Wednesday, September 26, 2012

Microsoft Bing reminds me of beggars in Tehran

    Microsoft Bing reminds me of my undergraduate years in Tehran.  I remember whenever my car was stuck behind a red light in heavy traffic of Tehran, multiple beggars would run to my window and try all new tricks to make me give them some money.  They were actually very smart.  They were not pretending to be poor and asking for money, they were creative in getting your attention...so you had to learn their tricks to not fall into their traps.

    Nowadays Microsoft’s Bing tries to sneak into my computer.  Anytime I install anything I have to make sure Bing has not changed my browser's default search engine, or by sneaked into my router DNS, or attached itself as a free tool with other applications such as facebook!

   Dear Microsoft...I noticed that you have worked hard to make your search engine better, but I just don't wanna switch from Google!  If I want to use Bing, I will let you know, please leave me alone!

Tuesday, September 25, 2012

Difference of "Hosted AdSense for Content" and "AdSense for Content"

I love Google. I think they are great at their job, but there is something which Google is not very good at...naming its products or choosing the right word for their features.

I think lots of Google's products didn't make it to the mainstream just because of their stupid names.
For instance: Orkut, iGoogle, Goolge mini, Google Play ,Google Plus,Google Adsense, Google Site...

Today I was checking out the Google Adsense control panel and I saw this:

After lots of research in forums, I found out "Hosted Adsense for Content" means Youtube ads and "Adsense for content" means actual ads on your site/blog.  Who is in charge of choosing the names in Google?!  

Sunday, September 23, 2012

How to add custom icon for specific application in a unity ubuntu 12.04

I installed a new icon theme for ubuntu 12.04 using "My Unity" i found a very beautiful theme named Breathe, the only problem is it doesn't show an icon for one of my favorite applications (PulseAudio Equalizer) and its icon in unity  shows as a folder icon . (which very annoying)
Here is how to add a custom icon for a specific application in ubuntu 12.04 Unity (hopefully works for all previous unity verions)

First: Find an icon

Fir we need to find an icon for your icon-less application, you can do one of the following:

  1. Steal from another icon theme set
    the location of icon images for icon themes are like this : (Humanity is the name of the icon theme set) :
  2. Search in google images or in flicker
  3. Take a screenshot of the application (my favorite)
  • Run the application
  • Make sure it is the active window
  • Press alt+print , you will have something like this:

Second: Set the icon

1- Open a root nautilus
sudo nautilus
2- Go to
3- find your application's name in my case (PulseAudio Equalizer), right click and click on properties

4- click on the current icon
5- change it to the image that you found in Step 1 .

now you will see your custom icon for the application that was missing icon file for your icon theme.

Thursday, September 20, 2012

How to see what is on line number # in Linux?

Quick terminal tip:

Sometimes you get errors in compiling a program and it complains something is going on in line number something , let say line number 139   if you want to see what is on the line number 139, in file myProgram.c

tail --lines=+139 myProgram.c

This really saves time, (imagine each time opening a text editor and trying to find line number something, thats a pain in the neck!)

Saturday, September 15, 2012

Useful Chrome Extension : Save chrome tabs and state without hibernation

Today I wanna share with you one of my most favorite extentions for google chrome, Seassion Buddy, which lets say you save the state of your chrome tabs and windows, with a single click and name it and restore it anytime later very fast anytime.

So it feels like you hibernated your computer, except it is extremely fast and also you can save the state and then close and use chrome again.

One of the use cases of session buddy for me is, to save links about each lecture for my courses at school.

Let say I study I have a course "concepts of programming languages" for each lecture I open lots of links in wikipedia and other sites, I used to print all my links and lable them in each folder "lecture one material" and store them (tons of paper very hard to search though them) but now I just use "Session Buddy" to save each lecture's links and name it "session for lecture 1 Course CSC447". it makes reviewing for midterm and final exam a

Sunday, September 9, 2012

How to return current URL without args & queries in PHP?

Today I needed to find out how to return the URL of current page without queries and variables and here is what I learnt:

The difference of URL  and URI in php  .

Example Let say this address:  http:://shevin.info/blog/album.php?album_id=2

will return /album.php?album_id=2


will return /album.php

$_SERVER['REQUEST_URL'] returns no queries or arguments or variables or strings attached .

A Suggestion For Google Plus (Max page show in stream )

Google Plus has lots of new features that are totaly new in social world and I like it,
here is an idea for G+ that I came up with :

We should be able to limit the maximum number of posts of a page (that we fallow) in Google+ stream page.

for example I the "wisdom" page, but they show up just too many times in my steam page, I don't want to mute this page but I rather be able to make it show in my stream page every often. I would like to have a set of rules for diffrent set of pages ,for example  here is how I would define my stream page.

"Funny pages"  (maximum 3 times in a row) or (max 3 times out of 10 posts)
"Computer-related pages"   (maximum 10 times in a row) or (max 3 times out of 10 posts)
"Philosophy " (maximum 1 times in a row) ...

I wouldn't be surprise if I see that Google is already working on this feature, because so far any feature idea that came up to me a few months or years later Google implemnted it. that's why I love Google, we feel the same for the features that should be added to Google products.

Wednesday, September 5, 2012

How to use PHP code in phpBB template?

phpBB is a popular free open source forum software, by default for the security measures , they have disabled using PHP code inside the template and you are limitted jsut for a few phpBB tags and syntax for controlling the phpBB conditions:

here is how you can override this security measurement:
if you are sure that nobody is gonna put any malcious php code into your template , do this :
Go to ACP (adminstractip control panel) ,
Go to General
On the left choose Security
now find  Allow php

another important thing to do is now

Instead of normal php syntax in html which is
you have to use

echo "Hello World!"; 

for example here is a code to return the current page in php to put in phpBB template.

echo "Hello World!";
$currentpage = $_SERVER['REQUEST_URI'];

Friday, August 31, 2012

My opinion on Apple-Samsung + a suggestion for apple

what do I think about Apple versus Samsung argument ?
well this is the picture that apple showed to the court

I am not a big fan of samsung, I had a couple of their devices and they turned me down, (once the $300 phone's camera stopped working right after purchase without any warranty , hard disk stopped working and lost all my data and I personally I find them very crappy and low quality ... )

And I think Samsung did copy Apple's iphone shamelessly  but is what Apple doing a nice thing by chasing them and making them pay 1 billion dollar ?

Apple is already the biggest company in the world, they already have lots and lots of money. I think they are being greedy now , why do they need to do anything to destroy their image ?

This is gonna start a sue game between apple and other companies, Apple itself copied lots of things from small companies , but those poor companies are either too small to be able to fight apple or they just don't care or they are generous or they are open source and they are actualy happy that their idea is used in a product to serve society and technology.

Taking into consideration that apple is already richest company in the world, Apple should not show anger that inspired other companies products, it should just be happy and shut up !

P.S1 : Samsung paying apple $1 billion in 5 cent coin no matter true or fake was so funny .
P.S2:  I suggest Apple donate that $1 billion to fund open source projects, I think that way everyone would be happier, and Apple wouldnt look like a greedy money sucking rich man !

Friday, August 10, 2012

Why I don't use netflix?

I have been a linux user since 2005 and nothing ever made me think to switched back to windows since then.

lots of my friends use netflix and I get jealous sometimes, I wanna get a netflix account too but the sad part is, they do NOT support linux or firefox, you have to have a Windows with Internet Explorer (omg I can not even imagine me using IE again ...NEVER)

so even though I like to have netflix but I am not gonna go back to windows just to watch some movies.

there are some posts over internet like how to make moonlight work with netflix, but they simply don't work all of them eventually suggest you to buy a Xbox or something like that.

but there is a petition that you can sign online, may be netflix will listen ?'

one of the devices that work with Netflix is called roku it is cheap ,  so if you really want netflix you might want to buy that .

Friday, August 3, 2012

How to find a piece of code in a folder of files ?

sometimes while debugging a code or editing a template you need to find a pattern of text in many files, how frasutrating it would be if you open all of them and do "Ctrl+F" in your text editor ?

here is how you do it correctly :

let say I am searching for 'Recent Topics' in a folder named phpBB in my Desktop.
First of all open a terminal. (ctrl+alt+t)
cd Desktop  ( ofcouse :p )
cd phpBB 
grep -r 'Recent Topics' *
-r is gonna do a recursive search in the current folder and all sub folders and search for Recent Topics

if you wanna ignore casesentivity you add -i
grep -r 'Recent Topics' *

Tuesday, May 15, 2012

How to Make Linux Prompt in Terminal Shorter ?

Sometimes when going inside too many folders in terminal , the linux prompt gets too long and it is annoying specially when you are developing an application or coding something in terminal :

For example let say this is how your terminal looks like after going inside too many directories .

To make it shorter in a nice way  enter the following in the command line :
PS1="[\W]\\$ "
Now your prompt will look like this : (only showing the directory you are in)
If you want to see the full path you can enter pwd anytime

[hello_world_project]$ pwd
if you don't like the new look of terminal promot , don't worry these changes will be gone if you close this terminal and open a new one, however if you want to make it permanent (but I personally like it temproary only when I need it)

You can play with the PS1 and add your username to the prompt
for example:
PS1="[\u@\W]\\$ "
will give you your username @ the currentfolder

If you want to master PS1 , PS2, PS3, PS4 in Linux Prompt you can read this article

Sunday, May 13, 2012

How to read integer from file and put in a list in Python

one of the classic practical examples in every programming language is reading a file which has multiple numbers at each line and you need to read them and put them in an array or list .

let say I have a text file containing X,Y integers like this :
5 4
6 2
4 3
3 1
3 6
1 2
2 3

and I want to read them from the file put them in a list (x,y)

Here is step by step example code in python  to read integers from file:
1- we need to open the file in read only mode
    f = open(filename,"r")

2- Initialize a list to put our numbers in it
3- in this part , we read every line in the file and cast it into integer ,
split() function divides the words that have a space in a line so we can read it one by one
if we our text was like
we could use line.split(',')
but in this case line.split() works for us
int(s) converts the type of elements in line into integer and put them in two different variable name x and y
and then we append x,y into points list
    for line in f:
        x, y = (int(s) for s in line.split())

4- in the end I close the file
The full code in python :
def readfromfile(filename):
    for line in f:
        x,y = (int(s) for s in line.split())
    return points

 here is how it looks like when you run it
>> readfromfile('case4.txt')
[(5, 4), (6, 2), (4, 3), (3, 1), (3, 6), (1, 2), (2, 3)]

Sunday, May 6, 2012

How to Install GIMP 2.8 in ubuntu 12.04 ? (without dpkg-deb error)

To upgrade Gimp 2.6 to Single-Window mode Gimp 2.8 on ubuntu 12.04 do the following steps otherwise you would break the package manager and you would get this error :
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:

0- If you allready broke the package manager and you get the error do the following :
sudo apt-get remove gimp-plugin-registry
sudo dpkg --purge gimp gimp-plugin-registry
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove -f

1- First remove GIMP Plugin Registry :
sudo apt-get remove gimp-plugin-registry

2- Add the GIMP PPA and install it
sudo add-apt-repository ppa:otto-kesselgulasch/gimp
sudo apt-get update
sudo apt-get install gimp
3-   Do a partial upgrade
sudo apt-get dist-upgrade 

4- To enable Single-window mode :
Open Gimp
Go to Window Menu
Click on Single-Window mode

Thursday, May 3, 2012

[How to fix] Dual Monitor Freeze in Ubuntu 12.04 64bit

one of the features that ubuntu 12.04 promised was better support for dual-monitor however after I upgraded from ubuntu 11.10  to ubuntu 12.04 I noticed if I change the display settings it will freeze for example I noticed:

- I  move the external monitor to the left of laptop monitor , (or above it) it freezes
- I try to turn of the laptop monitor ,so I only have my external monitor it will freeze again. the mouse and keyboard stop responding and the only way key that respond is
 ALT+PRINTSCREEN+K (to restart the X server)

I openned a bug in Launchpad and I tried every possible solution  after pulling my hair and not sleeping in the whole night .Here is how I fixed it : To fix dual monitor freeze in ubuntu 12.04 you need to install the older version of  xserver-xorg-input-evdev

1- Download the following two packages to your desktop:
xserver-xorg-input-evdev-udeb_2.6.99.901-1ubuntu3~lp921236_amd64.udeb (24.0 KiB)
xserver-xorg-input-evdev_2.6.99.901-1ubuntu3~lp921236_amd64.deb (38.0 KiB)
2- Open a terminal
cd Desktop
sudo dpkg -i *.deb
3- Restart your computer or if you are lazy just restart the X Server (ALT+PRINTSCREEN +K)

Sunday, January 15, 2012

What happened to "ALT+BACKSPACE" in Ubuntu ?
How to restart Xorg ?

We all know old friend  alt+backspace which forced the XORG to be restarted when the computer screen was frozen .
and also the other old friend CTRL+ALT+DELETE , which is also disabled .

  What happened to Alt+Backspace in Ubuntu 11.10 ? (How to restart the X in ubuntu)
in pervious versions of Ubuntu (and other Gnome-based linuxes) , whenever the X crashed (the graphical window system manager) we would hit Alt+Backspace and the X would be restarted .

However , in the new versions of ubuntu, alt+backspace  doesn't work anymore and it been replaced by Alt+Printscreen+K
which is better . why ? because ALT+Printscreent+K combination could be caught by Kernel when the whole X is totaly gone, (remember those times that Alt-backspace wouldn't work ? it was because it was totaly gone , but now Alt Print Screen would be sent to Kernel which is better idea) 

Another explaintion of this change is, nowadays lots of applications use ALT+something as short cut and it would lead to restart the X by accident and possible data loss .

What happened to CTRL+ALT+DELETE , How to call System Monitor  or Kill a process or Log out in Ubuntu 11.10?
The CTRL+ALT+DELETE has been replaced by "CTRL+ALT+BACKSPACE" .
which it simply calls system monitor , so you could see the Ram usage and also the processes and kill them or End them or Map their memory usage .

Saturday, January 14, 2012

How to handle space in file name in any Linux terminal

Today I wanted to mount My Passport External Hard disk and it reminded me of how I used to be nevrous whenever I wanted to do any operation (copy/move/delete...) on any file or folder with blank Space character in its name in the terminal , (we dont have this problem in graphical file managers)

Lets learn once forever , how to treat it here is the simple rule :

Whenever you see the space in the name you just replace it with "\ " without Qouation Marks .
for example this will NOT work in terminal
cd /media/My Passport
because it has an space in it , to make it work I add "\ " for each space but the following will work

cd /media/My\ Passport
and it works , I promise .

Tuesday, January 10, 2012

How to install Python 2.7 in Ubuntu 11.10

I am taking Crypyology this quarter with Professor Schaefer and he uses python in the class , I installed Python 2.7 on ubuntu 11.10 64bit , installing it is easy as other apps , just the step 3 is a bit different.

1- Download the Python 2.7 source code and Extract it do the Desktop

2- Do the things that we do for all other compiles

cd Desktop
cd Python-2.7

3- This is the important part it is altinstall not install !
sudo make altinstall

4- Test it
medya@medya:~/Desktop$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hi shevin"
hi shevin



computer (48) ubuntu (46) linux (28) tutorial (20) opinion (17) programming (14) software overview (13) terminal (12) troubleshooting (8) life (7) literature (7) poem (7) human languages (6) vim (6) bash (5) google (5) python (5) android (4) cars (4) phpBB (4) suggestion (4) tips (4) 12.04 (3) Chef (3) extension and addons (3) firefox (3) java (3) personal (3) russian (3) shell (3) windows (3) 64bit (2) Calligraphy (2) Chicago (2) Vagrant (2) apple (2) backup (2) bug (2) code (2) eclipse (2) funny (2) google chrome (2) idea (2) monitor (2) php (2) phpBB3 (2) shorter prompt (2) ssh (2) virtualbox (2) $_SERVER['REQUEST_URI'] (1) 2.7 (1) ALT+Backspace (1) AVR (1) Alt-Printscreen-K (1) AutoRotate (1) CTRL+ALT+DELETE (1) DRM (1) Debugging (1) Gimp (1) Gimp 2.8 (1) Microcontroler (1) Restart X (1) UML (1) Ventra (1) adsense (1) amazon (1) audio (1) aws (1) background process (1) battery (1) bing (1) blank (1) blogging (1) bmw (1) boot (1) business review (1) car (1) cd (1) chrome (1) comcast (1) computer kubuntu (1) conference (1) cookie (1) cron (1) database (1) date (1) display (1) domain name (1) download manager (1) dual boot (1) dual monitor (1) extensions (1) feature request (1) file (1) folder (1) freeze (1) gimp single window (1) git (1) gnome 3.10 (1) google docs (1) google plust (1) google+ (1) grep (1) icon (1) install (1) iterator (1) links (1) linu (1) linux links (1) list (1) mac os (1) media server (1) microsoft (1) moonlight (1) music (1) mysql (1) name (1) nautilus (1) netflix (1) notepad++ (1) parking (1) permission (1) philosophy (1) photo (1) prompt (1) protest (1) ps3mediaserver (1) putty (1) read from file (1) realtek (1) resolution (1) roku (1) samsung (1) scala (1) screenshot (1) security (1) selinux (1) server (1) skype (1) space (1) spam (1) spambot (1) sql (1) suspension (1) system monitor (1) tar (1) task manager (1) template design (1) th23 domain (1) thinking (1) ubuntu 13.10 (1) unity (1) vimrc (1) virtual machine (1) weblogic (1) wget (1) with space (1) xorg (1) xrand (1)