vendredi 11 septembre 2015

Is Prototype an anti pattern?

When Joshua Bloch mentions that Cloneable interface is broken in Java, why is the Prototype pattern, which uses clone() method to facilitate object creation, not considered an anti-pattern in Java development?

"It's a shame that Cloneable is broken, but it happens." - Joshua Bloch



via Chebli Mohamed

How to find the time an attribute was added to a version in Clearcase

I'm trying to figure out how long on average I take to review files at work. The way our review system works, someone checks a new version in and applies a Reviewer attribute to the file with the name of the reviewer. Then after the reviewer finishes the review, they apply an Approved attribute with the value "yes" or "no".

So to find the time it takes for me to review something, I need to find the difference in creation time of the two attributes. Is there a way to find these creation times in clearcase?

I can definitely get the time the version itself was created using cleartool describe, but I didn't see a way to do it for the attributes.



via Chebli Mohamed

Close CSS dropdown menu onclick

I'm very new to CSS and HTML combination. I'm trying to make use of following code for dropdown menu. But when mouse is moved away from dropdown menu, it gets closed. I would like to close it onclick outside the dropdown menu. Can anyone suggest me a fix in CSS to achieve this? JSFiddle for me code is at following location Fiddle link. Your help will be much appreciated. HTML looks like this.

<div id="main">
<div class="wrapper">
    <div class="content">
        <content>
            <div>
                <ul> 
                     <a href="#"><li>Lorem ipsum dolor</li></a>
                     <a href="#"><li>Consectetur adipisicing</li></a>
                     <a href="#"><li>Reprehenderit</li></a>
                     <a href="#"><li>Commodo consequat</li></a>

                </ul>
            </div>
        </content>
    </div>
    <div class="parent">Drop Down Parent 1</div>            
</div>

And CSS looks like this

#main {
margin: 30px 0 50px 0;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}
#main .wrapper {
display: inline-block;
width: 180px;
margin: 0 10px 0 0;
height: 20px;
position: relative;
}
#main .parent {
height: 100%;
width: 100%;
display: block;
cursor: pointer;
line-height: 30px;
height: 30px;
border-radius: 5px;
background: #F9F9F9;
border: 1px solid #AAA;
border-bottom: 1px solid #777;
color: #282D31;
font-weight: bold;
z-index: 2;
position: relative;
-webkit-transition: border-radius .1s linear, background .1s linear, z-index 0s linear;
-webkit-transition-delay: .8s;
text-align: center;
}
#main .parent:hover, #main .content:hover ~ .parent {
background: #fff;
-webkit-transition-delay: 0s, 0s, 0s;
}
#main .content:hover ~ .parent {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
z-index: 2;
}
#main .content {
position: absolute;
top: 0;
display: active;
z-index: 2;
height: 0;
width: 180px;
padding-top: 30px;
-webkit-transition: height .5s ease;
-webkit-transition-delay: .4s;
border: 1px solid #777;
border-radius: 5px;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
#main .wrapper:active .content {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
#main .content div {
background: #fff;
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#main .content:hover {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}



via Chebli Mohamed

ng-options to work with response from promise

I am receiving a promise like so.

var GetAgentsPromise = LeadsServiceTest.GetAgents($http);
        GetAgentsPromise.then(function(response) {
            $scope.ClientAgents.id =  response.data.d.AgentIDs;
            $scope.ClientAgents.name = response.data.d.FullNames;
            console.log($scope.ClientAgents);             
        });

My select looks like so

 <select ng-model="ClientAgents">
                        <option ng-repeat="ClientAgent in ClientAgents" value="ClientAgent.id" id="SortTypeSelect" class="form-control ng-pristine ng-valid ng-touched" style="width: 70%;">{{ClientAgent.name}}</option>
                    </select>

What am I doing wrong and why ?

My response is returning the correct data.



via Chebli Mohamed

SAS - how to find variable name in string which is similar to a specified sub-string

I want to find if a variable exisits in a string (&fixed) and if so, which word number.

%LET fixed = %STR(variable1 region1 variable3);

%IF %INDEX(&fixed, regio) %THEN
  %DO;
    %LET regioxc = %SCAN(&fixed, %SYSFUNC(FIND(&fixed, regio)));
  %END;

I want to create a macro variable called regioxc, which could be equal to either region1 one time, and the next time the macro is run it could be equal to regiodc, or something else (always with the beginning string 'regio'), if that is the region variable specified within the &fixed string. This only works if the regio variable is specified first within the &fixed string, but in this case it is the second variable, so this does not work. I cannot find a robust method of creating the variable (word) count value from the &fixed string to be able to use the scan function. I know it should be 2, in this case. Any help here would be much appreciaited.



via Chebli Mohamed

Why String.Prototype replace doesn't work inside nested functions?

I have declared in same script file the following sub-string replace function :

String.prototype.replaceAt = function(index, character) {
    return this.substr(0, index) + character + this.substr(index + character.length);
}

If I use this function in the main script file (for example right after its declaration), it works properly with string output.

If I use this function inside nested functions, more exactly I have a function inside another function and I call "replaceAt" inside the second function, it doesn't work and it truncates all characters after the "index" specified in "replaceAt". I also specify that this is a content script in a Chrome extension.

Example (works okay outside functions, in main file) :

var h = '000000';
h = h.replaceAt(3, "1");
console.log(h);

Example (truncates everything after "index") :

function do_lut() {
    function nfu_change(e, i) {
        if (e.checked) {
            if (temp != null) {
                console.log(i + " - " + temp);
                temp = temp.replaceAt(i, "1");
            } else {
                temp = '000000000000000'.replaceAt(i, "1");
            }
        }
    }
}

Temp is just a string variable declared as empty global. Also, the above is not the full statement with event passing etc, just for exemplification.



via Chebli Mohamed

Angularjs Service does not work

I define a Service to share a variable between two controllers, but when i set the variable in a controller and then get this from another controller it does not get the correct value , this is the service:

 App.service("ProductService", function () {
    var productTotalCount = {};
    return {
        getproductTotalCount: function () {
            return productTotalCount;
        },

        setproductTotalCount: function (value) {
            productTotalCount = value;
        }
    }
});

and this is the controller which i set productTotalCount:

 App.controller("ProductController", function ($scope, $http, $rootScope, ProductService) {
    $scope.GetAllProducts = $http.get("GetAllProductsInformation").success(function (data) {

        $rootScope.Products = data.Data;
        ProductService.setproductTotalCount(data.TotalCount); // i set productTotalCount here and it's value became 19
    });
    $scope.editProduct = function (data) {

        $scope.model = data;
        $rootScope.$broadcast('modalFire', data)
    }
});

and when i get the productTotalCount in this controller it return object instead of 19 :

 App.controller('Pagination', function ($scope, ProductService) {
    debugger;
    $scope.totalItems = ProductService.getproductTotalCount(); // it should return 19 but return object!!
    $scope.currentPage = 1;
    $scope.itemPerPage = 8;
});

what is the problem?



via Chebli Mohamed