Kate and replace with regular expressions

Just got good experience with KDE’s Kate editor and must share it.

You have piece of code, which looks like this

if(get_var('submit')){
    // still empty..
}else{
    $var1=null;
    $var2=null;
    ...
    $var100=null;
}

and now you need to put those initializations of var’s to the first block also, getting variables from GET or POST supervariables. What to do? Doing hunderd times of “delete null, paste get_var(”), copy-paste ‘name of variable’” and the day is going to be sooooo long …

Now, in Kate you can do it by one click. Copy all lines “$var..=null;” to first block, select those lines and “ctrl+r” (replace) and put values:

Find: \$(.*)=null;
Replace: \$\1=get_var('\1');
Mode: Regular expression
[V] Selection Only (just incase)

and press “Replace All”. And it’s done:

if(get_var('submit')){
    $var1=get_var('var1');
    $var2=get_var('var2');
    ...
    $var100=get_var('var100');
}else{
    $var1=null;
    $var2=null;
    ...
    $var100=null;
}

and explained:
In Find expression you see (.*) – content of parentheses are treated as parameter “one” and referenced later as \1. That what you see in Replace expression \$\1 – will get replaced as “$var1″ and get_var(‘\1′) gets get_var(‘var1′)

Posted in Uncategorized | Leave a comment

Force Moodle to put Dataroot under website root

Had to help install Moodle today. Pretty ugly experience comparing for example to wordpress installation.

Main problem was that Moodle forces you to put dataroot directory outside of webroot directory. Not going to argue is it magic cure against all evil and bad or not, but two things are sure:

a) User needs options, and decision should be he’s (just warning should be ok, and default restricting .htaccess file)
b) If you are using some hostingserver or have some-kind setup which doesn’t allow your php script to access files outside from wwwroot, then you are in deep problems.

But, there is atleast one good solution :D And that’s directly related to power of open source – if you don’t like something, CHANGE IT!

Solution:

* Open in your favorite editor file MOODLE_INSTALL_DIR/lib/adminlib.php
* find function is_dataroot_insecure
* add return false; directly after function header, so it looks like this

function is_dataroot_insecure($fetchtest=false) {
    return false;
    global $CFG;
...

it allows you to put datadir wherever you want and test or use it on your own risk.

Other problems were somehow related to installer, and seems that it thinks, that you have all power on database you ever can (in other words – you have root-like permissions). So lot of messages “table already exists” and so on. And later.. some magical message “DDL sql execution error” – whatta hek is that?

As it happes on import, it is related to creation of temporary tables. WHY can’t it be cheked in installation time or given some HUMAN-readable message. Fix it:

GRANT CREATE TEMPORARY TABLES ON `database`.* TO 'username';
Posted in Uncategorized | Leave a comment

Linux Mint installation dvd asks username and password?

Downloaded and tried to install Linux Mint 12 today.

After burning DVD and booting up it in my laptop I got username and password prompt in graphical interface. At first I tried mint/[no password], mint/mint, install/[no password] and so on and on. Even tought that maybe it asks user and password of existing installation on disk. After that I tried search installation manual but no reference to username and password. So.. whatta hek?

but after lots of googling I found this and got next idea to check md5sum of iso and burned disk. but..

How to checksum already burned DVD?
Okay, before I got to DVD I already discovered that iso on disk is not good anymore, md5sum was different from that was said on Mint’s page. But how did that happen, as I already controlled iso and it WAS ok!? Problem was that during download computer crashed, and later I started new download before I discovered that old download was resumed by firefox. Anyway.. smth was broken. Third DVD was already success:)

but back to question. You can check your iso file md5 by running command (note, this is correct iso)

$ md5sum linuxmint-12-gnome-dvd-64bit.iso
548f0ac303fea840ef138e5669880a74  linuxmint-12-gnome-dvd-64bit.iso

to check already burned DVD or CD, you must know the size, as for one way I figured out. With “ls -l” you get 1066518528, and now it must be divided with 2048 as block size: 1066518528/2048=520761

# calculate md5sum on invalid file:
$ md5sum linuxmint-12-gnome-dvd-64bit.iso
86788cd20f20f1f370c833c650c16838  linuxmint-12-gnome-dvd-64bit.iso

# check md5sum of DVD
$ dd if=/dev/cdrom4 bs=2048 count=520761 | md5sum
520761+0 records in
520761+0 records out
1066518528 bytes (1.1 GB) copied, 125.79 s, 8.5 MB/s
86788cd20f20f1f370c833c650c16838  -

why is this impotrant, or why you can’t just sum whole device? Some additional burining info is added to DVD…

Posted in Uncategorized | Leave a comment

rdesktop: how to switch off from fullscreen?

Looked for that solution alrady long time, but no acively – just thought about it – if using remote connection in Windows, there is additional bar on top of screen, but whatabout rdesktop?

And as I found out, there is nice solution. Just press ctrl + alt + enter – it switces off or on fullscreen mode.

Posted in Uncategorized | Leave a comment

Install openoffice.org in Ubuntu

Unfortunately it is not anymore possible through package management. Searching for openoffice in Synaptic Package Manager or apt-get, you will find openoffice but it will install libreoffice not openoffice. Only way, as I know currently, is install by hand.

To installation we need package and you can get it from here http://download.openoffice.org/other.html

$ tar xvfz downloaded_file.tar.gz
$ apt-get remove libreoffice*.*
$ dpkg -i unpacked_dir/DEBS/*.deb
$ dpkg -i unpacked_dir/DEBS/desktop-integration/*.deb
Posted in Uncategorized | Leave a comment

And gone again – Adsense account closed

abut week ago I got message from Google Adsense Team:

While going through our records recently, we found that your AdSense
account has posed a significant risk to our AdWords advertisers. Since
keeping your account in our publisher network may financially damage
our advertisers in the future, we’ve decided to disable your account.

As they provide no details, and that was my third try to use their service I’m giving up. Don’t know what’s going on in their heads?

* I didn’t click by myself nor was forcing anyone to click any banner
* wrote unique content
* in english

So, why I still see googles ads everywhere on pages which clearly doesn’t create unique content? Probably I will never know.

Trying now banners from others but it seems that they are even more pointless, as atleast in Estonia they provide no clicks and no money..

Posted in Uncategorized | Leave a comment

Open gzipped file with vi?

If you are using latest (and greatest) vi/vim then it can open gzipped files (those with extension .gz) automagically, but it’s not so easy if you must use some old/outdated system where is also old vi/vim.

So, what to do? Gunzipping is sometimes impossible (no gunzip? not enough free space? readonly system? too many files to just search through…). Use zcat!

$ zcat filename.gz | vi -

That’s not all!
gzip package (on Gentoo : app-arch/gzip) contains many more commands useful with .gz files, for example:

* zcmp – binary-compare two gzipped files
* zdiff – compare two gzipped files
* zgrep, zegrep, zfgrep – grep in gzipped files
* zless, zmore – do less and more on gzipped files

Posted in Uncategorized | Leave a comment

KDE and empty “Open With…” menu

Updated to KDE 4.6.2 on one computer and weird problem happened. When tried automount usb disk and open it with dolphin instead I got dialog to choose program to do it with. Strange. Later discovered, that right-click on file “Open With” dialog was empty. Just like all mime-related info was gone.

To fix it, just remove /var/tmp/kdecache-[username] and just relogin to KDE.

Posted in Uncategorized | Leave a comment

Errors in wordpress after php upgrade

Got an interesting problem few days ago. Just updated php (and apache and some other programs) and did “/etc/init.d/apache2 graceful” when suddenly got errors in wordpress blogs like this

Warning: preg_replace() [function.preg-replace]: Compilation failed: unknown option bit(s) set at offset 0 in /path/to/wp-install/wp-includes/shortcodes.php on line 228

Code-repo showed that there were no changes for long time in shortcodes.php file, so there was like two possibilities – some new problem with php or some weird error in my server.

Got also two links from wordpress bugtracker

http://wordpress.org/support/topic/warning-preg_match-functionpreg-match-errors

http://wordpress.org/support/topic/plugin-contact-form-7-problem-with-preg

from where I found out, that it might be releated to libpcre. I created test.php with phpinfo(); inside and found out that php was using pcre 7.9 when in system was actually installed 8.12.

final step to discovery of problem was some page where some user complained, that he has different output of phpinfo(); in apache and on commandline. So, inspired of that, I checked out and got interesting result:

$ php --info|grep -i pcre
/.../
PCRE Library Version => 8.12 2011-01-15
/.../

also were both files pointing to right place

$ ldd /usr/bin/php | grep pcre
        libpcre.so.0 => /lib/libpcre.so.0 (0xb7230000)

and

$ ldd /usr/lib/php5.3/apache2/libphp5.so | grep -i pcre
        libpcre.so.0 => /lib/libpcre.so.0 (0xb6aba000)

So, only possible explanation could be, that apache graceful restart was not enough. When I did restart, it complained about configuration (yeah, two changes in same time, bad-bad!) – ssl port was already taken), and when I fixxed apache start-flags it started and also showed php right pcre version and problem in wordpress dissapeared.

Posted in Uncategorized | 6 Comments

How to find out uptime in windows?

If you are looking answer for that, you will soon discover that there is no way to find out this from default GUI programs

Run this in “cmd” :

net statistics server

or shorter

net stats srv
Posted in Uncategorized | Leave a comment