tag:blogger.com,1999:blog-40208062380512307072024-02-19T01:37:24.483-08:00Triple Shot SoftwareHi, I'm Paul Norton.
I'm a software developer who has had the privilege of working on a vast number of technologies, stuff from desktop applications, to multi-tier web applications, to mobile applications.
I have my own company, but really this blog isn't so much about my company as my personal development interests and discoveries.
I guess you could say this blog is targeted to colleagues, not clients.Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-4020806238051230707.post-49696838603217821652013-04-01T15:22:00.001-07:002013-04-02T08:39:29.921-07:00Cocos2D & CocosBuilder - tools for building a great iOS user experienceI have used cocos2d-iphone for apps that need a game-like feel, those apps where good ole' Cocoa Touch felt a little too utilitarian. Recently I discovered, downloaded, and tried out CocosBuilder (<a href="http://www.cocosbuilder.com/">http://www.cocosbuilder.com</a>) and I've got to say I'm really pleased. It would have been a big help for some of those past projects that use cocos2d-iphone.<br />
<br />
I've been playing around with it for a couple of days & have decided that I need to put it to use in a project. It seems to be a great tool for building unique user interfaces for iOS apps. It appears to also support Android, and desktop applications, but for my first project or two I think I'm going to focus on using it for iOS.<br />
<br />
I'll post my experiences as I put together a project using CocosBuilder, but as this is a pet project updates may be a little slow at times.<br />
<br />
The tool does seem to either be missing some features, or have them well hidden. The item that comes to mind immediately is the ability to add screen sizes to a project after the project has been created (you choose screen sizes when you create the project, but I didn't see any way to add or remove screen sizes later.)Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0tag:blogger.com,1999:blog-4020806238051230707.post-85660948767238323452013-02-21T14:17:00.000-08:002013-02-21T14:17:48.030-08:00Picking up Node.jsOver the last 6 to 9 months I've started playing around with <a href="http://nodejs.org/">Node.js</a>. Node.js has often been described as "server-side" but really it's about using a javascript engine in all the places you might want to use Javascript, but don't want the browser.<br />
<br />
Node is <a href="http://www.commonjs.org/">CommonJS</a> implementation. You can run code server-side, you can make command-line tools, I'm sure there is other stuff you can do with it too.
<br />
<br />
A good place to start learning Node is <a href="http://www.nodebeginner.org/">The Node Beginner Book</a> at least for me it was a great starting point.Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0tag:blogger.com,1999:blog-4020806238051230707.post-19307883447697229452013-02-13T10:33:00.000-08:002013-02-13T11:26:24.518-08:00Stop the Android "bounce" on Cordova (PhoneGap) based projectsJeremy asked how to stop the bounce on android projects that use the WebView.<br />
<br />
What you need to do is add a little bit of code to your Java class that extends DroidGap.<br />
<br />
First, add an import for adroid.view.View:<br />
<pre>import android.view.View;
</pre>
<br />
<br />
Then, you need to make a call to 'setOverScrollMode' - however this call is only available on android 2.3 (gingerbread) and later.<br />
Note, you'll want to add this to the <i>end</i> of the onCreate method, after the call to <code>super.onCreate</code>
<br />
<pre>if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
this.appView.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
</pre>
And that should stop "OverScroll" or bounce & the associated highlighting you see.Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com6tag:blogger.com,1999:blog-4020806238051230707.post-37617414816650508982013-02-10T22:27:00.001-08:002013-02-13T11:19:49.920-08:00Simple command line tool via Node.jsHere is the gist of a little script I wrote recently:<br />
<br />
<a href="https://gist.github.com/tripleshotsw/4751496">concat.js</a><br />
<br />
It runs on Node, so you'll need that, and npm of course (which installs with Node), you'll also note that you'll need commander, you can ge that by running:
<br />
<pre>npm instal commander
</pre>
Once you've got that installed you can use the following to get the usage information:
<br />
<pre>node concat.js
</pre>
Which will return
<br />
<pre> Usage: concat.js [options]
Options:
-h, --help output usage information
-V, --version output the version number
-f, --filelist [txtfile] use an input file with a comma separated list of files to concat
-s, --files [files] specify the files to concat in the option
-d, --dest [dest] the destination file
</pre>
So, it's a little script that will take a list of javascript files & concatenate them together. You can provide the list either in a text file or on the command line, and in either case it's a comma separated list of filenames.
<br />
<br />
References:<br />
Inspiration: <a href="http://blog.millermedeiros.com/node-js-as-a-build-script/">blog.millermedeiros.com</a><br />
Node.js: <a href="http://nodejs.org/">Node.js</a><br />
Commander.js:<a href="https://github.com/visionmedia/commander.js"> on github </a>Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0tag:blogger.com,1999:blog-4020806238051230707.post-92013789230876041102013-01-27T22:40:00.001-08:002013-01-27T22:43:21.906-08:00--amend : Another reason I like GitOnce upon a time...<br />
<br />
I worked in an office on a large development team that used a centralized source control management (SCM) system. One of the amusing check-ins you would inevitably see from time to time would be the "file I forgot to add" check-ins.<br />
<br />
It happened like this: You made a significant change, played with one or two different solutions, did some refactoring, and came up with a significant change, and along the way you added some files. Sometimes you would remember to let the SCM system know they were added, other times you would forget & shortly after you checked in (if you were lucky enough to catch it yourself) or some time the next day (when the poor sap who had "build duty" caught you) you had to check in that last file. It was an additional checkin, and had a comment like: <blockquote>"Woops, forgot this file with change #####".</blockquote>
Of course if anybody else wanted your change, or later wanted to roll back to a that change, they needed 2 "changelists" to identify what should have been a single point in the repository history; and they needed to know they needed both changes. It was pretty rare that it created any real problems, but I prefer the git way.<br />
<br />
Git has a wonderful set of features around the <code>commit</code> keyword for fixing these mistakes. You can actually undo, redo, pick apart and merge changes that have been committed. With git you can have a much cleaner history of changes.<br />
<br />
Upon having <code>commit</code>ed (but not <code>push</code>ed) a change and realizing I need to fix it I can just make and <code>add</code> whatever changes and then perform a:
<br />
<pre>git commit --amend
</pre>
It's even possible to change older commits, provided you haven't pushed them to a shared repository, but that's out of scope for today. (You would use rebase to get to the commit you want to change.)<br />
<br />
It's important to note that you should not try to amend a change that has been pushed to a shared repository. Git normally won't let you do this and if you force your way around it the change becomes a different change (the hash changes, even if you change just the message) and then you can have two sets of "reality" or "history" in different repositories. You're basically changing things that "can't" or "shouldn't" be changed in the repository history... and then even The Doctor won't be able to save you from your collaborators.<br />
<br />
Ok, so <code>--amend</code> only helps when you catch the mistake yourself, still, a nice thing to have in the tool-chest.<br /><br />
Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0tag:blogger.com,1999:blog-4020806238051230707.post-75696264279780429632012-09-11T16:01:00.000-07:002013-02-13T11:23:26.332-08:00New favorite git feature.While I'm a relatively new user of git, I'm certainly getting used to it and it's way of doing things. While it's not perfect, it is much better than some of the alternatives for SCM. <br />
<br />
So, my new favorite feature?<br />
<br />
<pre>git stash</pre>
<br />
Say I'm working on a long running, low-priority change for a client, when they call with something more urgent. Stash let's me do just that, stash all my current changes that haven't been commited, and work on the new requirement. Once I'm done and the client has signed off on the high-priority item, I can jump right back into the low-priority task via 'git stash pop'<br/><br/><br />
Certainly I could do the same thing via a branch, but stash is a lot simpler and quicker.Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0tag:blogger.com,1999:blog-4020806238051230707.post-4722821348418512292012-09-06T23:41:00.000-07:002013-02-13T11:27:22.551-08:00Stop the UIWebView bounce for Cordova based projects.<br />
For every Cordova (PhoneGap) app that I've created for iOS, I've wanted to prevent the UIWebView from bouncing.
There's two potential solutions, one is a setting in the plist, and the second is a change to the objective-c code.<br />
<br />
For PhoneGap 1.5.0 and later the best solution is to set "UIWebViewBounce" to "NO" in the PhoneGap.plist/Cordova.plist file (which file you have depends on which version of the SDK you are using.) In the 'Root' of the plist file, look for "UIWebViewBounce", and set it to "NO" or "false" (If it's missing, go ahead and add it to the plist file.)
<br />
<pre>UIWebViewBounce NO</pre>
<br />
For versions previous to 1.5 and native projects that are using the UIWebView, you would need to make a change to the Objective-C in the project.<br />
The solution is to send the setBounces:NO message. You'll need to change the MainViewController.m (or AppDelegate.m file in older versions of Cordova/Callback/PhoneGap).<br />
<br />
Look for webViewDidFinishLoad, and within that method add the following line:<br />
<pre>[[theWebView.subviews objectAtIndex:0] setBounces:NO];</pre>
<br />
Note, that I've seen suggestions that the following Javascript would work:
<br />
<pre>document.onload = function(){
document.ontouchmove = function(e){ e.preventDefault(); }
};
</pre>
This doesn't work because the bounce occurs before the document.ontouchmove event is fired.<br />
<br />Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com10tag:blogger.com,1999:blog-4020806238051230707.post-83561446834003749872012-02-25T11:23:00.001-08:002012-02-27T17:30:03.933-08:00JavaScript Coding Style<p>I've been working with jQuery quite a bit lately, and of course doing anything really unique in jQuery can lead to taking a look at a number of jQuery plug-ins. I came across one, that I find both very useful and extremely frustrating all at the same time.
</p>
<p>The plug-in is small and seems both efficient and effective. It does what it was meant to do and seems to do it well. My problem with the plug-in is that I wanted to make it do something new, something very much like it's intended feature, but with a new requirement.</p>
<p>Unfortunately, I found the code difficult to work with, here is a sample:</p>
<pre>
function memento(t, th) {
var w,
m = 0,
i = 0,
aux = [];
if (th) {
t.cg[removeAttr](width);
if (t.opt.flush) {
S[t.id] = "";
return;
}
w = S[t.id].split(";");
for (; i < t.ln; i++) {
aux[push](100 * w[i] / w[t.ln] + "%");
th.eq(i).css(width, aux[i]);
}
for (i = 0; i < t.ln; i++)
t.cg.eq(i).css(width, aux[i]);
} else {
S[t.id] = "";
for (i in t.c) {
w = t.c[i][width]();
S[t.id] += w + ";";
m += w;
}
S[t.id] += m;
}
}
</pre>
<p>In the interest of full disclosure; there were comments, but I've left them off because I wanted to focus on the coding style not the comments. In fact, leaving them off in some cases made the code easier to read (and clearer where the code seemed to differ from the comments.) In general though, without the comments and the context, I don't think you have a chance of knowing what's happening in this method, and that is what I think is wrong with it.
</p>
<p>The 'S' in the code is sessionStorage, the 't' is a table, the 'th' I believe to be a <th> element, so that one really is descriptive, but you cannot tell from the context because the other variables are reduced to single character variables.
</p>
<p>I suspect that the original author did this to minimize the code, but in doing so I feel they have created code that is unnecessarily difficult to work with, and I don't get why. Why make all the variables single characters if you're going to leave in all the whitespace? Why hand minify when there's several readily available tools to do it for you? It did more to obfuscate the code than it did compact it, and not knowing the original authors intent, I have no idea why they did it this way.
</p>
<p>Anyway, this was from an open-source plug-in that I had been considering using. It's almost perfect for my needs, but the style makes it something I wouldn't ask others to maintain and so, I think I'm going to have to rewrite it from scratch.
</p>
<p>Bummer.</p>
<p>So, now I'm curious what others think, have I gone off the deep end? Am I being pedantic? Is this code something you would happily use in a project?</p>Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0tag:blogger.com,1999:blog-4020806238051230707.post-72708656933300764082012-02-11T16:44:00.000-08:002013-02-13T11:28:09.457-08:00Scope and Variable “Hoisting” in JavaScriptScope, in JavaScript is Function scope, and variable declarations get moved to the top of their scope.<br />
Because the scope is function scope, the body of a function establishes new context, but <code>if, for, switch,</code> and <code>{},</code> and anything else that is not a function does not create a new context.<br />
So, to demonstrate that with a little code:<br />
<pre>//Global scope
var i;
for(i=0;i<3;i++){
//Still Global scope
var myTotal = i;
}
alert(myTotal); // 2</pre>
Since the for loop has no affect on the variable scop, all references to myTotal above are in the Global space.<br />
Of course functions do have a local scope, as seen with this snippet:<br />
<pre>function newFunction() {
//newFunction local scope
var myVar = "Original Var";
if (true) {
myVar = "New Var";//newFunction local scope
}
alert(myVar); // "New Var";
}
newFunction();
alert(myVar) // ReferenceError Thrown
</pre>
The alert within the function gives "New Var", which is a local variable.<br />
The alert outside of the function throws a ReferenceError because there is no myVar in the Global space, and within the Global space we do not have access to local variables that were declared within a function body.<br />
JavaScript also does something that has been called “hoisting”. JavaScript varable declarations will be moved to the top of their scope. Note, it's just the declarations, not the initialization.<br />
Variable hoisting can lead to some unexpected results, for instance this:<br />
<pre>var myVar = "Original Var"
function newFunction() {
if (!myVar) {
var myVar = "New Var";
}
alert(myVar);
}
newFunction(); // "New Var"
</pre>
The value of myVar at the <code>if</code> statement is <code>undefined</code> because the local variable has been declared, but not initialized. The variable declaration is moved to the top of the function, and so is really no different than this:<br />
<pre>var myVar = "Original Var"
function newFunction() {
var myVar;
if (!myVar) {
myVar = "New Var";
}
alert(myVar);
}
newFunction(); // "New Var"
</pre>
That version of the function makes it clear that the myVar is declared at the top of the scope, and that it is at that point uninitialized. It also makes clear that the <code>if</code> statement is extraneous by clearing up what is happening with the local variable. <br />
<br />
Moving your variable declarations to the top is a JavaScript “Best Practice” because it turns the code into a more accurate expression of what JavaScript is actually going to do.Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com1tag:blogger.com,1999:blog-4020806238051230707.post-36248457820325695652012-02-11T14:07:00.000-08:002012-02-11T14:07:26.126-08:00JavaScript Book RecommendationI just read <u>JavaScript: The Good Parts</u> by Douglas Crockford.<br />
<br />
Excellent introduction to Javascript, I wish I had read it years ago.<br />
<br />
The author tries to stick to just the “good parts” of JavaScript, and does a great job of that, so you'd probably also need a JavaScript reference of some sort as a companion. It is, however, an introductory book I would recommend to anyone coming to JavaScript from a more classical OOP background.Anonymoushttp://www.blogger.com/profile/06303711299082578820noreply@blogger.com0