Skip to content

Instantly share code, notes, and snippets.

View adamsilver's full-sized avatar

Adam Silver adamsilver

View GitHub Profile
@pkananen
pkananen / set-interval-spec.js
Last active February 8, 2016 20:56
testing setInterval with Jasmine using a Mock Clock
describe('createIntervalCallback', function() {
var sut = $.clockTest;
it('calls setInterval with callback() at a delay of 7000 ms', function() {
spyOn(sut, 'callback');
jasmine.Clock.useMock();
sut.createIntervalCallback();
jasmine.Clock.tick(7000);
@erikfried
erikfried / MyModule.js
Created July 1, 2011 09:51
Testing YUI3 modules with Jasmine
YUI.add("my-module", function (Y) {
Y.namespace("mynamespace");
Y.mynamespace.MyModule = function () {
return {hello : "hello"};
};
}, '0.0.1' /*version*/, {
requires : ["base"]
});
@nuxlli
nuxlli / sublime_text_2_useful_shortcuts.md
Created September 9, 2011 18:51 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 - Useful Shortcuts

Tested in Mac OS X: super == command

Open/Goto


  • super+t: go to file
  • super+ctrl+p: go to project
  • super+r: go to methods

Forget AMD and that's straight from the source. Sorry for the long build-up on the history, but if I'm to convince you to forget this non-technology, I think it's best you know where it came from. For those in a hurry, the executive summary is in the subject line. ;)

In Spring of 2009, I rewrote the Dojo loader during a requested renovation of that project. The primary pattern used to make it more practical was:

dojo.provide('foo', ['bar1', 'bar2'], function() {

[module code]

});
@david-mark
david-mark / gist:3279190
Created August 6, 2012 22:47
Sencha Touch Still Sucks

Was asked to look at this thing again; only reviewed the JS portion. Last I checked, the CSS was similarly reality-challenged. Graphics are nice, but are tantamount to the paint job on a used car. Under the hood, this thing is all junk. It's hard to imagine the innards of any Web or mobile device-based application would end up like this, which raises the question of whether the authors have ever written such applications (or any amount of meaningful JS).

/**
 * @class Ext
 * @singleton

There (still) are no "classes" or "singletons" in JS (starting off on the wrong foot by mangling JS terms).

@david-mark
david-mark / gist:3445646
Created August 24, 2012 05:09
Thoughts on jQuery 2.0

The big question regarding the upcoming (and thoroughly unneeded) 2.0 version of this most dubious script is whether its authors are foolish enough to leave "Sizzle" (their QSA fallback) in the code. If they are foolish enough to offer a "solution" that breaks IE 8- users (or requires conditional comments to avoid doing so), can they possibly think that they need anything but QSA to query the DOM?

Another looming question is how a project that has no way to keep track of plug-in compatibility with just one fork going to handle two at once? Poorly I imagine, but that's for those who remain on board to worry about.

Let's deconstruct this "magic" script. It's roughly 70% "Sizzle" (and supporting functions), 10% "Live" (an atrocious event system), 10% outmoded special effects (which can be done far more efficiently with CSS3 transitions and animations) and 10% miscellaneous (and often wildly confused) DOM "normalization" functions (e.g. measuring the viewport dimensions, reading and writing attributes/propertie

@david-mark
david-mark / gist:3768460
Created September 23, 2012 01:28
"RWD" and "Mobile First" buzzwords explained

Have been fighting with some RWD "expert" on Wikipedia of late. At the time of this writing, my edits to the related article are still visible.

http://en.wikipedia.org/wiki/Responsive_Web_Design

RWD is just a buzzword. According to the article (and a fairly recent book it seems), it incorporates these techniques:

  1. Use EM units to size text (and containers of text of course).
  2. Use media queries
  3. Let the browser scale images (by using em's instead of pixels)
@mkmcdonald
mkmcdonald / gist:3853216
Created October 8, 2012 15:51
Learning JavaScript
On 08/10/12 09:35, I Am Here wrote:
> Can someone recommend me a good book which will cover ALL important
> features of [JavaScript]?
There is no book that adequately covers JavaScript. Douglas
Crockford’s *JavaScript: The Good Parts* contains a moderately high
level of technical depth, but is quite brief.
David Flanagan’s *JavaScript: The Definitive Guide* is at best a
@david-mark
david-mark / gist:4312841
Created December 16, 2012 20:54
Unobtrusive JS === Unrealistic JS

Unobtrusive JS === Unrealistic JS

In general, Web developers want to be seen using the very latest and "greatest" Web technologies. We want to add buzzwords to our CV's as soon as they are coined and want to be considered "cutting edge" developers who are "moving the Web forward". Unfortunately, history takes a dim view of our exuberance and science ignores it completely.

Best to start at the beginning with DOM0, which came out in the 90's. Here we have a button that alerts when clicked:

<button type="button" onclick="window.alert('Hello world!')">Click me!</button>
@david-mark
david-mark / gist:4349216
Last active January 10, 2017 05:14
Progressive Destruction

Progressive Destruction

Last time we looked at the decade-long (and failed) effort to reinvent event listener attachment. We saw that the inherent graceful degradation of HTML still beats the equivalent "unobtrusive" patterns and is certainly a better bet for prototyping an application than the usual suspect DOM libraries.

There's a myth that progressive enhancement is somehow a "better" technique for browser scripting, but the fact is that they are not mutually exclusive and each has its place. This may remind you of a similar argument regarding feature detection vs. browser sniffing, but it certainly doesn't apply in that context.

We left off with the start of a draggable toolbar that works with any manner or combination of pointing devices (including your fingers).