Remove SVN – AppleScript droplet

(July 4th, 2011)

Well, I know this type of droplet’s has been written before, but I have not seen much code shared. So here’s my take on it. Do like this. Just drop your folder, or folders if you like, onto the app and all the .svn folders will be cleaned.

on open current_files
       
        repeat with current_file in current_files
               
                – validate if the file as a folder
                if (current_file as string) ends with ":" then
                       
                        try
                                set current_file_path to (POSIX path of the current_file as string)
                                do shell script "find  ’" & current_file_path & "’ -name ‘.svn’ | xargs rm -Rf"
                               
                        end try
                       
                end if
               
        end repeat
       
end open

I also added this as a gist under github. So please feel free to fork!
https://gist.github.com/1063705

Introducing AtomCart

(February 13th, 2011)

I was actually supposed to release this project a couple of weeks ago, but work interfered (it always seems to do so). Anyhow here is AtomCart. AtomCart is basicly a very lightweight shopping cart in its purest form (hence the name), built in javascript as a jQuery plugin. It does nothing else except hold a very lightweight interface shopping cart, that supports adding/removing cart items and basic sum calculations. Dead simple and very easy to implement.

AtomCart is hosted on Github, so you can find it here: https://github.com/marteinn/AtomCart

AS3Flobile: Altering the ScrollList dataProvider without forcing a scroll position reset.

(October 25th, 2010)

I was working with the AS3Flobile component ScrollList (its a great framework when doing mobile flash-development) and had the need to modify the dataProvider (I was making a continuous scroller), but everytime I changed the dataProvider the scroller would reset the scroll-position to x = 0, y = 0. After a little tinkering, I came up with a quick and dirty way to force the ScrollList to move to a position without a animation, and by doing so, making sure that the scroller starts at the same position as where we left off.

Of course, if anyone has a better solution, just post a comment at the end of this post!

Here it goes.

1. First we need to extend the BaseScrollViewportStrategy class. This could look something like this:

package se.marteinn.app.controls.viewport.context
{
        import com.custardbelly.as3flobile.controls.viewport.context.BaseScrollViewportStrategy;
        import com.custardbelly.as3flobile.controls.viewport.context.IScrollViewportStrategy;
       
        import flash.geom.Point;
       
        public class CustomScrollViewportStrategy extends BaseScrollViewportStrategy implements IScrollViewportStrategy
        {
                public function moveToStaticPoint( point:Point ):void
                {
                        _currentScrollPositionX = point.x;
                        _currentScrollPositionY = point.y;
                       
                        _coordinate.x = _currentScrollPositionX;
                        _coordinate.y = _currentScrollPositionY;
                }
        }
}

2. Then we need to extend ScrollList and add this method: moveToStaticPoint and then override getDefaultScrollContext.

// This method sets a new scrolling position on both the ScollList itself and the strategy instance.
public function moveToStaticPoint ( point:Point ) : void
{
        var strategy:CustomScrollViewportStrategy;                     
        strategy = _scrollContext.strategy as CustomScrollViewportStrategy;
               
        _currentScrollPosition = point;
        strategy.moveToStaticPoint( point );
        _listHolder.x = point.x;
        _listHolder.y = point.y;
}

// And this method makes sure that we implement the new strategy element.
override protected function getDefaultScrollContext():IScrollViewportContext
{
        return new ScrollViewportMouseContext( new CustomScrollViewportStrategy() );
}

3. After that. You can use ScrollList like this.

var scrollList:MyScrollList;

// Dump the scrollPosition (clone() is important). We will use this position after the dataProvider has changed
position = scrollList.scrollPosition.clone();

// Do your stuff. for instance alter the dataProvider of the scroll list
// scrollList.dataProvider = updatedContent;

// Finish it off by running the moveToStaticPoint method. The ScrollList will now be set at the same position as where we started.
scrollList.moveToStaticPoint( position );

Finding your Google App Engine directory under OSX (with GoogleAppEngineLauncher installed)

(October 3rd, 2010)

I stumbled upon this dilemma when I was trying to create a pydev google app engine project in the AptanaStudio 3 edi, to complete the wizard I had to set my google app engine directory.

After a bit of searching, I realized that the “google_appengine” directory was not placed in public on my harddrive, but hidden inside the GoogleAppEngineLauncher.app package (right klick on the application – choose show content).

So, if you run GoogleAppEngineLauncher on your mac, the path to your google app engine root is this:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/

Android: InteractiveScrollView

(June 4th, 2010)

This post is a simple follow up to Android: Understanding when ScrollView has reached the bottom where I have created a small plug and play widget which notifies when scroll bottom has been reached through a listener.

It works like this: InteractiveScrollView inherits from ScrollView and overrides onScrollChanged to validate scroll position. If bottom has been reached, onBottomReachedListener triggers.

Usage:

InteractiveScrollView scrollView;    

scrollView = (InteractiveScrollView) findViewById( R.id.scrollView);
scrollView.setOnBottomReachedListener(new InteractiveScrollView.OnBottomReachedListener() {
                @Override
                public void onBottomReached()
                {
                        // bottom reached
                }
});

View the class or download it here.

Android: Understanding when ScrollView has reached the bottom

(May 12th, 2010)

This snippet is pretty mutch as the title says, an example in detecting when ScrollView has reached the bottom. In this sample I extend ScrollView and then overrides the onScrollChanged method (inherited from View).

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
        // Grab the last child placed in the ScrollView, we need it to determinate the bottom position.
        View view = (View) getChildAt(getChildCount()-1);
       
        // Calculate the scrolldiff
        int diff = (view.getBottom()-(getHeight()+getScrollY()));
       
        // if diff is zero, then the bottom has been reached
        if( diff == 0 )
        {
                // notify that we have reached the bottom
                Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
        }

        super.onScrollChanged(l, t, oldl, oldt);
}

Cheers to this thread for helping me getting the calculations right.

Patching NetStreamClient

(February 14th, 2010)

I couple of days ago I noticed that my conceptual NetStreamClient was failing when connecting it towards a NetStream, the debugger threw errors regarding missing a Proxy implementation of getProperty.

The problem was when building the class I took for granted that NetStream referenced against the client object and invoked the callback function from the object when a callback took place. But the fact is that when you assign a client object to netstream it saves a reference to the callback function, not the client object itself. So it was clear why my class didnt work.

So I patched it up with the proxy implementation getProperty (it looks a bit hackish but it does the trick).

flash_proxy override function getProperty(name:*) : *
{
        var qName:QName = name as QName;
       
        return function ( args ) : void
        {
                flash_proxy::callProperty( qName, args[0] );
        }
}

I also noticed that in my usage example I used an object instead of the NetStreamClientEvent. So this is how you “really” use it.

// create a instance
client = new NetStreamClient();
// assign the client
netStream.client = client;
// then just add listeners to the client
client.addEventListener( NetStreamClientEvent.CUE_POINT, client_cuePointHandler );

// an example of the handler function
function client_cuePointHandler ( event:NetStreamClientEvent ) : void
{
        // the info object holds the original data
        var info:Object;
                       
        info = event.arguments[0];
                       
        trace( [info.name, info.time, info.cuetype] );
}

Updated classes here: Download it here here, or view the NetStreamClient class here.

Note to self: Connecting MySQL with Django using Mamp in OSX

(February 14th, 2010)

Having trouble connecting your MAMP mysql database wth django?

Add the path DATABASE_HOST and connect it towards

{path to your MAMP directory}/tmp/mysql/mysql.sock

So my connection is for instance

DATABASE_HOST = ‘/Applications/MAMP/tmp/mysql/mysql.sock’

And the full mysql settings for for django

DATABASE_ENGINE = ‘mysql’ # ‘postgresql_psycopg2′, ‘postgresql’, ‘mysql’, ‘sqlite3′ or ‘oracle’.
DATABASE_NAME = ‘mydb’ # Or path to database file if using sqlite3.
DATABASE_USER = ‘root’ # Not used with sqlite3.
DATABASE_PASSWORD = ‘root’ # Not used with sqlite3.
DATABASE_HOST = ‘localhost’ # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ’8888′ # Set to empty string for default. Not used with sqlite3.
DATABASE_HOST = ‘/Applications/MAMP/tmp/mysql/mysql.sock’

Its straightforward, but good to know, since adding the mysql.sock file in a folder named tmp seems a bit odd.

A nicer way of using NetStream.client

(January 11th, 2010)

* UPDATE: This class has been patched

After working with the NetStream class for quite some time it has always striken me how badly the “client” approach is.

Default behaviour

netStream.client = {onCuePoint:myCuePointCallback};

function myCuePointCallback ( point:Object ) : void
{
}

Basicly to retrive a cue point we have to assign the client property with a object populated with a needed set of callback functions, that in the end will be triggered by the NetConnection class. You rarely see this callback mechanism in as3 and it can easly get a bit confusing, mainly beacuse you need to remember the callback function names.

So I made a specific client class for NetStream which extends the Proxy util and converts the callbacks into actual events with EventDispatcher. It works like this.

Usage

// create a instance
client = new NetStreamClient();

// assign the client
netStream.client = client;

// then just add listeners to the client
client.addEventListener( NetStreamClientEvent.CUE_POINT, client_cuePointHandler );
client.addEventListener( NetStreamClientEvent.META_DATA, client_metaDataHandler );

// an example of the handler function
function client_cuePointHandler ( info:Object ) : void
{
        trace( [info.name, info.time, info.cuetype] );
}

The NetStreamClient covers the most used callbacks (such as metadata, play status), and the callbacks it cannot identify gets labeled as a Unknown call.

Try it out and just shout if you have any comments!
Download it here here, or view the NetStreamClient class here.

/ Martin

Dealing with the NetStatus info codes

(November 16th, 2009)

I never liked dealing with the NET_STATUS info codes that NetStream generates, beacuse I always forget the different codes. And there is no built in class which holds the string constant as representations for the different codes. So I basicly did a very simple wrapping of the status codes from the Adobe Reference into a simple to use class.

Usage

protected function netStream_netStatus ( event:NetStatusEvent ) : void
{
        switch( event.info.code )
        {
                case NetStatusConstants.NETSTREAM_PLAY_START:
                        trace("Start!");
                        break;
        }
}

So if you are like me, with a memory like a pacific sea turtle, this might come in handy. Download it here here, or view the class here.