text:
Q: Spring more than one bean of type: crash early When I load a webpage in my Spring web application, I get the following error:
java.lang.IllegalStateException: More than one bean of type [com.Car] found, you have to specify the name of the bean

How can I force Spring to detect this problem at startup?
Please do note that I know how to solve the problem on itself (e.g. removing one of the two definitions)
I just want to be sure that there aren't any other cases that I will not find before opening every single webpage.

A: Create a BeanPostProcessor which keeps track of number of instances created for each bean definition in the application context. THis will throw an exception for bean types that you want to restrict and will halt the container initialization. Hence you can detect the errors earlier
    public class DuplicateBeanDetectionBeanPostProcessor implements BeanPostProcessor{

    private Map<Class<?> , Boolean> beanTypeFound = new HashMap<Class<?> , Boolean>();

    private Set<Class<?> typesToRestrictToOneInstance = new HashSet<Class<?>>();

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException{
    return bean;
    }

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException{
    Set<Class<?>> restrictedTypesForBean = findRestrictedTypesForInstance(bean);
    if(!restrictedTypeForBean.isEmpty() && typeAlreadyFound(bean , restrictedTypesForBean)){
       throw new IllegalStateException("Bean of type : " + restrictedTypeForBean + " already found in the application context";
    }
    return bean;
    }

    private Set<Class<?>> findRestrictedTypesForInstance(Object bean){
      Set<Class<?>> restrictedTypesForBean = hew HashSet<>();
      Class<?> superClass = bean.getClass();
    while(superClass != null){
       for(Class<?> restrictedType : typesToRestrictToOneInstance){
          if(restrictedType.isAssignableFrom(superClass){
               restrictedTypesForBean.add(restrictedType);
          }
       }
    }
    return restrictedTypesForBean;
    }

    private boolean typeAlreadyFound(Object bean , Set<Class<?>> restrictedTypesForBean){
    for(Class<?> restrictedTypeForBean : restrictedTypesForBean){
        if(beanTypeFound.get(restrictedTypeForBean)){
            return true;
        }
        else{
           beanTypeFound.set(restrictedTypeForBean , true);
        }
    }
    return false;
    }

    public void setTypesToRestrictToOneInstance(Set<Class<?>> typesToRestrictToOneInstance){
   this.typesToRestrictToOneInstance = typesToRestrictToOneInstance;
}
}

Add the BeanPostProcessor to your application context through suited to your configuration mechanism. Then set all types that you want to restrict


text:
Q: C++ Overloaded function, one takes takes argument of base class, another takes argument of derived class Sorry if this is a duplicate question but couldn't find any relevant results myself.
I have class A, and derived class B which is derived from A.
I have the following overloaded function:
void print(A* obj) {
    printf("This is an A object.");
}
void print(B* obj) {
    printf(This is a B object.");
}

And I do the following in my main.
B* bObj = new B;
print(bObj);

What exactly are the rules by which is chosen to call? Does the order in which the overloaded functions are declared matter?

A: The order doesn't matter. The rules are such that the most specific overload must be taken - in this case the B version.
Please also note that the function call is inserted at compile time - that is, it doesn't depend on the actual runtime type and therefore does not insert a virtual/dynamic lookup. So should you change to
A* bObj = new B;
print(bObj);

Then a call to the function take A* will be called.

A:
What exactly are the rules by which is chosen to call?

The overload resolution rules. They are described in the section [over.match] of the standard. The section is about 20 pages long, so concise description may be helpful: The candidate whose arguments require unambiguously the least conversions is preferred.

Does the order in which the overloaded functions are declared matter?

Yes, but only in relation to the function call. Only the overloads that have been already declared are considered:
void print(A*);

void foo() {
    B* ptr = nullptr;
    print(ptr); // will call void print(A*)
}

void print(B*);

Otherwise, the order of declaration is not significant.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Multiple count distinct on sql Server 2014 Im facing a issue with multiple count on a single query.
Im using SQL server 2014 with very high end configuration server. i.e, 224 GB RAM, 4k PIOPS.
Since I have created CLUSTERed COLUMN STORE index on tables, now i can't create any indexes.
Please find my query. fct_sale_line has 1.75 B rows and I have created CLUSTERED COLUMN STORE index on it.
SELECT dim_customer.gender_code,
       gender,
       date_key,
       COUNT(DISTINCT fct_sale_line.CUSTOMER_CODE),
       COUNT(DISTINCT fct_sale_line.customer_key),
       SUM(sale_net_val)
FROM dbo.fct_sale_line fct_sale_line,
     dbo.dim_customer dim_customer,
     dbo.dim_product dim_product,
     dbo.dim_store dim_store
WHERE fct_sale_line.date_key >= 20120126
AND   fct_sale_line.date_key <= 20130126
AND   department_code IN ('400','500','600','700','800')
AND   fct_sale_line.customer_key = dim_customer.customer_key
AND   fct_sale_line.product_key = dim_product.product_key
AND   fct_sale_line.store_key = dim_store.store_key
GROUP BY dim_customer.gender_code,
         gender,
         date_key
ORDER BY gender;

the query is never ending. its running .. running .. running and running.
But when i removed one of COUNT(DISTINCT ) and kept another, then it is fetching the result in 1 min's. Can any one help me resolve this issue.
Even i have tested with the single table. please see time taken by each query.
SELECT date_key,
       SUM(sale_net_val),
       COUNT(1)
FROM dbo.fct_sale_line fct_sale_line
WHERE fct_sale_line.date_key >= 20120126
AND   fct_sale_line.date_key <= 20130126
GROUP BY date_key;

Took only 1 Sec's to fetch the result.
SELECT date_key,
       SUM(sale_net_val),
       COUNT(1),
       COUNT(DISTINCT fct_sale_line.CUSTOMER_CODE)
FROM dbo.fct_sale_line fct_sale_line
WHERE fct_sale_line.date_key >= 20120126
AND   fct_sale_line.date_key <= 20130126
GROUP BY date_key;

Took 29 Sec's, but still acceptable(b'z of count distinct).
SELECT date_key,
       SUM(sale_net_val),
       COUNT(1),
       COUNT(DISTINCT fct_sale_line.CUSTOMER_CODE),
       COUNT(DISTINCT fct_sale_line.CUSTOMER_KEY)
FROM dbo.fct_sale_line fct_sale_line
WHERE fct_sale_line.date_key >= 20120126
AND   fct_sale_line.date_key <= 20130126
GROUP BY date_key;

--Never Ending(Waited for 45 Min's)
Can anyone let me know is it a known issue in the sql server 2014.
Regards
Noor

A: First of all, Clustered Columnstore Indexes are extremely effective in the terms of the IO, so that alone should help you avoiding reading unnecessary data.
Without seeing the execution plan I would guess that your problem might be lying in the Execution mode:
check on your execution plan if your Hash Match (Aggregate) (group by parameters for example) are running in the Batch Mode and if you are Spilling on the disk.
The following query for the ContosoRetailDW will take some amount of time to run, because of the Spilling which occurs in Row Mode at the Hash Match (second line after eager spool):
select count( distinct StoreKey ) as 'Distinct Stores'
, count( distinct CustomerKey ) as 'Distinct Customers'
, count( distinct CurrencyKey ) as 'Distinct Currencies'
from dbo.FactOnlineSales sales
    inner join dbo.DimPromotion prom
        on sales.PromotionKey = prom.PromotionKey
where prom.DiscountPercent = 0
group by sales.LoadDate, sales.ProductKey

Sorry, I can't put an execution plan image because of my low reputation – it is being blocked right now.
You might need to run a more selective query (with more precise predicates),
you can increase memory grants by modifying your query,
and also you can use the Segment Elimination Technic, which should help quite a lot for distinct counts: http://www.nikoport.com/2014/04/16/clustered-columnstore-indexes-part-29-data-loading-for-better-segment-elimination/
Best regards,
Niko


text:
Q: cname issue with hosted ecommerce Having a bit of an issue with a store that has just been set up with shopify. The problem is with cnaming the domain into the shopify subdomain. I have www working just fine so www.no1gadgetstore.co.uk cnames to no1gadgetstore.shopify.com. However, http://no1gadgetstore.co.uk does not resolve and I can't set up a cname for a non www record.
Does anybody have a simple solution to this, as everything I've come across so far is too complicated to even try.
Many thanks
Dave

A: From one of our support guys:

sounds like he just needs http://no1gadgetstore.co.uk to be a URL redirect to http://www.no1gadgetstore.co.uk - the CNAME should only be on the www. address.

For more on this, check out http://wiki.shopify.com/DNS


text:
Q: Can Windows 7 be installed on a Macbook with Leopard using BootCamp? The Apple website says
http://support.apple.com/kb/HT3920

Summary
Apple will support Microsoft
  Windows 7 (Home Premium, Professional,
  and Ultimate) with Boot Camp in Mac OS
  X Snow Leopard before the end of the
  year. This support will require a
  software update to Boot Camp.

so what about Leopard?  This seems not so typical of Apple to say something that is quite incomplete... to mention about Snow Leopard and not Leopard -- many people still run Leopard.

A: Yes, it will work. This blog post explains in detail how to go about installing.

A: Instead of waiting for this functionality to be implemented why don't you use a Virtual Machine? I have a mac too and I find it to be much easier to run a Virtual Machine in OSX than deal with having to restart every time you want to switch operating systems. VirtualBox is pretty good and free. Parallels has more features but it also costs money. You could also use VMWare Fusion. Honestly VirtualBox is good enough and has enough features. One thing that is for sure, they are all compatible with Windows 7. I have had no problems on both Leopard and Snow Leopard running Windows 7 in a Virtualized Environment.
To answer your question in the comment. According to this article there are other virtualization options for Mac OS. How good they are, and if they are free, you will have to look into yourself. If I was you I would just use VirtualBox. Just because it's free doesn't mean you shouldn't give it a chance.


text:
Q: How do you write a "Hello, world!" for Comet in AngularJS? I've looked and haven't been able to find out how to handle a basic Comet proof-of-concept in AngularJS. I'm looking at Comet implemented by the client making repeated Ajax calls, rather than streaming JavaScript.
If I have a server-side CGI:
#!/bin/bash
echo "Content-type: application/json"
echo ""
echo "'"Hello world at "`/bin/date`"'!'"'"

What is a bare-bones AngularJS proof of concept that will query the server every second, and modulo network latency and the like, display a "Hello world!" that includes the server time?

A: The Plunkr
http://plnkr.co/edit/6kpLplq5hy9e2sXMaEsG?p=preview
The HTML
<!DOCTYPE html>
<html>

  <head>
    <script data-require="angular.js@*" data-semver="1.2.15" src="http://code.angularjs.org/1.2.15/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-app="myApp" ng-controller="MyCtrl">
    {{data.theDate}}
  </body>

</html>

The JS
angular.module("myApp", []).service("UpdatingService", function($http, $timeout){
  var service = {
    data:{},

    getData:function(){
      $http.get("someData.json").success(function(result){
        angular.copy(result, service.data)
        service.data.theDate+="    "+new Date();
      });
    }
  };

  cancelRefresh = $timeout(function myFunction() {
      service.getData();
      cancelRefresh = $timeout(myFunction, 1000);
  },1000);

  return service;
}).controller("MyCtrl", function($scope, UpdatingService){
  $scope.data = UpdatingService.data;
});

So I show how I would generally do this above.  First create a service that handles doing the request and storing the data.  Then make a controller and inject said service.  Within the service inject the $http and $timeout services from angular so we can make the ajax request and can repeat the request thereby polling the server.  Since there's no real setInterval the $timeout callback creates a new $timeout to continue the cycle, you can use the cancelRefresh if you need to stop the timer at some point details on that in the link below.
using setInterval in angularjs factory


text:
Q: open source e commerce solution I tested the OpenCart but I noticed that is quite problematic to change the layout.
I need to use a specific layout that i have done, so, my question is: what is the ecommerce open source solution that permit a more easy adaptivity of the layout?
as you can imagine is complicated test all e commerce solutions...
thanks

A: The fantastic CMS Umbraco is open source and there's a super easy to use and style low budget e-commerce called Tea Commerce to it.
It's based on ajax and has a very simple JavaScript library which makes it both fun and easy to setup. You can do any design with Tea Commerce.
/Rune