Skip to content

Instantly share code, notes, and snippets.

@gistfrojd
Last active March 24, 2016 07:48

Revisions

  1. gistfrojd revised this gist Mar 24, 2016. No changes.
  2. gistfrojd revised this gist May 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion boilerplate-toggleview.js
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ ToggleView.prototype.clickHandler = function(e) {
    self.toggle();
    };

    ToggleView.prototype.toggle = function(e) {
    ToggleView.prototype.toggle = function() {
    var self = this;

    self.clickCounter++;
  3. gistfrojd revised this gist May 18, 2015. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion boilerplate-function.js
    Original 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
    validateEmail: validateEmail,
    validateEmailList: validateEmailList
    };
  4. gistfrojd revised this gist May 18, 2015. 2 changed files with 2 additions and 2 deletions.
    File renamed without changes.
    4 changes: 2 additions & 2 deletions main2.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /**
    * Example of a project startfile
    * 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"});
    var toggleView = new ToggleView({selector: ".js-toggle"});
    }
  5. gistfrojd revised this gist May 13, 2015. 2 changed files with 61 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions main2.js
    Original 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"});
    }
    46 changes: 46 additions & 0 deletions toggleview.js
    Original 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;
  6. gistfrojd revised this gist May 13, 2015. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,18 @@
    /**
    * Example of a project start file.
    */

    /* globals alert */

    "use strict";


    var Menu = require("./views/megamenu");
    var MegaMenu = require("./views/megamenu");
    var Utils = require("./utils");


    if (Utils.isIE()) {
    var megaMenu = new MegaMenu({element: "js-megamenu"});
    if (! Utils.isIE()) {
    var megaMenu = new MegaMenu({selector: ".js-megamenu"});
    } else {
    alert("Step away from the computer!");
    }
  7. gistfrojd revised this gist May 13, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions boilerplate-function.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    /**
    * Example of a util library
    * Example of a Email utils library
    *
    * Usage:
    * var utils = require("./utils");
    * utils.validateEmail("[email protected]");
    * var EmailUtils = require("./utils");
    * EmailUtils.validateEmail("[email protected]");
    */

    "use strict";
  8. gistfrojd revised this gist May 13, 2015. 2 changed files with 19 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions boilerplate-prototype.js
    Original 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 this.store[key];
    return Gzip.unpack(this.store[key]);
    }

    Store.prototype.set = function(key, value) {
    return this.store[key] = value;
    return this.store[key] = Gzip.pack(value);
    }


    14 changes: 14 additions & 0 deletions main.js
    Original 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"});
    }
  9. gistfrojd revised this gist May 13, 2015. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions boilerplate-prototype.js
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,6 @@
    "use strict";


    var path = require("path");


    function Store(options) {
    this.store = {};
    }
  10. gistfrojd revised this gist May 13, 2015. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions boilerplate-function.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,20 @@
    /**
    * Simple module that installs path.
    * Example of a util library
    *
    * Usage:
    * var utils = require("./utils");
    * utils.validateEmail("[email protected]");
    */

    "use strict";


    var path = require("path");


    function setup(directory) {
    path.set(directory);
    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 = setup;
    module.exports = {
    validateEmail: validateEmail
    };
  11. gistfrojd revised this gist May 13, 2015. 2 changed files with 40 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions boilerplate-function.js
    Original 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;
    24 changes: 24 additions & 0 deletions boilerplate-prototype.js
    Original 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;
  12. gistfrojd created this gist May 13, 2015.
    56 changes: 56 additions & 0 deletions styleguide.md
    Original 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