ddrayne + programming 141
Adequately Good - Writing Testable JavaScript - by Ben Cherry
january 2012 by ddrayne
ostic of the environment (DOM, browser, etc). For my purposes, I would have probably written a url redirector function that i pass both the URL to *and* the controller to do it on (in this case, the window.location object). As such, instead of relying on the single "singleton" global (window.location), my unit tests can pass in a mocked window.location object and assert that it's manipulated correctly.
The only thing I'd really take issue with is the idea of not creating private methods in closures. I understand the thought behind it, but I think it's off base, and here's why:
If I'm unit testing a built-in native (I know, why do that!?), I don't care how it works internally... I assume it works internally as expected. I write tests to test it as a single indivisable unit. In other words, does a RegExp object with a known regex and a known string produce a known output. If the browser changes how it does that internally, I don't care.
I like to think of testing modules that way too. I can test the public API of a module all day long, but asking me to be able to expose all my internal-only methods for testing is a request that seems unruly. Imagine some other language like Java that was more formal... would the advice there be "make everything public so it's all testable"? I doubt it.
The formalism of hiding private stuff can be abused, but properly used it has a good place in JS in my opinion. We shouldn't discourage its use by saying it's untestable. We should show ways that privates can be useful (and the public API that uses them still feasibly testable) and contrast that wi
javascript
programming
testing
The only thing I'd really take issue with is the idea of not creating private methods in closures. I understand the thought behind it, but I think it's off base, and here's why:
If I'm unit testing a built-in native (I know, why do that!?), I don't care how it works internally... I assume it works internally as expected. I write tests to test it as a single indivisable unit. In other words, does a RegExp object with a known regex and a known string produce a known output. If the browser changes how it does that internally, I don't care.
I like to think of testing modules that way too. I can test the public API of a module all day long, but asking me to be able to expose all my internal-only methods for testing is a request that seems unruly. Imagine some other language like Java that was more formal... would the advice there be "make everything public so it's all testable"? I doubt it.
The formalism of hiding private stuff can be abused, but properly used it has a good place in JS in my opinion. We shouldn't discourage its use by saying it's untestable. We should show ways that privates can be useful (and the public API that uses them still feasibly testable) and contrast that wi
january 2012 by ddrayne
Fisher–Yates Shuffle
january 2012 by ddrayne
act the array. On average, that’s n / 2 elements to shift per element to shuffle, giving O(n2).
But here’s an interesting, if obvious, insight: the number of shuffled elements (n - m) plus the number of remaining elements (m) is always equal to n. This means we can do the entire shuffle in-place, without any extra space! We use the back of the array to store the shuffled elements, and the front of the array to store the remaining elements. We don’t care about the order of the remaining elements as long as we sample uniformly when picking!
To implement the in-place O(n) shuffle, then, pick a random remaining element (from the front) and place in its new location (in the back). The unshuffled element in the back is swapped to the front, where it waits for subsequent shuffling:
programming
But here’s an interesting, if obvious, insight: the number of shuffled elements (n - m) plus the number of remaining elements (m) is always equal to n. This means we can do the entire shuffle in-place, without any extra space! We use the back of the array to store the shuffled elements, and the front of the array to store the remaining elements. We don’t care about the order of the remaining elements as long as we sample uniformly when picking!
To implement the in-place O(n) shuffle, then, pick a random remaining element (from the front) and place in its new location (in the back). The unshuffled element in the back is swapped to the front, where it waits for subsequent shuffling:
january 2012 by ddrayne
My Ultimate Developer and Power Users Tool List for Mac OS X (2011 Edition) | Hacker News
december 2011 by ddrayne
Unless of course you have an SSD. With an SSD, Spotlight is easily fast enough to work well. To start XCode, I hit CMD-space, xc, enter, with a split-second pause before the enter. That is enough for Spotlight to catch up to my typing and I am about as fast as Alfred or Quicksilver for opening apps.
programming
macintosh
mac
tools
december 2011 by ddrayne
Vim: revisited
december 2011 by ddrayne
h Vim for the past many years.
Before, I never felt like we understood each other properly. I felt that the kind of programming I’m doing is not easily done without plugins and some essential settings in .vimrc, but fiddling with all the knobs and installing all the plugins that I thought I needed was a process that in the end stretched out from few hours to weeks, months even; and it the end it just caused frustration instead of making me a happier coder.
design
editor
programming
reference
vim
Before, I never felt like we understood each other properly. I felt that the kind of programming I’m doing is not easily done without plugins and some essential settings in .vimrc, but fiddling with all the knobs and installing all the plugins that I thought I needed was a process that in the end stretched out from few hours to weeks, months even; and it the end it just caused frustration instead of making me a happier coder.
december 2011 by ddrayne
Web 2.0 Development and Business Lessons: You Don't Know JavaScript
december 2011 by ddrayne
h knowledge on callbacks and function application such as the 'call' and 'apply' method
javascript
programming
webdev
december 2011 by ddrayne
Cocoa Dev Central: C Language Tutorial for Cocoa
september 2011 by ddrayne
le has a function, a print statement, a comment, an array, variables, and a loop. If all of this makes sense to you, you're ready to use this tutorial.
cocoa
mac
osx
programming
c
september 2011 by ddrayne
Ash Furrow » Blog Archive » How to Write iOS Apps
september 2011 by ddrayne
.doesn't mean it's controller's viewdidAppear: method ever gets called." In my haste, I missed that crucial word.
The point really is that how a view appears on your screen really matters.
Thanks for the comment - I'll correct the article.
programming
cocoa
ios
The point really is that how a view appears on your screen really matters.
Thanks for the comment - I'll correct the article.
september 2011 by ddrayne
Creating a Spider with Python Mechanize to Monitor Your Website | Web Development Blog of Chris Nizzardini
march 2011 by ddrayne
We want our spider to periodically grab the HTML Document(s), check for anything out of the ordinary, and inform us of any problems. I accomplished this by looking for the opening and closing BODY tags. If either of these is missing either a developer made a mistake or our server-side language has encountered some sort of error. Next we want it to notify us. At some point I’d like to get fancy and tie into a VOIP API service like Google Voice to actually make an outbound phone call, but for now SMS and email will suffice. Last, we don’t want it to keep notifying us every time the cron job fires that we are down. So we’ll store a flag in flat file and tell the spider not to notify us if the file contains a zero. When the site comes back up it will set the flag to “1″ and therefor will know to tell us next time the site goes back down.
python
programming
march 2011 by ddrayne
Comparing E-mail Address Validating Regular Expressions
may 2010 by ddrayne
local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org
email
regex
validation
regexp
programming
may 2010 by ddrayne
related tags
activerecord ⊕ air ⊕ ajax ⊕ animation ⊕ api ⊕ apps ⊕ article ⊕ backbone.js ⊕ beginner ⊕ bestpractice ⊕ blog ⊕ book ⊕ books ⊕ c ⊕ cakephp ⊕ canvas ⊕ class ⊕ classes ⊕ closures ⊕ cocoa ⊕ code ⊕ coding ⊕ codinghorror ⊕ coffeescript ⊕ css ⊕ css3 ⊕ database ⊕ debug ⊕ debugging ⊕ deployment ⊕ design ⊕ development ⊕ django ⊕ documentation ⊕ eclipse ⊕ ecmascript ⊕ editor ⊕ education ⊕ email ⊕ firebug ⊕ framework ⊕ git ⊕ goo ⊕ google ⊕ googlemaps ⊕ heroku ⊕ hierarchical ⊕ howto ⊕ html ⊕ html5 ⊕ http ⊕ humor ⊕ ide ⊕ ideas ⊕ indexeddb ⊕ inheritance ⊕ inspiration ⊕ interface ⊕ ios ⊕ iphone ⊕ javascript ⊕ jquery ⊕ js ⊕ language ⊕ lectures ⊕ linux ⊕ mac ⊕ macintosh ⊕ maps ⊕ mercurial ⊕ mistakes ⊕ mysql ⊕ node ⊕ object ⊕ object-oriented ⊕ objective-c ⊕ oop ⊕ opensource ⊕ osx ⊕ patterns ⊕ performance ⊕ php ⊕ plugins ⊕ productivity ⊕ programming ⊖ prototype ⊕ python ⊕ quiz ⊕ Rails ⊕ reference ⊕ regex ⊕ regexp ⊕ regularexpressions ⊕ resources ⊕ rest ⊕ ruby ⊕ rubyonrails ⊕ simplexml ⊕ smashingmagazine ⊕ software ⊕ spam ⊕ testing ⊕ tips ⊕ tools ⊕ toread ⊕ towatch ⊕ tree ⊕ tutorial ⊕ tutorials ⊕ uml ⊕ validation ⊕ versioncontrol ⊕ video ⊕ vim ⊕ web ⊕ webapp ⊕ webdesign ⊕ webdev ⊕ webdevelopment ⊕ webfaction ⊕ webmonkey ⊕ xdebug ⊕ xml ⊕Copy this bookmark: