Skip to content

Instantly share code, notes, and snippets.

View davej's full-sized avatar
💭
Working on @ToDesktop

Dave Jeffery davej

💭
Working on @ToDesktop
View GitHub Profile
@davej
davej / finished-polyfill.js
Last active August 29, 2019 14:14 — forked from simevidas/finished-polyfill.js
Animation.prototype.finished polyfill
// only polyfill .finished in browsers that already support animate()
if (document.body.animate) {
// Chrome does not seem to expose the Animation constructor globally
if (typeof Animation === 'undefined') {
window.Animation = document.body.animate({}).constructor;
}
if (!('finished' in Animation.prototype)) {
Object.defineProperty(Animation.prototype, 'finished', {
extendsScope_module = angular.module 'classy-extends', ['classy-core']
###
Note that this does NOT get the mixin class dependencies as of now.
###
extendsScope_module.classy.plugin.controller
name: 'extends'
localInject: ['$controller']
define [
'base-ctrl'
], (BaseCtrl) ->
class AppController extends BaseCtrl
@register()
@inject('$scope')
init: ->
@$scope.foo = "bar"
@davej
davej / gist:1680278
Created January 26, 2012 01:21 — forked from EGreg/gist:1678415
Asynchronous loop issues illustrative example
// Illustrative case
// YEAH -- ILLUSTRATIVE OF THE FACT THAT YOU CAN ISSUE PARALLEL QUERIES TO THE DATABASE INSTEAD OF SERIAL ONES LIKE A DUMB THREADED IMPLEMENTATION THAT IS INFERIOR FOR DOING WEB SERVERS
function (recentBlogPostIds, callback) { // obviously you need this, but use callback instead of return
var results = [], // Use array not object
, len = recentBlogPostIds.length; // Cache length since we'll be using it more than once
for (var i = 0; i < len; i++) {
var blogPostId = recentBlogPostIds[i];
@davej
davej / DRY.js
Created January 26, 2012 01:14 — forked from EGreg/DRY
Asynchronous cache failover example
function cacheOrDB (id, callback) {
asynchronousCache.get("id:"+id, function(err, myThing) {
if (myThing == null) {
asynchronousDB.query("SELECT * from something WHERE id = "+id, function(err, myThing) {
callback(err, myThing);
});
} else {
callback(err, myThing);
}
});
// helper function that goes inside your socket connection
client.connectSession = function(fn) {
var cookie = client.request.headers.cookie;
var sid = unescape(cookie.match(/connect\.sid=([^;]+)/)[1]);
redis.get(sid, function(err, data) {
fn(err, JSON.parse(data));
});
};
// usage