rulururu

post MP3 to ogg, preserving tags

April 20th, 2008

Filed under: mac — zedr0n @ 2:51 pm

I personally don’t like all those insane 320kbit bitrates, I’m perfectly fine with listening to 80kbit ogg(which sounds like 128kbit mp3 occupying less space at the same time). As it’s impossible to convert from inside iTunes(oh, Foobar, where art thou?) I had to resort to command line tools. The tools we’ll need are

  • LAME - mp3 encoder
  • eggenc - ogg encoder(you’ll need to build libogg, libvorbis, vorbis-tools but it builds out-of-box)
  • id3tool - mp3 tag viewer(and editor) - also builds successfully
  • Grep and sed - text manipulators, powerful standard tools

Now the bash script which will convert all the supplied mp3 files to ogg(mp32ogg):

#!/bin/sh

for file in "$@"
do
    if test ! -f "$(basename "$file" .mp3).ogg"
    then
        lame --decode "$file"
        ARTIST=`id3tool "$file" | grep Artist | sed s/Artist:// | sed 's/[^A-Za-z0-9]*//'`
        ALBUM=`id3tool "$file" | grep Album | sed s/Album:// | sed 's/[^A-Za-z0-9]*//'`
        TRACK=`id3tool "$file" | grep Track | sed s/Track:// | sed 's/[^A-Za-z0-9]*//'`
        YEAR=`id3tool "$file" | grep Year | sed s/Year:// | sed 's/[^A-Za-z0-9]*//'`
        GENRE=`id3tool "$file" | grep Genre | sed s/Genre:// | sed -e 's/[^A-Za-z0-9]*//' -e 's/(.*)$//'`
        oggenc -a "$ARTIST" -G "$GENRE" -d "$YEAR" -N "$TRACK" -l "$ALBUM" -b 80 "$file.wav" -o "$(basename "$file" .mp3).ogg"
        rm "$file.wav"
    fi
done

In case you wonder why it uses such strange long lines, the process of getting the artist for example can be described as follows:

  • id3tool “$file” - get tags
  • grep Artist - get line containing word Artist
  • sed s/Artist:// - remove the preceding string “Artist:” from the line
  • sed ’s/[^A-Za-z0-9]*// - remove the unnecessary spaces/tabs/etc… before the artist name itself(the actual meaning is remove all characters before encountering alphanumerical - A-Z or a-z or 0-9)

Btw, basename “$file” .mp3 is just a neat way to strip mp3 extension preserving the filename itself.

The syntax is straightforward - you could use built-in wildcards - e.g. mp32ogg T*.mp3 will convert all mp3 files starting with T.

post Using CMake with vim

April 13th, 2008

Filed under: C++, Coding — zedr0n @ 3:08 pm

I’ve recently moved from make to CMake which is a cross-platform build system. It’s quite nice if you want to be able to build for mac/win with the same makefile(CMakeLists.txt for CMake). The CMakeLists syntax is quite powerful and I haven’t regretted moving since.

One of the main ideas of CMake is out-of-source build - that is you use cmake like this

cmake directory

where directory contains the CMakeLists.txt and it builds everything in the current directory you are in. This is mostly because CMake is quite messy - it uses lots of files to build.

I use Vim for my development and its awesome ‘make’ compatibility which allows to build programs using make inside vim and view errors with special vim commands. Now as CMake uses unix makefiles on mac, it works quite well from vim. But then you’ll have to first generate makefiles with cmake inside the source directory for that to function. Not a nice idea really…

My solution to this is to use Makeobj. It is a script used to build using normal make outside of source directory. It uses OBJ_SUBDIR environment variable which defines the name of subdirectory where the build will take place.

How can it be used with CMake and vim? Here is the maker script I use

#!/bin/bash

if [ -e makefile ]; then
    make
else
    export OBJ_SUBDIR=build
    if [ -e CMakeLists.txt ]; then
        if [ -d build ]; then
            cd build
            rm CMakeCache.txt
        else
            mkdir build
            cd build
        fi
        cmake ../
        cd ..
        makeobj $1 $2 $3 $4 $5
    fi
fi

Now in vim you just go

:set makeprg=maker

post RPM’s on OsX

March 19th, 2008

Filed under: mac — zedr0n @ 12:18 pm

Recently one of the ways to distribute packages(binary and source) is by using RPM. That’s all very good and everything but what to do if the rpms aren’t supported - as on osX? It gets a bit trickier but still manageable.

First grab the perl script - rpm2cpio.pl. Its usage is pretty straightforward

rpm2cpio, perl version by orabidoo <odar@pobox.com> +sw
dumps the contents to stdout as a cpio archive

use: rpm2cpio [file.rpm] > file.cpio

Here's how to use cpio:
    list of contents:   cpio -t -i < /file/name
       extract files:   cpio -d -i < /file/name

Thankfully, cpio is natively available on osx, so that’s pretty much it all amounts to.

post Par2 on OsX

March 19th, 2008

Filed under: C++, Coding, mac — zedr0n @ 12:08 pm

There’s a handy tool for correcting data errors - Par2

The command line utility for linux is included in most packages, but alas not so on macos. There are still two ways to go - there is a port over at MacPorts but I already have Fink installed and I didn’t really want to get another clutter in the system. So I just found the ALT Linux Source, extracted the rpm and built it.

You can grab the source here Par2.tar.gz
Now just extract it and build it

tar -xvf par2.tar.gz
cd par2cmdline-0.4
chmod +x configure
./configure
make

Now you can just move par2 utility to your path directory of choice.
Just in case you don’t want to bother building it - grab the binary here - par2.bz2

post Vim & LaTeX on a mac

February 26th, 2008

Filed under: mac — zedr0n @ 9:38 pm

Since I’ve moved to mac not so long ago, I was happy that most of the apps I normally use are ported to os x.
As I’ve been writing a lot of mathematical stuff in LaTeX it soon got quite annoying constantly recompiling, closing previous Preview.app instance and opening it again so that the pdf file gets properly reloaded(on Windows dvi viewer reloaded automatically). Seems like this wasn’t only my problem as there turned out to be a pdf/dvi viewer out there with automatic reloading - Skim.

I’ve also learned about pdfsync which is quite neatly handled in Skim - just Shift-Command-Click and it opens Vim at the corresponding line in tex file, nice…

While at it, I’ve switched to MacVim because of better integration with pdfsync, along with nicer aqua interface, tab support etc…

post Cave story - multiple saves

February 21st, 2008

Filed under: mac — zedr0n @ 12:44 am

There is a very old-skool platformer style game called Doukutsu Monogatari or Cave story. You can read more about it here. It has multiple endings but the main drawback is that it has very limited save support - there is only one save slot available - which is quite similar to another old-skool game ADOM.
But it doesn’t take a super-guru to right things for this one. Here is a quick-coded bash script which adds the capability for multiple saves. It’s based on the fact that the save progress is stored in file ~/Library/Preferences/com.nakiwo.Doukutsu.plist
What is done precisely is just saving the current file to a Save directory with a description supplied by the user.

Installation:
- Download doukutsu script here
- chmod +x doukutsu in case it’s not executable
- create a directory named Saves in the directory where you put doukutsu script
- you are done

The usage is straightforward, just follow the instructions when running the script.

P.S. It will locate the Cave Story .app file on its own if it has been put in /Applications folder

post OS X SVN Clients - SvnX & ZigVersion

January 21st, 2008

Filed under: SVN — zedr0n @ 1:38 pm

On windows the most popular client is TortoiseSVN, but the situation isn’t as clear on the mac.

SvnX

The first one i tried was SvnX. It’s free open-source subversion client which is quite popular.Read more…

ZigVersion

So I’ve decided to switch over to ZigVersion. It’s not open-source, but free for personal use which suits me just fine.Read more…

Conslusions

All in all, I do prefer Zigversion, though I’ll be on lookout for other mac svn clients - there is java SmartSvn and upcoming VersionsApp which looks quite promisiing. For now, the choice is yours what to use…

post Installing wiki on a2hosting with latex support on A2Hosting

January 20th, 2008

Filed under: A2Hosting — zedr0n @ 8:37 pm

Installing MediaWiki

Getting MediaWiki up and running is pretty simple. Here is the installation script which will download mediawiki 1-11.0 and do the necessary preconfiguration (see more here on that)

Setting up database for Wiki

Go to CPanel->MySQL Databases and add new database(e.g wikidb - I’m not sure but to be on the safe side I recommend to select name which isn’t the same as one of subdomains on your website). Then Add User(e.g wikiuse) and Add User to database with all privileges.

Configuring

You can try to do the first part automatically by running the script in the intended wiki directory - bash installwiki.sh
If everything went ok, then just point your browser to the config directory. Follow the direction on-screen - you should enter the data you used when creating the database in the Database config section - don’t forget to add your a2hosting username to db name and db username.
Now some postinstallation stuff

mv ./config/LocalSettings.php ./
rm -rf ./config

It will just delete ./config directory and move localsettings.php to its intended place

Enabling TeX

To enable tex you need to have texvc compiled in your wiki/math subdirectory. Unfortunately, a2hosting doesn’t have ocaml installed so you won’t be able to compile it on-site. But I managed to find the precompiled binary for CentOS 5 for x86_64 platform which is what a2hosting runs. You can grab it here. You’ll need to put it into your wiki/math subdirectory and maybe do chmod 777 ./texvc on it.
Then you’ll have to add the following lines(or change the value if they exist already) to your LocalSettings.php file

$wgUseTex = true;
$wgTmpDirectory = "/home/your_username/www/your_wiki_directory/images/tmp";
$wgMathDirectory = "/home/your_username/www/your_wiki_directory/images/math";

You’ll also have to actually create the directories in question by ssh’ing to your server and executing

cd ~/www/your_wiki_directory/images
mkdir tmp
chmod 777 tmp
mkdir math
chmod 777 math

post Setting up single-user synced SVN repositories

January 17th, 2008

Filed under: Coding, SVN — zedr0n @ 9:30 pm

First you’ll need to follow the SVN wiki entry to set up svn repository and passwordless ssh access at A2Hosting.

As this is only for one user, then the easiest way is to use svn dump functionality which allows for incremental dumps. Using post-commit hooks we’ll just save the new commits since last sync to a dump file. Furthermore, apart from manual update of repositories from dump we’ll also write a script which will sync the repositories nightly(e.g using cron). But the main thing is to be able to switch from using remote(main) repository to its local copy to continue developing if for some reason we don’t have network access.

Setting up repositories

I assume that you’ve got one repository completely set up and ready. Now we only need to dump the repository,

svnadmin dump repository_path >dumpfile

copy the dumpfile and run

svnadmin create repository_path
svn load repository_path <dumpfile

Setting up automatic dumping

The next thing is installing post-commit hook, which is just an executable program put into repository_path/hooks. Consult post-commit.tmpl for more info.
post-commit

#!/bin/sh
REPOS="$1"
REV="$2"
DUMP=path_to_dump_to

svnadmin dump $REPOS --incremental --revision $REV >$DUMP/newsvn.dump
cat $DUMP/svn.dump $DUMP/newsvn.dump >$DUMP/svn_.dump
mv -f $DUMP/svn_.dump $DUMP/svn.dump

And don’t forget to make it executable with chmod.

Synchonizing the repositories

This is the script to sync from remote to local
sync2local

#!/bin/bash
FTP_USER=
FTP_PASS=
FTP_SERVER=
SSH_SERVER=
SSH_USER=
DUMPFILE=svn.dump
REPO=/svn
PORT=-p 7822

#delete old dump file
if [ -e $DUMPFILE ]; then
    rm $DUMPFILE
fi
#get current dump file
wget --password=$FTP_PASS --user=$FTP_USER ftp://$FTP_SERVER/$DUMPFILE
if [ $? != 0 ]; then
    echo No dumpfile available
    exit
fi

#update local repository
svnadmin load $REPO <$DUMPFILE

#delete dump file if sucessful
if [ -e $DUMPFILE ]; then
 ssh $SSH_USER@$SSH_SERVER $PORT rm $DUMPFILE
 rm $DUMPFILE
fi

And the script to sync from local to remote
sync2remote

#!/bin/bash
FTP_USER=
FTP_PASS=
FTP_SERVER=
SSH_SERVER=
SSH_USER=
PORT="-p 7822"
REPO=
#dumpfile with full path
DUMPFILE=
#test if dump file exists
if [ ! -e $DUMPFILE ]; then
    echo "No dump file available"
    exit
fi

#upload dump file
echo "put $DUMPFILE $(basename $DUMPFILE)" | ftp ftp://$FTP_USER:$FTP_PASS@$FTP_SERVER
if [ $? != 0 ]; then
    echo "Can't upload dumpfile"
    exit
fi
#update remote repository
ssh $SSH_USER@$SSH_SERVER $PORT "svnadmin load $REPO <$(basename $DUMPFILE)"
#delete dump file if sucessful
rm $DUMPFILE
ssh $SSH_USER@$SSH_SERVER $PORT rm $(basename $DUMPFILE)

Switching between repositories

These 2 scripts svn2remote and svn2local can be used to switch a working copy between repositories. Before switching it will sync to the most recent copy, which is precisely what we need.
svn2remote

#!/bin/bash
REPO=/svn
sync2remote
svn switch --relocate file://$REPO svn+a2hosting://zedr0n@quant0r.com/home/zedr0n/svn .

svn2local

#!/bin/bash
REPO=/svn
sync2local
svn switch --relocate svn+a2hosting://zedr0n@quant0r.com/home/zedr0n/svn file://$REPO .

So, basically, whenever you want to work on some projects, you just check it out by doing svn2local and merge the changes with svn2remote when you are done. If you are confident in remote repository then you can just work with it all the time. It’s quite flexible really…

post Installing OpenID with WordPress

January 16th, 2008

Filed under: A2Hosting — zedr0n @ 5:14 pm

The first part is to allow openID users to post comments on your blog, this can be easily achieved by installing Wordpress OpenID plugin. The installations is simplicity itself - just copy the plugin and activate it, nothing else required.

The other part is being able to use your blog as an openID server. I wasn’t able to find this as a plugin so I decided to go with a standalone
phpMyID. Grab the 0.7 beta here and follow the instructions in README file, they are pretty straightforward and they worked for me with no problems.

Just to note that if you want it to work with your wordpress blog you need to add to the header.php file of your current theme

<link rel="openid.server" href="http://<your-blog>/MyID.config.php" />
<link rel="openid.delegate" href="http://<your-blog>/MyID.config.php" />

If your blog is on a subdomain then MyID.config.php and MyID.php should be uploaded to the subdomain root(i.e. your-domain/subdomain).
Otherwise if you just put it into your root, it will point to your openID server - i.e. the root of your domain

Next Page »
ruldrurd
© quant0r.com , Designed by Stealth Settings
Entries (RSS) and Comments (RSS)