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

Dismiss the keyboard on a background tap or table cell tap.

You can use the following code to dismiss the keyboard when you tap the background or a tableview cell. The cell selection should still work as expected.

- (void)viewDidLoad
{
    // .......
    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTap)];
    gestureRecognizer.cancelsTouchesInView = NO;
    [self.tableView addGestureRecognizer:gestureRecognizer];
    [gestureRecognizer release];
}
 
- (void)backgroundTap 
{
    // resign the first responder of all your textfields
    [myTextField resignFirstResponder];
    [aTextField resignFirstResponder];
    [anotherTextField resignFirstResponder];
}
Posted in iOS Development | Leave a comment

iOS: Getting and Setting Properties on the Application Delegate

To set a property on your application delegate from anywhere in you code:

[(SomeAppDelegate *)[[UIApplication sharedApplication] delegate] setFoobar:aFoobar];

And to read back the property:

NSString *myFooBar = [(SomeAppDelegate *)[[UIApplication sharedApplication] delegate] foobar];
Posted in iOS Development | Tagged , , | Leave a comment

Fix the Worldpay Magento Extension for Magento v1.4 and newer.

There is a community extension developed by Phoenix Maiden for the integration of RBS Worldpay payment gateway into the Magento ecommerce system. However, due to changes in the templating engine, it doesn’t work for newer versions of Magento.

This is how I fixed it for Magento version 1.4.2.0. I am using version 1.3.1 of the worldpay extension.

By default, Magento connect installs some files to an incorrect location.

To fix move the directory:

app/design/frontend/default/default/template/worldpay

to

app/design/frontend/base/default/template/worldpay

and the file

app/design/frontend/default/default/layout/worldpay.xml

to

app/design/frontend/base/default/layout/worldpay.xml

Refresh your cache and the extension should now work correctly.

Posted in Magento | Tagged | Leave a comment

Formatting date strings from NSDate

These two static methods are useful for returning a formatted date string from an NSDate object. The first method takes both NSDate and your format NSString.

The second calls the first method and passes in a default formatting string.

+ (NSString *)getFormattedDateString:(NSDate *)date:(NSString *)format {
 
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:format];
 
    return [dateFormatter stringFromDate:date];
}
 
+ (NSString *)getFormattedDateString:(NSDate *)date {
    return [self getFormattedDateString:date:@"dd/MM/YYYY"];
}
Posted in iOS Development | Tagged , , , | Leave a comment

Use NSNumberFormatter to get a formatted currency string from NSNumber

This static method will return a properly formatted UK currency string from the value of an NSNumber object.

+ (NSString *)getPriceFromNumber:(NSNumber *)value {
 
    NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
    [formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [formatter setCurrencySymbol:@"£"];
 
    return [formatter stringFromNumber:value];
}
Posted in iOS Development | Tagged , , , | Leave a comment

OS X Terminal Colours

To enable file type/permission colours in your OSX terminal, create the file .bash_profile in your home directory and add:

export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

I have used the same file for my other linux systems.

Posted in Shell | Tagged , , , | Leave a comment

Enable VIM Syntax Highlighting, Smart Indents, Backspace Key and more…

In your home directory create the file .vimrc with the content:

syntax on
highlight Comment term=bold ctermfg=6 guifg=Cyan
highlight Special term=bold ctermfg=6 guifg=Cyan
 
set showmode
set tabstop=2
set shiftwidth=2
set expandtab    
set ruler
set nowrap
set smartindent
set backspace=2
set nobackup

I have used this file on Ubuntu and OS X. For a full description of the options in this config file see the VIM options docs.

Posted in Shell | Tagged , , , | Leave a comment

Add ellipsis text truncating support for firefox

Create the following XML file:

<?xml version="1.0"?>
    <bindings xmlns="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
    <binding id="none">
        <content><children/></content>
    </binding>
 
    <binding id="ellipsis">
        <content>
            <xul:label crop="end"><children/></xul:label>
        </content>
        <implementation>
            <field name="label"> document.getAnonymousNodes( this )[ 0 ] </field>
            <field name="style"> this.label.style </field>
            <property name="display">
                <getter> this.style.display </getter>
                <setter> if( this.style.display != val ) this.style.display= val </setter>
            </property>
            <property name="value">
                <getter> this.label.value </getter>
                <setter> if( this.label.value != val ) this.label.value= val </setter>
            </property>
            <method name="update">
                <body>
                    var strings= this.textContent.split( /\s+/g )
                    if( !strings[ 0 ] ) strings.shift()
                    if( !strings[ strings.length - 1 ] ) strings.pop()
                    this.value= strings.join( ' ' )
                    this.display= strings.length ? '' : 'none'
                </body>
            </method>
            <constructor> this.update() </constructor>
        </implementation>
        <handlers>
            <handler event="DOMSubtreeModified"> this.update() </handler>
        </handlers>
    </binding>
 
    </bindings>

And in your CSS rule for the element in question, where the bindings.xml is the file your created above.

.some-element {
    text-overflow: ellipsis;
    -moz-binding: url( 'bindings.xml#ellipsis' );
    white-space: nowrap;
    overflow: hidden;
}

Now you have text overflow ellipsis support for IE, chrome, safari and firefox.

Opera users have the -o-text-overflow: ellipsis; too.

This technique was originally found on this blog.

Posted in Web Development | Leave a comment

Text overflow with ellipsis on table cells without inner elements

Using the following CSS rules to have IE/webkit browsers apply an ellipsis on table cells text overflows is well documented.

table { table-layout: fixed; }
table td { 
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

However, you cannot set a width on the last column of the table if you want IE6/7 to correctly apply the ellipsis. Instead, set widths on your other columns and on the table itself for to get the desired layout.

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