Sunday, June 7, 2015

INTERVIEW - The Art Of Hiring Great Javascript Developers

http://www.zsoltnagy.eu/the-art-of-hiring-great-javascript-developers/?utm_content=bufferb411d&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer

JavaScript - iterate or loop over JavaScript object or JSON

It is taken from here: http://stackoverflow.com/questions/684672/loop-through-javascript-object

In JavaScript, every object has a bunch of built-in key-value pairs that have meta-information. When you loop through all the key-value pairs for an object you're looping through them too. hasOwnPropery() filters these out:

for (var key in p) {
  if (p.hasOwnProperty(key)) {
    alert(key + " -> " + p[key]);
  }
}
In ECMAScript 5 you have new approach in iteration fields of literal - Object.keys
More information you can see on MDN
My choice is below as a faster solution in current versions of browsers (Chrome30, IE10, FF25)

var keys = Object.keys(p),
    len = keys.length,
    i = 0,
    prop,
    value;
while (i < len) {
    prop = keys[i];
    value = p[prop];
    i += 1;
}

KARMA + JASMINE tutorial for testing

http://www.bradoncode.com/blog/2015/02/27/karma-tutorial/

Friday, June 5, 2015

GWTBootstrap - custom email validation for TextBox

=== JAVA CODE ===

TextBox emailLookup = new TextBox();
emailLookup.addValidator(new Validator() {
            @Override
            public int getPriority() {
                return 0;
            }

            @Override
            public List<EditorError> validate(Editor editor, Object value) {
                List<EditorError> result = new ArrayList<EditorError>();
                String valueStr = value == null ? "" : value.toString();
                if (!valueStr.matches(EMAIL_REGEXP)) {
                    result.add(new BasicEditorError(emailLookup, value, "Not a valid email address"));
                } else if (isEmailReapeated(valueStr)) {
                    result.add(new BasicEditorError(emailLookup, value, "Email address is repeated"));
                }
                return result;
            }
        });

=== UI BINDER ===

<b:Row addStyleNames="{style.padding}">
    <b:Column size="XS_12">
        <b:Row>
            <b:Column size="XS_2">
                <b:FormGroup>
                    <b:TextBox ui:field="emailLookup" placeholder="Enter email" allowBlank="false"/>
                    <b:InlineHelpBlock iconType="EXCLAMATION"/>
                </b:FormGroup>
            </b:Column>

            <b:Column size="XS_1">
                <b:Button ui:field="addContact" text="Add"/>
            </b:Column>

        </b:Row>
    </b:Column>
</b:Row>

D3 Karma Jasmine testing

http://busypeoples.github.io/post/testing-d3-with-jasmine/

JavaScript Karma Jasmine - JSON parsing tests

http://stackoverflow.com/questions/20938320/loading-external-file-from-karma-jasmine-test
http://stackoverflow.com/questions/25035688/json-parse-fails-in-jasmine

ANGULAR + KARMA + JASMINE: test controller with $http, $scope

https://docs.angularjs.org/api/ngMock/service/$httpBackend