rulururu

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 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 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 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 Custom refresh of NetNewsWire with AppleScript

January 16th, 2008

Filed under: Coding, mac — zedr0n @ 5:00 pm

I’ve switched to mac just recently and haven’t yet found the alternatives for all the windows tools. I’ve been trying Newsfire for some time and I’ve been somewhat satisfied with its performance. But since I’ve discovered Wilmott Forums RSS feeds I was having problems with Newsfire - it doesn’t change status, nor in any other way acknowledge small item updates. And as Wilmott goes with the one-item-per-thread model, so that the item just contains the date of the last post, it was more or less useless for with Newsfire.

Then NetNewsWire went freeware, so I decided to give it a try. It has a useful feature - “mark updated items as unread” while also sorting the items by the last update time, which is more or less what I need. Although, I need to say that it doesn’t mark items as unread after tiny updates - as on Wilmott, so it’s not ideal. One other problem with NetNewsWire is that the minimum refresh time is set to 30 minutes. While it might be acceptable to most feeds so as to not get distracted all the time, I want to get faster wilmott updates. Well, when there’s a will, there’s a way. And this way is called AppleScript.

Skip down for new beta of custom refresh app

The first, and by far simpler, way is to use a script. It’s pretty straightforward - just open up Script Editor and insert

repeat
  tell application "NetNewsWire" to refreshAll
  delay 300
end repeat

I’ve settled on 300 seconds for delay time, but whatever one wants. Now, running the script manually, looks like a chore and it still shows up as a window. So, to improve it, we can do File->Save As->application bundle. Still not much improvement so far, we can’t even quit the app. But we don’t really need it if we hide it. And it can be easily achieved by adding to /NameOfApp.app/Contents/Info.plist

<key>LSUIElement</key>
<string>1</string>

This key tells the app to work in background/dockless mode, which is precisely what we need. The cpu usage is quite modest indeed, so we can just add it as a Login item and all’s done. The NetNewsWire now refreshes as fast as we want it too.

The second way is for those who just need to be able to stop refreshing without resorting to Force Quit. It’s a bit harder, and involves using XCode.
The standard way to automate actions in Os X so far seems to use Automator, and NetNewsWire is no exception. Unfortunately, the number of actions available is rather limited, and no refresh/refreshAll action available. But we can create a new action on our own. To do this, simply do
XCode->New Projects->New AppleScript Application. Now the files we need are main.applescript, Info.plist, InfoPlist.strings. The script is just

on run {input, parameters}
    tell application "NetNewsWire" to refreshAll
    return input
end run

Now, if we switch to Release mode and build the app, the only thing left to install the action is to copy from project directory to either /Library/Automator or ~/Library/Automator. It will show up in Automator but as a separate action unrelated to NetNewsWire, it will work, but it does annoy a bit. That’s why we’ll need Info.plist - we change AMApplication key to

<key>AMApplication</key>
<string>NetNewsWire</string>

And that’s all we need to do for the app to show under NetNewsWire. To clean up things a bit, we can also edit InfoPlist.strings

AMName = "RefreshFeeds";
/*  AMDescription localized strings  */
AMDSummary = "Refresh all feeds";

Everything else there is irrelevant for our purpose.

The only thing left is just to create an Automator workflow of the format:

  • NetNewsWire-> _our new action to refreshAll in NetNewsWire_
  • Automator->Pause
  • Automator->RunWorkflow

Now we can save the workflow as application and apply the same trick with LSUielement. The only difference is on the menu bar
Menu Bar refresh

We can stop it at any time by pressing the red button. The disadvantages with this approach is 5-10 times bigger cpu usage(well, under 1% still) and clutter on the menu bar - but whatever one prefers…
You can download both apps here - script RefreshRSS and Automator RefreshFeeds

Thanks to a request from Theodora I’ve tried to improve the script a bit to allow for custom subscription refresh. It’s beta for now, so any comments are highly welcome, though it should work ;) So, what’s in the Refresher.app? It’s still just a script as RefreshRSS but with a few tweaks. Upon launch you’ll get a dialog in NetNewsWire asking

netnewswire001.jpg

If you click yes, then you’ll get a list of all your subscriptions where you need to choose the one you wish to set/change the refresh rate, it looks smth like this
netnewswire002.png

If you select the subscription you haven’t previously set the refresh rate for you’ll just get a dialog box
netnewswire003.png

The default value is 5 minutes; pressing ok will bring you again to the dialog box asking if you want to add another refresh rate.

If for whatever reason you want to change the refresh rate for subscription you just select it from the list and get a dialog box like
netnewswire005.png

That’s pretty much it. For technically oriented, this is pure AppleScript, all the details of your subscriptions are stored in ~/Library/Preferences/Refresher.info in format “Subscription:refresh time” on every line.

You can get it here : Refresher.zip

p.s. If you are getting error message “file Macintosh HD: … is already open” then this means that app crashed earlier and you’ll have to reboot to close it properly. Anybody knows how to close file opened with open for access under applescript for that matter?

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