Boher Architecture iPhone app now available on iTunes

An app I recently built for Boher Architecture in Midhurst just went live on the iStore! You can get it for free from itunes.apple.com/us/app/boher/id539358624?ls=1&mt=8.

It features;

  • Categorised Unit Converter covering Length, Area, Distance, Mass and many more!
  • A graphical roof pitch calculator
  • A complete set of UK building regs for reference, available when you’re on site, even without mobile signal
  • Portfolio and contact details for Boher Architecture

Boher Architecture can also be contacted via their, soon-to-be-launched website at www.boherarchitecture.com

No Comments

Why you should use var in your for loop control variables

Had a conversation recently about JavaScript and the importance of var for scoping your variables- even in for-loop control variables; This little gotcha still seem’s to get a few devs so thought I would post a fiddle…

http://jsfiddle.net/shawson/gH4KC/5/

1 Comment

Undo checkout for unchanged files in TFS 2010

This is a really annoying one- I’ll often open files and not make any changes, but perhaps hit save out of habit making TFS check the file out. It will then hang about in pending changes until I manually go through the entire list checking each file for changes, only for TFS to helpfully inform me the files are identical! If you have TFS power tools you can run the following from a command line (having cd’ed to your solutions directory);

tfpt uu /recursive /noget

This will check all files and ask if you wish to undo checkout for identical files. Simples. But even simpler.. I found this article on Antoine Aubry’s blog detailing how to create a menu item in visual studio making this impossibly easy!

The balls of it (incase the site ever disappears!) is to go to tools> external tools> and then add a new item with the following configuration;

Title &Undo fake changes
Command %windir%\System32\cmd.exe
Arguments /C echo y | “%ProgramFiles(x86)%\Microsoft Team Foundation Server 2010 Power Tools\TFPT.EXE” uu /recursive /noget
Initial directory $(SolutionDir)

1 Comment

Rotating child UIView when parent UITabBar or UINavigationController isn’t rotatable!

I’m building an app at the moment, with what is most likely a pretty fairly use case. It is a tab based app (Using StoryBoard/ iOS5.0/ XCode 4.3.2) , so at the top I have a UITabBarController, UINavigationController’s coming off of a few different tabs, then UIViewControllers coming off of those.

I DON’T want the home screen’s to be rotatable, but I do want one of my child UIView’s (a picture gallery, of course!) to be rotatable.

My UITabBarController at the root of the application had the following method;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

This will make sure the views at the top don’t rotate, so I figured I would just add add the following to my gallery view controller to make just that one rotatable;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{   
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

But I found nothing happened when I rotated. I set a bunch of break points and found the method in my gallery detail controller wasn’t even hit, but the parent TabBarControllers method was still being hit. The trouble is, you can’t rotate a view unless it’s parent is marked as rotatable.

After some head scratching, the solution was actually pretty simple- I created a switch on my root TabBarController “allowRotation”, then adjust the shouldAutorotateToInterfaceOrientation method in the tabBarController to;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (self.allowRotation)
        return YES;
    else
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Then in my gallery detail view I set that switch to true when you enter the view;

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    RootTabBarController *tabcontrol = (RootTabBarController*)[self tabBarController];
    tabcontrol.allowRotation = YES;
}

And when you click the back button at the top of the view, I quickly set the switch back to false;

- (void)willMoveToParentViewController:(UIViewController *)parent
{
    RootTabBarController *tabcontrol = (RootTabBarController*)[self tabBarController];
    tabcontrol.allowRotation = NO;
}

I tried doing this on viewWillDisappear and a bunch of other methods, but found none of them fired early enough to get in there before the back button fired off it’s magic to prepare the parent views rotation.

NOTE: Make sure you’re app has rotation enabled in the Project Target “Summary” sheet, otherwise none of this will work!

2 Comments

CSV Export from MySQL Command line (Windows/Linux)

select col1, col2, col3
INTO OUTFILE 'c:/dump.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
from tblA a inner join tblB b on a.col1 = b.col2;

No Comments

Highcharts- Highlight the last clicked bar

This is handy, only really if you have charts which, on click, have drill down data which pops up, perhaps in a table underneath or something- I basically just wanted to highlight the last clicked column in a column chart;

Check it out on jsFiddle : http://jsfiddle.net/shawson/CkkbF/8/

2 Comments

MVC3/Webforms app using forms authentication – CSS & Images folder not accessible before login

This is very usually embarrassingly simple. You have a site which is locked down using forms authentication, but your login page needs the css and images- so you add settings to your web config telling the app only authenticated users can come in, but no one else can- then you add a couple of exceptions for your specific folders- like so;

<configuration>
	<system.web>
		<authentication mode="Forms" >
			<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
			</forms>
		</authentication>
<!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
		<authorization>
			<deny users="?" /> 
		</authorization>
	</system.web>
<!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
		<location path="default1.aspx">
		<system.web>
		<authorization>
			<allow users ="*" />
		</authorization>
		</system.web>
		</location>
<!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder.  -->
		<location path="subdir1">
		<system.web>
		<authorization>
			<allow users ="*" />
		</authorization>
		</system.web>
		</location>
</configuration>

This is documented on the MSDN on this article.

I just deployed an existing site to a new dev server and found everything ran fine, except the css and images would not load on the login page, despite me having the exception in the web.config.

After lots of Googling (most articles simply explain that you need the above exception’s in your config!) I found this little gem which explained I needed to;

  1. Open the IIS7.5 control panel
  2. Select the application
  3. double-click “Authentication”
  4. select “Anonymous Authentication”, then Edit
  5. change it to use the Application Pool Identity. Make sure that user has permissions on the folder that contains the site

No Comments

Switching from ObjectContext to DbContext in your Entity Framework EDMX File

Tres easy and much cleaner classes turfed out the other end;

http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx

2 Comments

Recursive jQuery Drop Down Menu’s

Following on from my previous post about drop downs, I recently expanded the code to allow for sub menus- as many levels deep as you would like.

The Code:

$(document).ready(function () { // Shawsons' Teeny-Tiny Recursive Drop Downs!
    $('.drop-down-menu>li>ul').hide().mouseleave(function () {
        $('.highlighted', this).removeClass('highlighted');
        $(this).hide();
    });
    $('.drop-down-menu li>a').mouseenter(function () {
        var menu_root = $(this).parent().parent();
        $('ul', menu_root).hide();
        $('.highlighted', menu_root).removeClass('highlighted');
        $('>ul', $(this).addClass('highlighted').parent()).show();
    }).mouseleave(function (o) {
        if ($(this).parent().has($(o.relatedTarget)).length < 1) {
            $('ul', $(this).parent()).hide();
        }
    });
});

The Markup:

<ul class="drop-down-menu">
        <li>Drop Down Menu - Demo Title : </li>
        <li><a href="">Menu 1</a>
            <ul>
                <li><a href="a.htm">a</a></li>
                <li><a href="b.htm">b</a></li>
                <li><a href="c.htm">c &raquo;</a>
                    <ul>
                        <li><a href="c-a.htm">c-a</a></li>
                        <li><a href="c-b.htm">c-b &raquo;</a>
                          <ul>
                              <li><a href="c-b-a.htm">c-b-a</a></li>
                              <li><a href="c-b-b.htm">c-b-b &raquo;</a>
                                  <ul>
                                      <li><a href="c-b-b-a.htm">c-b-b-a</a></li>
                                  </ul>
                              </li>
                          </ul>
                        </li>
                        <li><a href="c-c.htm">c-c</a></li>
                    </ul>
                </li>
            </ul>
        </li>
        <li><a href="">Menu 2</a>
            <ul>
                <li><a href="d.htm">d</a></li>
                <li><a href="e.htm">e</a></li>
                <li><a href="f.htm">f</a></li>
            </ul>
        </li>
    </ul>

Some CSS:


.drop-down-menu { display:block; }
.drop-down-menu li { float:left; padding: 8px; }
.drop-down-menu>li>a { padding:8px; }
.drop-down-menu li ul  
{
    position:absolute; 
    background-color:#fff; 
    border: 1px solid #999;
    border-radius: 0px 7px 7px 7px; -moz-border-radius:0px 7px 7px 7px; -webkit-border-radius:0px 7px 7px 7px;
    padding:5px; 
    width: 50px;
}
.drop-down-menu li ul a {
   display:block;
   width:50px;
}
.drop-down-menu li ul li ul 
{
    margin-left:50px;
    margin-top: -20px;
}
.drop-down-menu li ul li { float:none; }
.drop-down-menu li ul li a { color:#000; }
.drop-down-menu li ul a.highlighted { background-color:#F68833; }

Demo :

 

2 Comments

Adding cross browser consistent keyboard short-cuts to your website

I wanted to employ keyboard short cuts to a frequently used internal web app used within the company- Pinch o’ the proverbial piss I thought- I’ll just use access keys! I’ve used them before on front facing sites for accessibility- but when I actually came to document these keys for the users I realised that support across different browsers is a mess;

IE Alt + {key}then hit return
Firefox Alt + Shift + {key}
Chrome Alt + {key} (the most sensible implementation, in my opinion)

IE also seems to refuse to aknowlege the links unless they are currently visible, and as the options I was short cutting existed in drop down menus this was no good, as they existing in bulleted lists which are “display:none” until the user mouses-over the menu bar (using my tiny drop down menu code)!

So to get around this I wrote some jQuery which standardises the short cuts- note this is no good for normal accessibility uses as it’s a new key combo which none of the browsers use, so without documentation no one will know- but for my use on an internal system it’s perfect.

I took the decision to make all the short cuts Ctrl+Alt+{key}, and wanted to keep using the accesskey attribute on my links rather than introduce another mechanism for dictating which keys triggered what- I also wanted to ensure if the link had a javascript onclick handler, instead of navigating away, we respect the handler and simply trigger that. Here’s the code;

$(document).keydown(function(e) {
	if (e.ctrlKey && e.altKey && e.which >= 65 && e.which <= 122) {
		e.preventDefault();
		
		var key = String.fromCharCode(e.which);
		var the_link = $("a[accesskey=" + key.toLowerCase() + "]");
		
		if (typeof(the_link) != 'undefined') {
			// does this link have a javascript assigned click handler, or do we simply send the user to the links href value?
			var events = $.data( $(the_link).get(0), 'events' );
			if (typeof(events) != 'undefined') {
				if (typeof(events.click) != 'undefined') {
					$(the_link).click();
					return;
				}
			}
			window.location = $(the_link).attr('href');
		}
	}
});

1 Comment