29. 7. 2012

GREP search and replace

Nasel jsem krasnej post:

Use this command:
egrep -lRZ "\.jpg|\.png|\.gif" . \
    | xargs -0 -l sed -i -e 's/\.jpg\|\.gif\|\.png/.bmp/g'
  • egrep: find matching lines using extended regular expressions
  • -l: only list matching filenames
  • -R: search recursively through all given directories
  • -Z: use \0 as record separator
  • "\.jpg|\.png|\.gif": match one of the strings ".jpg", ".gif" or ".png"
  • .: start the search in the current directory
  • xargs: execute a command with the stdin as argument
  • -0: use \0 as record separator. This is important to match the -Z of egrep and to avoid being fooled by spaces and newlines in input filenames.
  • -l: use one line per command as parameter
  • sed: the stream editor
  • -i: replace the input file with the output without making a backup
  • -e: use the following argument as expression
  • 's/\.jpg\|\.gif\|\.png/.bmp/g': replace all occurrences of the strings ".jpg", ".gif" or ".png" with ".bmp"





Dropbox musite mit

juknete na dropbox!

Dropbox je cloud reseni, ktere funguje jak z webu tak z Windows, Linux, Mac, Android
nabizi zdarma dostatek storage a spoustu moznosti jak ziskat nejakou zdarma, sam jsem aktualne na 5GB zdarma. Pokud dropbox chcete tak kliknete na muj referal a dostanu za vas 250MB :-)

Dik

25. 7. 2012

How to create custom application launchers in Gnome 3

http://blog.randell.ph/2011/08/01/how-to-create-custom-application-launchers-in-gnome-3/

17. 7. 2012

Batch update URL aliases in Joomla 2.5

Jak nastavit spravne URL aliasy pro existujici zaznamy v databazi.

Zjistil jsem, ze Joomla neumi odstranit diakritiku z nazvu tak aby friendly URL bylo spravne a č nebylo smazano. Nenasel jsem zadny nastroj, ktery by to dokazal opravit nad existujicimi zaznamy, tak jsem si napsal malinkej PHP script.

Prepiste si ho tak aby jste mohli parametry zadavat treba v konzoli, tohle byla jednorazovka.


mb_internal_encoding('UTF-8');


$conn = mysql_connect('localhost','xxxxx','xxxxxxx');
mysql_select_db('xxxxxx');
mysql_query('set names utf8');


$result = mysql_query('select * from j25_content order by id desc');
while ( $record = mysql_fetch_assoc($result) ) {
    $found = mysql_query('select count(*) matched from j25_content where `alias`="'.addslashes(seoUrl($record['title'])).'" and id<>'.$record['id']);
    $foundM = mysql_fetch_assoc($found);
    $alias = seoUrl($record['title']);
    if ($foundM['matched']>1)
    {
        $duplicates++;
        $alias.="-".(intval($found['matched'])+1);
        echo ('[!!] ' . $record['alias']. 'would be duplicit, changed to: '.$alias."\n");
    }
    if ($record['alias']!=$alias) {
        echo ('[++] ' . $record['alias']. ' changed to '.$alias.' from title "'.$record['title'].'"'."\n");
        mysql_query('update j25_content set alias="'.$alias.'" where id='.$record['id']);
        $modified++;
    } else {
        $correct++;
    }
       
}
$result = mysql_query('select * from j25_menu order by id');
while ( $record = mysql_fetch_assoc($result) ) {
    $found = mysql_query('select count(*) matched from j25_menu where `link`="'.addslashes(seoUrl($record['title'])).'" and id<>'.$record['id']);
    $foundM = mysql_fetch_assoc($found);
    $alias = seoUrl($record['title']);
    if ($foundM['matched']>1)
    {
        $duplicates++;
        $alias.="-".(intval($foundM['matched'])+1);
        echo ('[!!] ' . $record['alias']. 'would be duplicit, changed to: '.$alias."\n");
    }
    if ($record['link']!=$alias) {
        echo ('[++] ' . $record['link']. ' changed to '.$alias.' from title "'.$record['title'].'"'."\n");
        mysql_query('update j25_menu set alias="'.$alias.'",  path="'.$alias.'" where id='.$record['id']);
        $modified++;
    } else {
        $correct++;
    }
       
}

echo mysql_num_rows($result)." analyzed, $correct was ok, $modified has been modified, $duplicates was duplicate...\n";


/**
  * Return URL-Friendly string slug
  * @param string $string
  * @return string
  */

function seoUrl($string) {
        //Unwanted:  {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
        $string = mb_strtolower($string);
    $string = iconv('UTF-8','ASCII//TRANSLIT',$string);
        //Strip any unwanted characters
        $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
        //Clean multiple dashes or whitespaces
        $string = preg_replace("/[\s-]+/", " ", $string);
        //Convert whitespaces and underscore to dash
        $string = preg_replace("/[\s_]/", "-", $string);
        return $string;
}

16. 7. 2012

Update/Install Java Oracle JDK on Ubuntu 10-12.04

Pokud potrebujete pro nektere program JDK od javy misto OpenJDK, ktere ma dost problemu s vykonem a zobrazenim tak existuje PPA repositar, kde to lze jednoduse updatnout do aktualni verze.

Jak na to:

K pridani PPAv Ubuntu (12.04, 11.10, 11.04 and 10.04):
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-installer

Pokud vse probehlo bez chyby tak kontrola:
java -version

Meli by jste videt neco podobneho:
java version "1.7.0_04" Java(TM) SE Runtime Environment (build 1.7.0_04-b20) Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)

The package installs all the Java binaries, so you can also try "javac -version" which should return "javac 1.7.0_04" and so on (the "_04" part of the version can be different because I'm constantly updating the PPA with the latest Oracle Java 7 version).

If for some reason, the Java version in use is not 1.7.0, you can try to run the following command:
sudo update-java-alternatives -s java-7-oracle