Saturday, August 23, 2014

Script: create new SVN project, create branches and trunk folders, set permissions


Script for automatically creating a new SVN project, branches / trunk folders and setting file permissions.

Usage: $ ./repoCreate.sh svn-project-name

File (repoCreate.sh) contents:

#!/bin/bash

dirRepo="/svn-repos-location/$1"
dirCheckoutTmp="~/svn-new-project-tmp"

if [ -d "$dirRepo" ]; then
        echo "ERROR: Directory already exists: $dirRepo"
        exit
fi

echo "Creating repository folder"
svnadmin create $dirRepo

echo "Checking out, creating trunk/branches folders and first commit"
if [ -d "$dirCheckoutTmp" ]; then
        echo "Deleting directory $dirCheckoutTmp"
        rm -rf $dirCheckoutTmp
fi
svn co file://$dirRepo $dirCheckoutTmp
cd $dirCheckoutTmp
mkdir trunk
mkdir branches
mkdir tags
svn add *
svn ci -m "init deploy" *
rm -rf $dirCheckoutTmp

echo "Setting additional permissions"
chown -R user:group $dirRepo




Friday, August 22, 2014

Ubuntu 14.04 add custom launcher to menu

Ubuntu 14.04 create custom launcher prerequisites:

$ sudo apt-get install gnome-panel --no-install-recommends

Create executable file for easy reuse

$ cd ~
$ touch launcher-create.sh
$ chmod +x launcher-create.sh

Edit the file launcher-create.sh and set contents:

#!/bin/bash
sudo gnome-desktop-item-edit /usr/share/applications/ --create-new

Anytime you want to create a new launcher, run:

$ ~/launcher-create.sh

After creating the launcher, it will show up in Unity's search result.

Saturday, April 26, 2014

Eclipse SVN change repository url

Subversion repository moved to a new machine. Solution for modifying the repository url.

Go to "Repository Browser" perspective, right click current repository and select "Relocate".

Observation: If the SVN repositories are not displayed on the left side (and instead the projects are displayed) you must select a different view (SVN repositories) for the left panel by using the plus icon (which may be at the bottom of the panel)... Not very intuitive.

Thursday, April 10, 2014

Ubuntu PHAR extract

Install PHAR:

$ pear channel-discover pear.kotowicz.net

$ pear install kotowicz/PharUtil-beta

Extract PHAR contents:

$ phar-extract library.phar output-directory

Monday, November 25, 2013

PHP - Data structures - Tree - Chained processing units


<?php

/**
 * Chained processing units (tree structure)
 * @author Ionut Bodea
 */


/*
 * Tree Nodes (adiacent list)
 */
$aNodes = array(
    1 => array(2, 3),
    3 => array(4, 5, 6),
    5 => array(7, 8)
);


$oTree = new Core_DataStructure_Tree($aNodes);

echo 'Tree (recursive, multi level array):';
print_r($oTree->getTree());

echo 'Tree (horizontal representation):';
print_r($oTree->getTreeHorizontal());


class Core_DataStructure_Tree
{
    private $adiacentList;
    private $tree   = array();
    ## private $isTree = false;

    public function __construct($adiacentList)
    {
        $this->adiacentList = $adiacentList;
        $this->computeTree();
    }

    private function computeTree()
    {
        $this->tree = array();
        foreach($this->adiacentList as $sParent => $aChildren)
        {
            if(empty($aChildren))
            {
                $this->addNode($sParent);
            }
            else
            {
                foreach($aChildren as $sChild)
                {
                    $this->addNode($sParent, $sChild);
                }
            }
        }
    }

    private function addNode($sParent, $sChild = null)
    {
        ## echo 'Add node - parent: '.$sParent.', child: '.$sChild.'<br/>';

        if(!$this->nodeExists($sParent))
        {
            $this->tree[] = array(
            'node'       => $sParent,
            'children'   => array()
            );
        }

        if(null === $sChild)
        {
            return;
        }

        if($this->nodeExists($sChild))
        {
            ## move existing child under a new parent (move an entire branch under a new parent)
            ## echo 'node exists: [[[[' . $sChild . ']]]]';
            $aXpathResult = $this->getNodeXPath($sParent);
            $aXPathParent = $aXpathResult['xPath'];
            $aXpathResult = $this->getNodeXPath($sChild);
            $aXPathChild  = $aXpathResult['xPath'];

            $sVarParent   = "\$this->tree[".implode('][\'children\'][', $aXPathParent)."]";
            $sVarChild    = "\$this->tree[".implode('][\'children\'][', $aXPathChild)."]";

            $sStringEval = "$sVarParent" . "['children'][] = $sVarChild;";
            eval($sStringEval);
            $sStringEval = "unset($sVarChild);";
            eval($sStringEval);
        }
        else
        {
            $aXpathResult = $this->getNodeXPath($sParent);
            $aXPath = $aXpathResult['xPath'];
            $aEntry = array('node' => $sChild, 'children' => array());
            ## printr($aEntry);
            $sStringEval = "\$this->tree[".implode('][\'children\'][', $aXPath)."]['children'][] = \$aEntry;";
            eval($sStringEval);
        }

        ## printr($this->tree);
        ## echo '<hr/>';
    }

    private function nodeExists($sNode, $aNodes = null)
    {
        $aNodes = null === $aNodes ? $this->tree : $aNodes;
        foreach($aNodes as $aNode)
        {
            if(isset($aNode['node']) && $aNode['node'] == $sNode)
            {
                return true;
            }
            if(isset($aNode['children']) && !empty($aNode['children']))
            {
                return $this->nodeExists($sNode, $aNode['children']);
            }
        }
        return false;
    }

    private function getNodeXPath($sNode, $aNodes = null, $aXPath = array())
    {
        ## printr($this->tree);
        $aNodes = null === $aNodes ? $this->tree : $aNodes;
        foreach($aNodes as $k => $aNode)
        {
            if(isset($aNode['node']) && $aNode['node'] == $sNode)
            {
                $aXPath[] = $k;
                return array('nodeFound' => true, 'xPath' => $aXPath);
                ## return $aXPath;
            }
            if(isset($aNode['children']) && !empty($aNode['children']))
            {
                ## $aXPath[] = $k;
                ## $aResult = $this->getNodeXPath($sNode, $aNode['children'], $aXPath);
                $aResult = $this->getNodeXPath($sNode, $aNode['children'], array_merge($aXPath, array($k)));
                if(isset($aResult['nodeFound']) && $aResult['nodeFound'])
                {
                    return $aResult;
                }
                ## return $this->getNodeXPath($sNode, $aNode['children'], array_merge($aXPath, array($k)));
            }
        }
        return array('nodeFound' => false, 'xPath' => $aXPath);
    }

    /* public function isTree()
     {
    return $this->isTree;
    } */

    /**
     * @return array
     */
    public function getTree()
    {
        return $this->tree;
    }

    /**
     * Get a horizontal representation of the tree
     * Array
     *     [] -> level 0 nodes
     *     [] -> level 1 nodes
     *     ....
     * @return array
     */
    public function getTreeHorizontal($aNodes = null, $nLevel = null, &$aResults = array())
    {
        $aNodes = null === $aNodes ? $this->tree : $aNodes;
        $nLevel = null === $nLevel ? 0 : $nLevel + 1;
        foreach($aNodes as $aNode)
        {
            !isset($aResults[$nLevel]) ? $aResults[$nLevel] = array() : '';
            $aResults[$nLevel][] = $aNode['node'];
            $this->getTreeHorizontal($aNode['children'], $nLevel, $aResults);
        }
        return $aResults;
    }

}

Sunday, November 24, 2013

Global stats: Mobile vs Desktop

Mobile vs Desktop
Mobile OS

Stats are based on aggregate data collected by StatCounter from more than 3 million websites, having over 15 billion pageviews / month - http://gs.statcounter.com/about

Saturday, November 23, 2013

Linux/Ubuntu - Video editing - video/audio merging, soundtrack replacing

1) Merge multiple mp3 files into one
sudo apt-get install mp3wrap
mp3wrap onemp3.mp3 file1.mp3 file2.mp3 file3.mp3 ...
mp3wrap onemp3.mp3 -a file1-append.mp3 file1-append.mp3 ...


2) Change video file soundtrack
mencoder -ovc copy -nosound video.avi -o video_nosound.avi
mencoder -ovc copy -audiofile soundtrack.mp3 -oac copy video_nosound.avi -o video_new.avi


3) Merge multiple video files into one
sudo apt-get install mencoder
mencoder -oac copy -ovc copy -idx -o megavideo.avi *.avi


4) Resize video
mencoder input.avi -o output.avi -ovc xvid -xvidencopts bitrate=3000 -oac mp3lame

5) Speed up video (with Avidemux)
sudo apt-get install avidemux
Avidemux - Menu: Video -> Frame rate (set it to 100 for example) -> Save video  

Observation: Speeding up the video should be performed on a video file with the soundtrack removed (see above how to achieve this).