File and folder permissions using Access Control Lists

Access Control Lists allow you to define user permissions on files in a fine grained way. For example, if Apache needs write permission on a folder – but you want to retain your own permissions for also writing to that folder from command line scripts – ACL is the answer.

chmod +a
For systems that support chmod +a (i.e. OSX, in this case the apache web server: _www user)

sudo chmod +a "_www allow delete,write,append,file_inherit,directory_inherit" /Users/deano/tmp

setfacl
For systems that support setfacl (i.e. Ubuntu)

sudo setfacl -R -m u:www-data:rwx -m u:yourname:rwx /home/deano/tmp
Posted in Shell | Tagged , , | Leave a comment

GIT ignore file for xcode4 projects

My current GIT ignore file for xcode4 projects

 
.DS_Store
*.swp
*~.nib
build/
*.pbxuser
*.perspective
*.perspectivev3
*.xcodeproj/xcuserdata/*
*.xcodeproj/project.xcworkspace/xcuserdata/*
Posted in Git | Tagged , | Leave a comment

GIT ignore file for Symfony2

My current GIT ignore file for symfony2 projects:

# symfony files
.DS_Store
vendor/*
app/cache/*
app/logs/*
*~
 
# config files to ignore
app/config/parameters.ini
 
# eclipse PDT files
.buildpath
.project
.settings
Posted in Git | 1 Comment

ExtJS 3.3 error this.addEvents is not a function ‘statesave’

If you get something similar to the above error message in firebug while developing with Ext 3.3, a common cause if you have tried to create a component when omitting the new keyword.

var dv = Ext.DataView({...});  // incorrect
 
var dv = new Ext.DataView({...}); // correct
Posted in Web Development | Tagged , | 1 Comment

Custom text in the back button for a UINavigationController

The simple way to customise the back button text in the navigation bar. Add this code in your parent view controller.

- (void)viewDidLoad
{
    [super viewDidLoad];
 
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];
}
Posted in iOS Development | Tagged , , | Leave a comment

UITableView static background image

The easy way to achieve a static background image with a scrolling UITableView:

- (void)viewDidLoad
{
    [super viewDidLoad];
 
    self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
    self.tableView.backgroundColor = [UIColor clearColor];
}
Posted in iOS Development | Tagged , , | Leave a comment

Application crashing with “NSCFType controllerWillChangeContent” when using NSFetchedResultsController

I was using a UITableViewController that implemented the NSFetchedResultsControllerDelegate protocol. When navigating to this view, and then to another my application would crash with an error message something like:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance

I finally tracked down the problem to be that I was releasing the UITableViewController with releasing the delegate of NSFetchedResultsController.

So my code now reads:

- (void)viewDidLoad
{
    // ......
    NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    controller.delegate = self;
    self.fetchController = controller;
    [controller release];
    // ......
}
 
- (void)dealloc
{
    self.fetchController.delegate = nil;  // Set the delegate to nil
    [fetchController release];
    [super dealloc];
}

Note how I set the NSFetchedResultsController delegate to nil before releasing it. This solved my problem.

Posted in iOS Development | Tagged , , , , | Leave a comment

Flush the DNS Cache in Snow Leopard OS X 10.6 and above

To clear your DNS cache typpe in terminal

dscacheutil -flushcache
Posted in Shell | Tagged , | Leave a comment

Delete all test order data from Magento

These commands can be pasted into PHPMyAdmin, or some similar client. Tested on Magento version 1.4.2.0

SET FOREIGN_KEY_CHECKS=0;
 
TRUNCATE sales_flat_order;
TRUNCATE sales_flat_order_address;
TRUNCATE sales_flat_order_grid;
TRUNCATE sales_flat_order_item;
TRUNCATE sales_flat_order_status_history;
TRUNCATE sales_flat_quote;
TRUNCATE sales_flat_quote_address;
TRUNCATE sales_flat_quote_address_item;
TRUNCATE sales_flat_quote_item;
TRUNCATE sales_flat_quote_item_option;
TRUNCATE sales_flat_order_payment;
TRUNCATE sales_flat_quote_payment;
TRUNCATE sales_flat_shipment;
TRUNCATE sales_flat_shipment_item;
TRUNCATE sales_flat_shipment_grid;
TRUNCATE sales_flat_invoice;
TRUNCATE sales_flat_invoice_grid;
TRUNCATE sales_flat_invoice_item;
TRUNCATE sendfriend_log;
TRUNCATE tag;
TRUNCATE tag_relation;
TRUNCATE tag_summary;
TRUNCATE wishlist;
TRUNCATE log_quote;
TRUNCATE report_event;
 
ALTER TABLE sales_flat_order AUTO_INCREMENT=1;
ALTER TABLE sales_flat_order_address AUTO_INCREMENT=1;
ALTER TABLE sales_flat_order_grid AUTO_INCREMENT=1;
ALTER TABLE sales_flat_order_item AUTO_INCREMENT=1;
ALTER TABLE sales_flat_order_status_history AUTO_INCREMENT=1;
ALTER TABLE sales_flat_quote AUTO_INCREMENT=1;
ALTER TABLE sales_flat_quote_address AUTO_INCREMENT=1;
ALTER TABLE sales_flat_quote_address_item AUTO_INCREMENT=1;
ALTER TABLE sales_flat_quote_item AUTO_INCREMENT=1;
ALTER TABLE sales_flat_quote_item_option AUTO_INCREMENT=1;
ALTER TABLE sendfriend_log AUTO_INCREMENT=1;
ALTER TABLE sales_flat_order_payment AUTO_INCREMENT=1;
ALTER TABLE sales_flat_quote_payment AUTO_INCREMENT=1;
ALTER TABLE sales_flat_shipment AUTO_INCREMENT=1;
ALTER TABLE sales_flat_shipment_item AUTO_INCREMENT=1;
ALTER TABLE sales_flat_invoice AUTO_INCREMENT=1;
ALTER TABLE sales_flat_invoice_grid AUTO_INCREMENT=1;
ALTER TABLE sales_flat_invoice_item AUTO_INCREMENT=1;
ALTER TABLE sales_flat_shipment_grid AUTO_INCREMENT=1;
ALTER TABLE tag AUTO_INCREMENT=1;
ALTER TABLE tag_relation AUTO_INCREMENT=1;
ALTER TABLE tag_summary AUTO_INCREMENT=1;
ALTER TABLE wishlist AUTO_INCREMENT=1;
ALTER TABLE log_quote AUTO_INCREMENT=1;
ALTER TABLE report_event AUTO_INCREMENT=1;
 
TRUNCATE customer_address_entity;
TRUNCATE customer_address_entity_datetime;
TRUNCATE customer_address_entity_decimal;
TRUNCATE customer_address_entity_int;
TRUNCATE customer_address_entity_text;
TRUNCATE customer_address_entity_varchar;
TRUNCATE customer_entity;
TRUNCATE customer_entity_datetime;
TRUNCATE customer_entity_decimal;
TRUNCATE customer_entity_int;
TRUNCATE customer_entity_text;
TRUNCATE customer_entity_varchar;
TRUNCATE log_customer;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
ALTER TABLE customer_address_entity AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE customer_entity AUTO_INCREMENT=1;
ALTER TABLE customer_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE log_customer AUTO_INCREMENT=1;
ALTER TABLE log_visitor AUTO_INCREMENT=1;
ALTER TABLE log_visitor_info AUTO_INCREMENT=1;
 
TRUNCATE eav_entity_store;
ALTER TABLE eav_entity_store AUTO_INCREMENT=1;
 
SET FOREIGN_KEY_CHECKS=1;
Posted in Magento | Leave a comment

Secure VNC to a remote machine from OS X via a corporate HTTP proxy with SSH and Corkscrew

Using this technique I was about to VNC securely to a remote machine via an SSH tunnel. I used corkscrew to send my SSH connection over a corporate HTTP proxy, bypassing the firewall.

Disclaimer: Don’t blame me if you get sacked for this!

Assuming you have corkscrew already installed… (if not, you can install it easily via macports)

Create an entry in your ~/.ssh/config file – this will save you a LOT of typing in future….This version assumes you are using standard ports for your VNC connection. And the remote machine is on a remote LAN.

Host remotehost
	HostName example.com
		Port	22
		User	joebloggs
		IdentityFile ./id_rsa_key  // only include if you use private key authentication
		ProxyCommand corkscrew proxyhost.com 8080 %h %p  // replace 8080 with your proxy server port
		LocalForward 5901 192.168.0.99:5901  // where 192.168.0.99 is the remote machine LAN IP

Make sure the VNC server is running on the remote machine (assuming screen 1 above).

Connect to the remote client:

ssh remotehost

Launch Safari, and type in the address bar vnc://127.0.0.1:5901 and the screen sharing program and connect to the remote machine.

Posted in Networking | Tagged , , | Leave a comment