Last active
March 24, 2016 07:48
Revisions
-
gistfrojd revised this gist
Mar 24, 2016 . No changes.There are no files selected for viewing
-
gistfrojd revised this gist
May 20, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ ToggleView.prototype.clickHandler = function(e) { self.toggle(); }; ToggleView.prototype.toggle = function() { var self = this; self.clickCounter++; -
gistfrojd revised this gist
May 18, 2015 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,23 @@ function validateEmail(email) { return re.test(email); } function validateEmailList(list) { var l = list.length; var email; while (l--) { email = list[l]; if (! validateEmail(email)) { return false; } } return true; } module.exports = { validateEmail: validateEmail, validateEmailList: validateEmailList }; -
gistfrojd revised this gist
May 18, 2015 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /** * Example of a project start file */ "use strict"; @@ -11,5 +11,5 @@ var ToggleView = require("./views/toggleview"); if($(".js-toggle").length) { var toggleView = new ToggleView({selector: ".js-toggle"}); } -
gistfrojd revised this gist
May 13, 2015 . 2 changed files with 61 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ /** * Example of a project startfile */ "use strict"; var $ = require("jquery"); var ToggleView = require("./views/toggleview"); if($(".js-toggle").length) { var toggleView = new ToggleView({selector:".js-toggle"}); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ /** * Example clickhandler */ "use strict"; var $ = require("jquery"); function ToggleView(options) { var self = this; self.selector = options.selector; self.el = $(self.selector); self.clickCounter = 0; $(self.selector).on("click", $.proxy(self.clickHandler, self)); } ToggleView.prototype.clickHandler = function(e) { var self = this; self.toggle(); }; ToggleView.prototype.toggle = function(e) { var self = this; self.clickCounter++; console.log("clicked: ", self.clickCounter); if(self.clickCounter > 5) { self.unbindToggle(); console.log("clickHandler is unbinded"); } }; ToggleView.prototype.unbindToggle = function() { var self = this; self.el.unbind("click", self.clickHandler); }; module.exports = ToggleView; -
gistfrojd revised this gist
May 13, 2015 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,18 @@ /** * Example of a project start file. */ /* globals alert */ "use strict"; var MegaMenu = require("./views/megamenu"); var Utils = require("./utils"); if (! Utils.isIE()) { var megaMenu = new MegaMenu({selector: ".js-megamenu"}); } else { alert("Step away from the computer!"); } -
gistfrojd revised this gist
May 13, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ /** * Example of a Email utils library * * Usage: * var EmailUtils = require("./utils"); * EmailUtils.validateEmail("[email protected]"); */ "use strict"; -
gistfrojd revised this gist
May 13, 2015 . 2 changed files with 19 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,16 +5,19 @@ "use strict"; var Gzip = require("gzip"); function Store(options) { this.store = {}; } Store.prototype.get = function(key) { return Gzip.unpack(this.store[key]); } Store.prototype.set = function(key, value) { return this.store[key] = Gzip.pack(value); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ /** * Example of a project start file. */ "use strict"; var Menu = require("./views/megamenu"); var Utils = require("./utils"); if (Utils.isIE()) { var megaMenu = new MegaMenu({element: "js-megamenu"}); } -
gistfrojd revised this gist
May 13, 2015 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,6 @@ "use strict"; function Store(options) { this.store = {}; } -
gistfrojd revised this gist
May 13, 2015 . 1 changed file with 11 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,20 @@ /** * Example of a util library * * Usage: * var utils = require("./utils"); * utils.validateEmail("[email protected]"); */ "use strict"; function validateEmail(email) { var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; return re.test(email); } module.exports = { validateEmail: validateEmail }; -
gistfrojd revised this gist
May 13, 2015 . 2 changed files with 40 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ /** * Simple module that installs path. */ "use strict"; var path = require("path"); function setup(directory) { path.set(directory); } module.exports = setup; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ /** * A simple store class that can both set and get values. */ "use strict"; var path = require("path"); function Store(options) { this.store = {}; } Store.prototype.get = function(key) { return this.store[key]; } Store.prototype.set = function(key, value) { return this.store[key] = value; } module.exports = Store; -
gistfrojd created this gist
May 13, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ ## Code guide ### Editing - For indentation use 4 spaces - Always try to limit your lines to 80 characters unless it breaks readability, then it can go up to a max of 120 characters - End every file with a empty line at the bottom - Avoid extraneous whitespace YES: spam(cat[1], {dog: 2}) NO: spam( cat[ 1 ], { dog: 2 } ) - Use early return when creating methods - Make sure everything passes hinting ### Naming - When creating a locally referenced scope variable use the variable name `self` - Always use camelCase - When naming your modules/packages, only use lowercase without any -_. character. Example: `/awesomepackage/cutecat.js` YES: `/awesomepackage/cutecat.js` NO: `/awesomePackage/cuteCat.js` ### Imports - Place all imports at the top - Separate top imports with your implementation with two blank lines - Use a blank line between node and distributed imports and project specific - Imports should be declared as vars on a new line. Example: ``` var env = require("node-env-file"); var winston = require("winston"); var fundamentet = require("./fundamentet"); ``` - When organizing imports, use the following order: 1. Core modules shipped in Node 2. Third part modules 3. Project modules ### Logging - Always remove console.log messages when checking in your code (unless it is really neccessary). - **TODO: Look into log wrappers** ### Exports - Put all your export declarations last - Always use `module.exports` when exporting, not `export` ### Comments - Try to keep the inline comments to a minimum - When creating a new module, always write a documentation in the header that explains what the module does ### Callbacks - When defining callbacks, always include a error parameter first - Make sure that you always return the result of your callbacks - Use early returns