Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

2010-07-27

xrandr: Configure crtc 0 failed

If you get problem:
xrandr: Configure crtc 0 failed
Create xorg.conf for NVidia graphics card:
nvidia-xconfig --add-argb-glx-visuals -d 24
Change your xorg.conf by running:
nvidia-settings
You can also add to xorg.conf manually following line to
Section "Screen"
Option AddARGBGLXVisuals" "True"
And then add to
SubSection "Display"
your preffered resolution, e.g. 1920x1080:
Modes "1920x1080" "1600x1200" "1280x1024" "1024x768" "800x600" "640x480"
There you can select your native monitor mode.

Resource: LinuxMint

2009-01-29

Vim - basics - copy-paste

Useful shortcuts for Vim beginners: 

mark text 
v ... start highlighting text 
+y ... end highlighting text 

d ... cut 
P ... P-paste above cursor (capital P)
p ... paste below 

u ... undo 
Ctrl+R ... redo 
source: source web 
other: other web 
Vim macro for copy-paste with Ctrl+C and Ctrl+W: abclinuxu.cz (Czech version)

VI shourtcuts:

Go to
Shift g    = end of file
gg    = start beginning of file
GG    = start of file
:22    = go to line 22
0 = start of line
^ = first letter on line
$ = end of line

Delete 
x = delete
X = backspace
dw = delete word
d$ = delete to EOL $
d0 = delete to start 0

Copy to buffer
:t.    = duplicate line
:t7 = copy line after line 7

yy = copy current line
ayy = copy current line to buffer a
a5yy = copy 5 lines into buffer a

Paste from buffer
y7yp = copy and paste 7 lines
p = paste line
ap = paste buffer a at the cursor


Search
n = search next
N = search previous
* = go to next occurrence of word under cursor
# = go to previous occurence

Less shortcuts

NoHup
# Nohup process id pid :
nohup my_command > my.log 2>&1 &
echo $! > save_pid.txt

2009-01-12

No sound in Flash under Linux

Problem description:
Using Debian or Ubuntu Linux, I experienced problem with no sound
using Flash player in Firefox.

Solution:
# apt-get install alsa-oss

Details:
alsa-oss package creates interface between Alsa sound libraries and OSS libraries. Latest systems usually support Alsa drivers while Flash requires OSS. This package interconnects both of them to play together.

2008-11-11

Faster scp with tar

scp using tar:

Following sequence retrieves data from remote server immediately without need to store compressed tar to file.

ssh root@server tar -c /www/domain.com | tar -x

Following sequence sends local data via ssh to the remote server.

tar -c /www/domain.com | \
ssh root@server cd /www/domain.com '&&' tar -x


Bash - functions, timestamp, date diff

Bash function - command line calculator
calcfn () { echo "$*" | bc -l; }

Bash timestamp of specific date
date +%s -d 20070103

Date difference in Bash
dateOfPast='20080103'
today=`date +%Y%m%d`
timeStampToday=`date +%s -d $today`
timeStampOfPast=`date +%s -d $dateOfPast`
secondsInDay=86400
dayDiff=`echo \($timeStampToday - $timeStampOfPast\) / $secondsInDay | bc`
echo $dayDiff

Convert Unix timestamp to local date time
echo $timeStamp | perl -n -e 'chop; print localtime( ($_)[0] ) . "\n";'

Convert Unix timestamp to GMT
echo 1234567890 | perl -n -e 'chop; print gmtime( ($_)[0] ) . "\n";'
Unix Timestamp
1234567890 ... Friday The 13th.

2008-11-10

Vim - File Differences with vimdiff

Brief usage of vimdiff. For detailed description see man, info and online docs.

Start vim in diff mode
vimdiff file1.php file1.php~

Alternatives:
gvimdiff
vimdiff -O ==horizontal windows
vim -d

Switch between windows
Ctrl+w Ctrl+w

Put new lines to other window
dp

Obtain new lines (from another window)
do

Skip between diff groups
previous group
[c

next group
]c

(Un)folding
open folded difference
zo

close folded diff
zc

Source: vimdoc

2008-10-12

Automated build with Autotools

Automake, Autoconf, Libtool - simply Autotools...

Quick way to start autotools

Programmer's command sequence:

autoscan
autoreconf --install --force
./configure
make clean


install
builds the configuration scripts by calling the sequence of particular autotools commands. The advantage is that we do not have to remember the whole sequence
and we do it in one simple command.

force forces the autoreconf to rebuild the configuration even if it already exists.

make clean cleans up build environment

The autoreconf command supplies following sequence
libtoolize --force
aclocal
automake --foreign --add-missing
autoconf


User's command sequence:

./configure --prefix=/usr/local
make
make check # not neccessary, just a test
DESTDIR=/tmp/package make install

Resources:
AutoBook book for Auto* Libtool, Gettext, ... (latest)
AutoTools for beginners - quick intro
Wikipedia: GNU build system - short description

2008-09-27

Processing mail with procmail

Sometimes I change my procmail rules and I want to force procmail to process my inbox again with these new rules. The inbox is usually in mbox format, therefore I have to split it to particular emails.

In this case I use formail which splits inbox to particular messages and calls specified program to serve each message independently.

Process allready received mail with procmail rules again:
formail -s procmail < $MAIL

2008-08-15

Mixed notes

Python lacks good XML support in standard distribution. I found a list of Python XML libraries comparison:
http://www.somebits.com/weblog/tech/python/xpath.html

It is possible to convert DOM to dictionary records with following functions:
http://code.activestate.com/recipes/116539/

or use module xml2dict:
http://code.google.com/p/xml2dict/

Sometimes I do ssh to some development machine which I am not quite familiar with. I usualy want to detect Linux distribution and version. The following description is very helpful:
http://www.novell.com/coolsolutions/feature/11251.html

Czech trafic navigator:
http://www.dopravniinfo.cz/default.aspx

Python date and time manipulation:
http://seehuhn.de/pages/pdate

2008-08-14

Dancing in Samba rhythm

Sometimes I want to use Samba as fast as possible. Unfortunately there may occur unexpected problems during user authentication. Following sequence of commands solves many of them:

smbpasswd user_name
pdbedit -a user_name

In other words, adding user and setting up password may not have been enough, we need to add him/her to user database.

Mount:
sudo mount -t cifs //netbiosname/sharename /media/sharename

Options:
-o \
username=winusername, \
password=winpassword, \
iocharset=utf8, \
file_mode=0777, \
dir_mode=0777 \

Or:
guest, \
rw

2008-08-11

Debian X Fonts

How to install nice X fonts in Debian quick and easily?

In the root console exec command:
apt-get install msttcorefonts

If the following error occur:
E: Couldn't find package msttcorefonts

you should add "contrib" section to your /etc/apt/sources.list:
deb http://ftp.us.debian.org/debian etch main contrib non-free

and then execute - as usually:
apt-get update

and do again:
apt-get install msttcorefonts

Then select these fonts as default.

If you use KDE open Control Center then select:
Appearance & Themes then Fonts. In the right dialog select default fonts for each font type.

Appropriate font names are: Times, Arial, Courier, Courier New, Courier 10 Pitch, Lucida Typewriter

Done. Note that font settings take effect after restart of each application. You also have to select fonts for specific applications such as Firefox, Thunderbird, Kwrite, etc.

2008-07-18

Starting with MySQL

All the beginning are terrible and slow... again and again looking into the manual for the same commands.

Install
apt-get install mysql-client mysql-server mysql-common php5-mysql

Set root password
mysqladmin password 'new_root_password'

Login to DB
mysql -u root -p

Create database
CREATE DATABASE db_name;

Create regular user and grant appropriate rights
SELECT PASSWORD('secret_password');
CREATE USER user_name IDENTIFIED BY 'secret_password';
GRANT ALL ON db_name.* TO 'user_name'@'host_name' IDENTIFIED BY 'secret_password';
^D

Login under the regular user
mysql -u user_name -p db_name

Create table
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
created_date DATETIME,
name VARCHAR(200),
phone VARCHAR(200)
);

Create index
CREATE INDEX index_users_name ON users (name);
details

2008-07-10

Xlib: connection refused by server

Trying run under root:
su
swscanner
I received following error message:
Xlib: connection to ":0.0" refused by server

Easy solution, run under regular user:
xhost +localhost
OR:
xhost local:root

Then run under root:
export XAUTHORITY=/home/regular_user_name/.Xauthority

Where
regular_user_name is name of the user doing command su.


2008-07-07

Acer TravelMate 5720 - video drivers

How To install video drivers to Acer TravelMate 5720 (thanks to Miro):
Proprietary binary drivers for Debian:
apt-get install fglrx-driver fglrx-driver-dev fglrx-control fglrx-kernel-src
cd /usr/src/
tar -xjvf fglrx.tar.bz2
cd modules/
./make.sh
mkdir -p /lib/modules/`uname -r`/misc
cp fglrx.ko /lib/modules/`uname -r`/misc/
depmod -ae

Oracle DB server notes

Oracle Error:
Warning: ocifetch(): OCIFetch: ORA-24374: define not done before fetch or execute and fetch in /home/martin/dev/www/inc/ora_funct.php on line 15

Reason and solution:

sometimes wrong syntax but mostly missing access rights to accessed table. You can solve this problem by granting sufficient rights to the user which is accessing the table.

Oracle sql date comparison:
SELECT column
FROM table
WHERE start_date <= TO_DATE('20080401', 'yyyy-mm-dd');

2008-06-24

Spelling with ispell and related tasks

Change default ispell dictionary:
dpkg-reconfigure ispell
or:
select-default-ispell

Using ispell by non-interactive way:
echo string | ispell -a | grep -v 'Ispell version' | grep -v '^

Optionaly we can define another dictionary:
ispell -d dictionary_name

We can choose the dictionary from istalled files:
ls /usr/lib/ispell/*.hash | sed 's/.*\///' | sed 's/.hash//'

One kind of errrors while using xargs:
xargs: unmatched double quote
OR:
xargs: unmatched single quote
Solution:
find . -type f -print | xargs grep pattern

I experienced error message while using iconv:
iconv illegal input sequence at position 0
Solution:
ispell --null

Converting UTF8 to 7bit ASCII:
iconv -f UTF-8 -t ASCII//TRANSLIT < input.txt > output.txt