Posts

mysql - sql order by rand() with highest value shown more frequently -

as title describes, im looking write sql (mysql db) thats displays random records highest value shown more others. select cpc advertisement order rand(), cpc desc the above code not work expected. heres im after: i have 10 advertisers each setting own cpc (cost per click) budget. advertiser heighest budget have his/hers advert show more others, yet being random. user_id | cpc | ------------------ 1 | 0.10 | 2 | 0.03 | 3 | 0.20 | 4 | 0.04 | 5 | 0.55 | 6 | 0.12 | so user 5 have advert displayed more freqently others 5, 3, 6, 1, 4, 2 - in order of impressions respectively. bit assume google adwords work, higher users budget more impressions he/she have. i know no 1 likes rand() due performance have no more 100 advertisers. regards i best way so: select user_id, cpc advertisement order rand() * cpc desc this make adverts appear randomly, user_id 5 theoretically appear 5.5x more user_id 1, fair.

java - JMX runtime input lookup class is not available because this JRE does not support JMX -

i getting above error when try running application. sure has updating log4j log4j2 since if not reference log4j2.xml file error gone. why getting error? here full stack trace, if helps: 2016-09-12 12:01:26,124 main warn jmx runtime input lookup class not available because jre not support jmx. jmx lookups not available, continuing configuration. java.lang.classcastexception: cannot cast org.apache.logging.log4j.core.lookup.jmxruntimeinputargumentslookup org.apache.logging.log4j.core.lookup.strlookup @ java.lang.class.cast(unknown source) @ org.apache.logging.log4j.util.loaderutil.newcheckedinstanceof(loaderutil.java:168) @ org.apache.logging.log4j.core.util.loader.newcheckedinstanceof(loader.java:301) @ org.apache.logging.log4j.core.lookup.interpolator.<init>(interpolator.java:106) @ org.apache.logging.log4j.core.config.abstractconfiguration.<init>(abstractconfiguration.java:116) @ org.apache.logging.log4j.core.config.defaultconfiguration....

ruby on rails - Products specs in admin panel spree -

i've got piece of specs code: https://gist.github.com/mpanasiewicz/9751c1de65e9920d8ad6d6f866ef0ae5 there problem because 302 code instead of 200 or 404(if sth went wrong). think 302 because redirects me. require 'rails_helper' rspec.describe spree::admin::productscontroller, type: :controller describe 'get synchronize' stub_authorization! let!(:variant) { create(:variant) } 'updates @products pkb starpacks details' spree_get :synchronize, id: variant expect(response).to have_http_status(200) end 'returns record not found if product not exist' spree_get :synchronize, id: 0 expect(response).to have_http_status(404) end end end i've got 'stub_authorization!' think doesn't work ideas wrong code? thanks! i think have redirect_to method in update method. redirect responds 302 code. if want code 200 should use render method instead redirect_to , i...

caching - Google Memcache vs Local disk cache? -

i want build mobile app. should cache data on google cloud memcache or it's better store data mobile phone local memory ? faster ? , type of data should put in cache in case of mobile app ? thanks you. any data want make available user in offline mode (device not connected internet) should cached on device itself. may want cache data in online mode (e.g. email app may cache emails last 7 days) , updates cache when user refreshes or server pushes new emails. memcache on google cloud use in application server caching data not change don't have keep loading same data database every request, improving performance. it faster access data on local device compared accessing data cloud.

matlab - Indexing Cell arrays for more efficient performance -

i have following code display 9-by-3 cell array: data = cell (9,3); col1 = [2, 3, 5, 7, 8, 11, 12, 15, 16]; col2 = {[1 1], [1 5], [3 9], [4 2], [4 6], [6 2], [7 6], [6 9], [9 9]}; col3 = {[2 3 4 5 8],[1 3 5 8],[1 2 5 7 8],[1 2 3 6 7],[3 4 7 8],[2 4 8 9],[2 4 5 9],[4 5 7 9],[2 6 7 8]}; k = length(data); = 1:k data{i,1} = col1(i); data{i,2} = col2{i}; data{i,3} = col3{i}; end data please, can code more efficiently written using form of indexing? thanks. your have written code assign 9 x 3 cell array, can written as: data2 = [num2cell(col1') col2' col3'] data2 = [ 2] [1x2 double] [1x5 double] [ 3] [1x2 double] [1x4 double] [ 5] [1x2 double] [1x5 double] [ 7] [1x2 double] [1x5 double] [ 8] [1x2 double] [1x4 double] [11] [1x2 double] [1x4 double] [12] [1x2 double] [1x4 double] [15] [1x2 double] [1x4 double] [16] [1x2 double] [1x4 double]

python - Pandas Apply groupby function to every column efficiently -

this question has answer here: apply multiple functions multiple groupby columns 2 answers in pandas can apply groupby functions every column in dataframe such in case of: pt=df.groupby(['group']).sum().reset_index() lets want apply lambda function lambda x: (0 < x).sum() count cells value in them , include count of total items in each group. there more efficient way apply columns other repeating code: import pandas pd df=pd.dataframe({'group':['w', 'w', 'w', 'e','e','e','n'], 'a':[0,1,5,0,1,5,7], 'b':[1,0,5,0,0,2,0], 'c':[1,1,5,0,0,5,0], 'total':[2,2,15,0,1,12,7] }) #check how many items present in group grp=df.groupby(['group']) pt1 = grp['a'].apply(lambda x: (0 < x).sum()).reset_index() pt2 = grp['b'].apply(lambda x: (0 ...

sql server - T-SQL inconsistent sp_send_dbmail results -

This summary is not available. Please click here to view the post.