Tag Archive for application

Relaunch an application

// gcc -Wall -arch i386 -arch ppc -mmacosx-version-min=10.4 -Os -framework AppKit -o relaunch relaunch.m

#import <AppKit/AppKit.h>

@interface TerminationListener : NSObject
{
const char *executablePath;
pid_t parentProcessId;
}

- (void) relaunch;

@end

@implementation TerminationListener

- (id) initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid
{
self = [super init];
if (self != nil) {
executablePath = execPath;
parentProcessId = ppid;

// This adds the input source required by the run loop
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationDidTerminate:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
if (getppid() == 1) {
// ppid is launchd (1) => parent terminated already
[self relaunch];
}
}
return self;
}

- (void) applicationDidTerminate:(NSNotification *)notification
{
if (parentProcessId == [[[notification userInfo] valueForKey:@"NSApplicationProcessIdentifier"] intValue]) {
// parent just terminated
[self relaunch];
}
}

- (void) relaunch
{
[[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:executablePath]];
exit(0);
}

@end

int main (int argc, const char * argv[])
{
if (argc != 3) return EXIT_FAILURE;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[[[TerminationListener alloc] initWithExecutablePath:argv[1] parentProcessId:atoi(argv[2])] autorelease];
[[NSApplication sharedApplication] run];

[pool release];

return EXIT_SUCCESS;
}

source

My initialize cart

# Initialize shopping cart.
def initialize_cart
# #1
# --
# if session[:cart_id]
#  @cart = Cart.find(session[:cart_id])
# else
#  @cart = Cart.create
#  session[:cart_id] = @cart.id
# end

# #2
# --
# if session[:cart]
#  @cart = session[:cart]
# else
#  @cart = Cart.create
#  session[:cart] = @cart
# end

# #3
@cart = session[:cart] ||= Cart.create
end

source

Current user

protected
def current_engineer
Engineer.find(session[:user])
end

def current_user
Employee.find(session[:user])
end

def check_user_authentication
unless session[:user]
redirect_to :controller => 'account', :action => 'login'
end
end

source

Add RubyOnRails application to svn repository

svn add . --force
svn ci -m "initial rails import"
svn up
svn remove log/*
svn commit -m "removing all log files from subversion"
svn propset svn:ignore "*.*" log/
svn update log/
svn ci -m "Ignoring all files in /log/ ending in .log"
svn up
svn add config/lighttpd.conf
svn ci -m "added lighttpd conf file"
svn up
svn move config/database.yml config/database.example
svn commit -m "Moving database.yml to database.example to provide a template for anyone who checks out the code"
svn propset svn:ignore "database.yml" config/
svn update config/
svn commit -m "Ignoring database.yml"
svn remove tmp/*
svn propset svn:ignore "*" tmp/
svn update tmp/
svn commit -m "ignore tmp/ content from now"

source

Create a new svn Repository for new RoR application

mkdir ~/src/appName
svnadmin create ~/src/appName
cd ~/
mkdir ~/tmp
mkdir ~/tmp/branches
mkdir ~/tmp/tags
mkdir ~/tmp/trunk
svn import ~/tmp <a href="file:///Users/spider/src/appName" >file:///Users/spider/src/appName</a> -m "initial import"
rm -r ~/tmp
cd ~/Documents/RubyOnRails
svn checkout <a href="file:///Users/spider/src/appName/trunk" >file:///Users/spider/src/appName/trunk</a> appName

source