Skip to content

Instantly share code, notes, and snippets.

View antoniocapelo's full-sized avatar

Capelo antoniocapelo

View GitHub Profile
@antoniocapelo
antoniocapelo / js_screenshot
Created December 7, 2014 18:15
Snippet for capturing screenshot
(function (exports) {
function urlsToAbsolute(nodeList) {
if (!nodeList.length) {
return [];
}
var attrName = 'href';
if (nodeList[0].__proto__ === HTMLImageElement.prototype
|| nodeList[0].__proto__ === HTMLScriptElement.prototype) {
attrName = 'src';
}
@antoniocapelo
antoniocapelo / edit_express_app.js
Created November 2, 2014 17:08
Editing express generated app.js to serve static files generated by grunt
// view engine setup - erased
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');
app.use(favicon(path.join(__dirname,'dist','favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
@antoniocapelo
antoniocapelo / newExtendClass
Created September 14, 2014 23:14
Another method of extending classes in Javasript
function BaseClass () {
this.doSomething = function () {
};
}
BaseClass.prototype.someObject = {};
BaseClass.prototype.sharedSomething = function () {
};
@antoniocapelo
antoniocapelo / classModulePattern
Last active August 29, 2015 14:06
Class Creation - Module Pattern
(function( global ) {
var ModPattern = function() {
function api1 (argument) {
return this.publicInstanceValue++;
}
function api2 (argument) {
return privateInstanceValue++;
}
@antoniocapelo
antoniocapelo / classPrototypePattern
Last active August 29, 2015 14:06
Class Creation - Prototype Pattern
(function(global) {
function OOPPattern(value) {
this.publicInstanceValue = value || 10;
var privateValue = 0;
var privatFn = function(argument) {
return 1 + 2;
}
this.api2NeedsPrivateValue = function(argument) {
@antoniocapelo
antoniocapelo / extendClass
Created September 13, 2014 10:51
Extending Classes in Javascript (Prototypal pattern)
function ClassName(name) {
this.name = name;
}
ClassName.prototype = {
constructor: ClassName,
greet: function () {
return 'My name is' + this.name;
}
};
@antoniocapelo
antoniocapelo / createProvider
Created September 13, 2014 10:36
Provider Creation in AngularJS
var app = angular.module('capeloMod', []);
app.provider('demo', function() {
var cfg = 'Default';
this.setCfg = function(providedCfg) {
cfg = providedCfg;
};
this.$get = ['dependencyName', function(dependency) {
return new dependency(cfg);
@antoniocapelo
antoniocapelo / createFactory
Created September 13, 2014 10:12
Factory creation in AngularJS
var app = angular.module('capeloMod', []);
//factory style, more involved but more sophisticated
app.factory('demoFactory', function() {
var publicValue = 0;
var privateValue = 0;
function apiFn() {
return this.publicValue++;
}
@antoniocapelo
antoniocapelo / createService
Last active August 29, 2015 14:06
Service Creation in AngularJS
var app = angular.module('capeloMod', []);
app.service('demoService', function() {
this.publicValue = 0;
var privateValue = 0;
var privateFn = function() {
return 1 + 2;
};
@antoniocapelo
antoniocapelo / gist:bfba67f96b4890e443e4
Created August 10, 2014 11:12
Detecting mobile device
/**
* Originally from http://www.abeautifulsite.net/detecting-mobile-devices-with-javascript/
**/
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);