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 .

medya@medya-Satellite-P745:~/Dropbox/SchoolWorks12/Workspace/hello_world_project$
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)
[hello_world_project]$
If you want to see the full path you can enter pwd anytime

[hello_world_project]$ pwd
/home/medya/Dropbox/SchoolWorks12/Workspace/hello_world_project
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
[medya@hello_world_project]$

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
    points=[]
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
5,4
6,2
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())
        points.append((x,y))

4- in the end I close the file
   f.close()
The full code in python :
def readfromfile(filename):
    f=open(filename,"r")
    points=[]
    for line in f:
        x,y = (int(s) for s in line.split())
        points.append((x,y))
    f.close()
    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:
 /var/cache/apt/archives/gimp_2.8.0-1ubuntu0ppa3~precise_amd64.deb

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)


Related

Labels

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)