Salı, Ekim 21, 2008

Sed wisdom

cat yop2.sql | sed -e "s/\([0-9]\),\([0-9]\)/\1.\2/g"  > yop3.sql
To turn commas into dots on numbers like "343,123" I have the previuos sed statement. Thanks sed!

Pazartesi, Eylül 22, 2008

IE bugs makes life unbearable

CSS is a nice technology when everybody adapts it correctly. Unfortunately some browser(s) like IE doesnt follow W3Cs recommendations and standarts making our lives miserable. I have done an html page with CSS which seems perfect on Firefox,Opera etc. But when it comes to IE it fails to be sown correctly. After some search I learned that IE has also a bug about floats which is called "3px float bug" . To solve it for my case
I changed a "width" attribute to a "max-width".
Also I used  png images with a hope for  transparency. But I learned after searc again that IE 6.0 is not capable of png transparency which is added to IE7.0 version. This is IE and life of a web programmer.

Perşembe, Eylül 18, 2008

Mambo change 2

A new problem with com_events and mysql 5.0
DB function failed with error number 1054
Unknown column
'a.checked_out' in 'on clause' SQL=SELECT a.*, cc.name AS category,
u.name AS editor, g.name AS groupname FROM jos_events AS a,
jos_categories AS cc LEFT JOIN jos_users AS u ON u.id = a.checked_out
LEFT JOIN jos_groups AS g ON g.id = a.access WHERE a.catid=cc.id ORDER
BY a.catid LIMIT 0,30
And the solution:
This query is the one that fails, and appears around line 226. This
is the fixed version and has had brackets added in line 227 in the FROM
clause, like so-
Code:
   $database->setQuery( "SELECT a.*, cc.name AS category, u.name AS editor, g.name AS groupname"
      . "\nFROM (#__events AS a, #__categories AS cc)"
      . "\nLEFT JOIN #__users AS u ON u.id = a.checked_out"
      . "\nLEFT JOIN #__groups AS g ON g.id = a.access"
      . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "")
      . "\nORDER BY a.catid"
      //. "\nAND a.state ASC"
      . "\nLIMIT $limitstart,$limit"
   );

Salı, Temmuz 29, 2008

Mambo Change

administrator/components/com_content/admin.content.php
line 195 is changed according to sayings on the page
http://forum.mamboserver.com/showthread.php?t=65497

old: . "\n FROM , #__content AS c, #__categories AS cc, #__sections AS s"

new: . "\n FROM #__categories AS cc, #__sections AS s, #__content AS c "
Now com_content is working

Cuma, Temmuz 25, 2008

Change locale

Too simple
export LC_CTYPE=ISO-8859-9

Perşembe, Temmuz 17, 2008

I love this game

Mysql to mysql backup through secured mysql connection between two ends.
The situation is this:
I have two mysql servers behind two modems. Only port 22 is open on modems.
Ports 3306 are open on both servers. First port forward on the server which is going to be backed up by
ssh -L 23306:127.0.0.1:3306 user@remoteserver(backupserver)
Then
mysqldump -t -u localuser -p db | mysql -v --host=127.0.0.1 --port=23306 -u remoteuser -p -C db
makes the magic.
By mysqldump we dump the mysqlserver which is going to be backed up. And point it to the local (forwarded) port 23306 and everything is written to the remote host.
Wow.
BTW, to connect to backup server from local we need this
mysql --host=127.0.0.1 --port=23306
thing.

Çarşamba, Temmuz 09, 2008

Incognito

Incognito is a live cd which makes you invisible on the web.
It uses tor to make you anonym.
It has even virtualisation support.
Take a look at here
http://www.browseanonymouslyanywhere.com/incognito/index.php

DSL (Embedded)

DamnSmallLinux is a cool stuff. It is very small and efficient.
You can put it on a cd (ofcourse), usb flash or even a floppy disk.
It has virtual images to be used with virtualisation.
It even works from *inside* Windows with a magic(QEMU).
http://www.damnsmalllinux.org/

Nfs cdrom share

It is nice to share cd/dvdroms by nfs especially when installing a distro to a non-cdromed box.
From OpenBSD faq:
<br />/mnt/cdrom -alldirs -ro -network=10.0.0 -mask=255.255.255.0<br /></pre>Remember: If you make changes to /etc/exports while NFS is already running, you need to make mountd aware of this! Just HUP mountd and the changes will take affect.  <blockquote><pre># <b>kill -HUP `cat /var/run/mountd.pid`</b><br /><br />http://www.openbsd.org/faq/faq6.html<br />

Perşembe, Temmuz 03, 2008

Burn cd image to a dvd

Sounds strange but useful sometimes.

growisofs -dvd-compat -Z /dev/dvd=cdimage.iso

That's it.

Çarşamba, Mayıs 07, 2008

Text Processing with Awk

Awk is a powerful unix utility.
$ awk -F":" '{ print "username: " $1 "\t\tuid:" $3" }' /etc/passwd
-F=Field Seperator
$1=first field seperated by ":"

Awk can use a program which is a file with awk instructions.
$ awk -f program.awk inputfile

A sample awk program file program.awk is as follows:
1- BEGIN {
2- FS=":"
3- x=0
4- }
5- { print $1 }
6- $1 ~ /regex/ { x++}
7- END {
8- print x
9- }

BEGIN is the place for commands to be executed before inputfile
is being processed. Here we set FS(field seperator) to : and
initiate variable x to 0.
Line 5 prints all matching 1st columns.
In Line 6 if $1 is similar to /regex/ then variable x is raised by 1.
At the END after processing input file variable x is printed to output.
FS,RS(Record Seperator),OFS(Output Field Seperator),ORS and
NF(Number of Fields) are other special variables in awk.
Reference: http://www.ibm.com/developerworks/linux/library/l-awk3.html

Perşembe, Mayıs 01, 2008

Curl and Wget For Proxying

Curl has many proxy options.Simply
curl -x proxyhost:port -U proxyuser(if any) www.example.com
It has also socks proxy support which wget doesnt
curl --socks5 127.0.0.1:9999 www.example.com

When it comes to wget
http_proxy = http://proxyhost:port/
use_proxy = on
wait = 15
suchsettings on .wgetrc makes it work with the proxy.

Regex help

Regex 11 metachars: [,?,*,$,^,\,.,+,(,),|
Character classes : [A-Z] matches a single character in range A-Z.
[^A-Z] matches a character that is not in between A and Z.
Metachars in a chearcter class are : [,\,^.- and need to be escaped by \ when try to match themselves.

Cuma, Mart 21, 2008

Grubi duzeltme



GRUB acilis yoneticiniz herhangi bir nedenden oturu hasar gorduyse
(ornegin; diskin bir bolumunde Linux varken bos bir bolume Windows
kurdugunuzda acilis yoneticiniz buyuk olasilikla size Linux 'unuzu
gostermeyecektir) herhangi bir Linux dagitiminin LiveCD 'sini sisteme
takin ve LiveCD 'deki Linux acildiktan sonra bir terminalde asagidaki
komutlari calistirin:



# grub

grub > root (hd0, X)

grub > setup (hd0)

quit

#



X: Linux bolumunuzun bulundugu disk bolumudur ve 1, 2, 3 gibi bir tam sayidir.
http://ipucu.enderunix.org/view.php?id=1875

Salı, Mart 18, 2008

Writing Unicode Characters in Python

Unicode files and Python



Reading and writing Unicode files from Python is simple. Use
codecs.open() and specify the encoding.



  import codecs
# Open a UTF-8 file in read mode
infile = codecs.open("infile.txt", "r", "utf-8")
# Read its contents as one large Unicode string.
text = infile.read()
# Close the file.
infile.close()

http://www.jorendorff.com/articles/unicode/python.html

Python UnicodeDecode

If you get an error like this
&gt;&gt; bytestring = '\xc3\xa4'     # Uuh, some non-ASCII bytestring!
&gt;&gt;&gt; german_ae += bytestring
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0:
ordinal not in range(128)
then you must do
german_ae.decode('latin1').
here is the discussion
http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/index.html



Salı, Mart 04, 2008

Python file handling


From Python documentation:
----------------
write( str)

Write
a string to the file. There is no return value. Due to buffering, the
string may not actually show up in the file until the flush() or
close() method is called.
----------------

Thus flush()
should be used before reading any information just written to a file
moreover seek() should be used to reposition the file pointer thus the code should be changed as follows:

f = open('c:/test.txt','w+') # open file for updating
f.write('Hello World') # write some text to it
f.flush() # flush the internal buffer
f.seek(0) # reposition file pointer to beginning of file This is important when you need to rewind the pointer
f.read() # read the text that was just written