Affichage des articles dont le libellé est Recent Questions - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Recent Questions - Stack Overflow. Afficher tous les articles

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

Difficulty in getting the matrix of red, green,blue

 a = imread('Sample1.jpg');
 imshow(a)

This gives me the image but my problem is stated as below

It happens that I have an image in RGB format then how to get 3 different matrix of red ,green,blue respectively in Mat lab , I have also searched the documentation but can't get satisfactory reply , I also want to store this values.



via Chebli Mohamed

Return the row of first non-blank cell

Let's say I have the array A1:A5 in excel:

    A  
1    
2  
3  'test'  
4  
5  'test2'

How can I return "3"? I'm looking for something in Excel formulas. The blanks are genuine blanks.



via Chebli Mohamed

How do I track when multiple objects touch in MATLAB?

I have x,y pixel coordinates of multiple objects that have been tracked from an image (3744x5616). The coordinates are stored in a structure called objects, e.g.

objects(1).centre = [1868 1236]

The objects are each uniquely identified by a numerical code, e.g.

objects(i).code = 33

I want to be able to record each time any two objects come within a radius of 300 pixels each other. What would be the best way to check through if any objects are touching and then record the identity of both objects involved in the interaction, like object 33 interacts with object 34.

Thanks!



via Chebli Mohamed

How to compute for the mean and sd

I need help on 4b please

  1. ‘Warpbreaks’ is a built-in dataset in R. Load it using the function data(warpbreaks). It consists of the number of warp breaks per loom, where a loom corresponds to a fixed length of yarn. It has three variables namely, breaks, wool, and tension.

    b. For the ‘AM.warpbreaks’ dataset, compute for the mean and the standard deviation of the breaks variable for those observations with breaks value not exceeding 30.

    data(warpbreaks)
    warpbreaks <- data.frame(warpbreaks)
    AM.warpbreaks <- subset(warpbreaks, wool=="A" & tension=="M")
    
    mean(AM.warpbreaks<=30)
    sd(AM.warpbreaks<=30)
    
    

This is what I understood this problem and typed the code as in the last two lines. However, I wasn't able to run the last two lines while the first 3 lines ran successfully. Can anybody tell me what is the error here? Thanks! :)



via Chebli Mohamed

data frame or matrix of quantiles

I used following code to get the quantiles (25 %, 50 %,75 % and 99 %) of x and replicate 100 times.

x<-c(1,2,3,5,4,5,6,7,8,5,4,3,2)
sample.boot=numeric()

for (i in 1:100){
       sample.boot[i]<-quantile(sample(x,replace = T),c(0.25,0.50,0.75,0.99))
}
sample.boot

This is not giving desired output. I want all four quantiles replicated 100 times and stored as data frame or in a matrix as below.

4 5 5 7
2 4 6 7
.......
.......
3 5 5 6



via Chebli Mohamed

Cordova Android Classification as Malware

I made a Cordova App with Version 5.2.0 A friend of me send me a Picture that states (freely translated from German):

AVG AntiVirus FREE Alert

App is classified as Malware. Click on Deinstallation to remove the App

Does anybody know where this comes from? Of course I implemented no Malware. Google only gave me this article and it is up to Cordova 4.0.1 Any ideas how to fix this?



via Chebli Mohamed

Removing duplicates within a cell

I can't find a way to remove duplicate values inside a same cell in Excel. For example, in A1, I have:

DOG DOG DOG

I want to have only DOG.

Actual code:

Sub test()
for i = 14 to 16
  transNumb= commRead(i, 23, 4)
next

If transNumb <> "    " and transNumb <> "F PA" then
        transNumbAcum = transNumbAcum + " " + transNumb
End if

Set exlTest = objExcel.Workbooks.Open(strPathExc)
objExcel.Application.Visible = True
exlTest.Sheets("ACCOUNT_CODE Day").Activate 
exlTest.Sheets("ACCOUNT_CODE Day").Cells(37, 4).Value = +transNumbAcum
exlTest.Close xlSaveChanges

objExcel.Quit
End sub

Code output: This will result certain values in the Excel cell (37, 4), such as:

2000 3000 0300 0300 2000

I am lost as to how to delete the repeated values in the cell.

EDIT:

I have these values in my cell A46: 2000 3000 4000 5000 3000 2000

Code I'm trying (doesn't seem to work)

Set d = CreateObject("Scripting.Dictionary")
            a = Split(objExcel.Sheets("ACCOUNT_CODE Day").Range("A46"), " ")

            For i = 0 To UBound(a)
            If Not d.Exists(a(i)) Then d.Add a(i), ""
            Next

            'Now your Dictionary should have unique values from your cell and you can recombine them:
            Set exlTest = objExcel.Workbooks.Open(strPathExc)
            objExcel.Application.Visible = True
            exlTest.Sheets("ACCOUNT_CODE Day").Activate 
            'exlTest.Sheets("ACCOUNT_CODE Day").Cells(37, 4).Value = +transNumbAcum
            'exlTest.Close xlSaveChanges
            'objExcel.Quit  

            objExcel.Sheets("ACCOUNT_CODE Day").Range("A46") = Join(d.Keys, " ")
            exlTest.Close xlSaveChanges



via Chebli Mohamed

Why DependencyProperty.UnsetValue is being passed into Equals()

I'm developing a simple WPF application. Currently, the application only manages a list of video games in a ComboBox. The game list is serialized to/from an XML file.

The feature that is currently broken is the ability to select a game from the ComboBox which makes it the "active" game to be managed. The active game will be stored as an application setting. To achieve this, I'm using two-way databinding and binding the SelectedItem in the ComboBox to the SelectedGame in the ViewModel.

When I run the application and select an item from the ComboBox, I get a null reference exception on the Game.Equals(Game other) method. While debugging, I saw that DependencyProperty.UnsetValue is being passed as the argument to the overriden Game.Equals(object obj) method which causes obj as Game to make obj null.

I don't understand why Equals is being called in the first place when all I'm doing is selecting an item from the ComboBox value, so I'm guessing it's something native to WPF. The code doesn't seem to hit any other breakpoints before heading to the Equals method, so I'm not even sure how to debug the issue. I also don't understand where DependencyProperty.UnsetValue is coming from. I'm just utterly lost here and would appreciate any insight, including how I can debug this further.

EDIT: As Glen alluded to, Equals must be called by some underlying component of WPF. My solution, at least for now, was to simply add a null check to my Equals override.

Model Class

public class Game : IEntity, IEquatable<Game>
{
    [XmlElement("Name")]
    public string Name { get; set; }

    [XmlElement("ExecutablePath")]
    public string ExecutablePath { get; set; } 

    public Game(string name, string executablePath)
    {
        Name = name;
        ExecutablePath = executablePath;
    }

    private Game() { } // Required for XML serialization.

    public bool Equals(Game other)
    {
        return Name.EqualsIgnoreCase(other.Name);
    }

    public override bool Equals(object obj)
    {
        return Equals(obj as Game);
    }
}

ViewModel

public class GamesViewModel
{
    // The GameRepository retrieves the game collection from the XML file.
    private readonly GameRepository _gameRepository;

    public ObservableCollection<Game> Games
    {
        get { return new ObservableCollection<Game>(_gameRepository.Items); }
    }

    public Game SelectedGame
    {
        get { return Settings.Default.ActiveGame; }
        set
        {
            if (!Settings.Default.ActiveGame.Equals(value))
            {
                Settings.Default.ActiveGame = value;
                Settings.Default.Save();
            }
        }
    }

    public GamesViewModel()
    {
        _gameRepository = RepositorySingletons.GameRepository;
    }
}

View

<UserControl x:Class="ENBOrganizer.UI.Views.GamesView"
             xmlns="http://ift.tt/o66D3f"
             xmlns:x="http://ift.tt/mPTqtT"
             xmlns:mc="http://ift.tt/pzd6Lm" 
             xmlns:d="http://ift.tt/pHvyf2" 
             xmlns:local="clr-namespace:ENBOrganizer.UI.ViewModels" 
             mc:Ignorable="d" >
    <UserControl.DataContext>
        <local:GamesViewModel />
    </UserControl.DataContext>
    <Grid>
        <ComboBox Name="GamesComboBox" ItemsSource="{Binding Games}" SelectedItem="{Binding SelectedGame}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Padding="5,0,0,0" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>
</UserControl>



via Chebli Mohamed

How to prevent web service from starting if install condition not met on WebSphere Application Server?

We have a web service running on WebSphere Application Server.

When certain critical properties are missing, we want to prevent the EAR containing the web service from starting outright thus preventing more esoteric and complicated errors downstream.

What is the best way to achieve that? We tried throwing runtime errors, they log well, but that does not prevent the application from starting.

Thank you in advance for any help, Bertrand



via Chebli Mohamed

Dynamics CRM 2015 - update Opportunity Owner id via javascript

I'm trying to update the OwnerId on an opportunity in Dynamics CRM 2015.

So far I am using the following code but my changes are not taking effect.

Xrm.Page.data.entity.attributes.get('ownerid').setValue('487ecd0c-d8c1-e411-80eb-c4346bade4b0')
Xrm.Page.data.entity.save();

This is a view of the GetValue call.

enter image description here

The attribute type is "lookup" and when I call getIsDirty(), it returns false after I do setValue, so I'm not sure if that's the correct way to set the value on a "lookup" type.



via Chebli Mohamed

Bash readline history previous line before history expansion

There are usually the keys Up and Ctrl+P mapped to previous-history Readline command in Bash which moves back in history to previous line with history expanded.

How to move to the previous line before History expansion? E.g. to line like

!!:gs/20010910/20010911/



via Chebli Mohamed

Should I use sync or blocking channels?

I have several go routines and I use unbuffered channels as sync mechanism. I'm wondering if there is anything wrong in this(e.g. compared with a WaitGroup implementation). A known "drawback" that I'm aware of is that two go routines may stay blocked until the 3rd(last) one completes because the channel is no buffered but I don't know the internals/what this really means.

func main() {
    chan1, chan2, chan3 := make(chan bool), make(chan bool), make(chan bool)
    go fn(chan1)
    go fn(chan2)
    go fn(chan3)
    res1, res2, res3 := <-chan1, <-chan2, <-chan3
}



via Chebli Mohamed

Polymer 1.0: google-signin sign in still success when user revoke permissions

I am using a google-signin element to have access to user's access scopes. I found, if I as a user authorize the my app with certain scopes, then revoke those scopes without clicking on "Sign out" button (basically the google-signin element), the google-sign is result as onSigninSuccess event even without the authorization.

This is weird. It should be onSigninFailure because the app doesn't have the corresponding scopes of authorizations from the user.



via Chebli Mohamed