Posts

SQL Server: how to generate comma separated string for distinct values in aggregated columns in group by statement -

Image
this question has answer here: how use group concatenate strings in sql server? 16 answers i generate comma separated string distinct occurrences aggregated column in group statement. have: select column1, ???statement involving column2??? mytable group column1 i can't figure out put between questions marks. assuming have got following tables: use tsql2012 if object_id('teststackoverflow') not null drop table teststackoverflow create table teststackoverflow( column1 varchar(100) not null, column2 varchar(100) not null, constraint pk2 primary key(column1,column2) ) insert teststackoverflow(column1,column2) values ('value1','t1'), ('value1','t2'), ('value1','t3'), ('value2','t5'), ('value2','t6'), ('v...

ruby on rails - redirect_to not working with ajax -

i have created ajax form in bootstrap modal creates new post database. form is: <%= form_for @post, remote:true, :html => {:id => "share-needs-form"} |f| %> <div class="modal-body"> <div id="shareneedsmodalfirststep"> <div class="row" style="margin-bottom: 10px"> <ul class="error-alert hidden share-needs-form-errors col-lg-10 col-centered" id="share-needs-error-alerts"></ul> </div> <div class="row"style="margin-bottom: 10px;"> <div class="col-lg-10 col-centered"> <%= f.text_field(:title, :class => "form-control", :placeholder => "add title e.g need designer, in return can code you", :id => "title") %> </div> </div> <div class="row" style="margin-bottom: 10px;"> ...

python - need to access a manytomanyfield in django templates -

so have these models: class cofifiuser(models.model): user = models.onetoonefield(user) class quoteidea(models.model): creator = models.foreignkey(cofifiuser,related_name="creator") text = models.textfield(max_length=250) votes = models.charfield(max_length=100,default="0") votes_received = models.manytomanyfield(cofifiuser) created_at = models.datetimefield(auto_now_add=true) and want: if request.user.username in item.votes_received.all <button class="disabled">button</button> else <button class="btn btn-primary">button</button> is same thing button on facebook . cannot give more 1 page ( in python/django ) please need here :) something that's important keep in mind here performance implication of having query many-to-many relationship each comparison, or pre-loading of m2m data see if user in votes_received queryset. in case this, opt de-normalized way boolean comparison. cr...

How to make Python refuse negative index values? -

basically working on script want neighbouring values 2d list. implementing simple version, take index , add , subtract 1 in directions , catch out of range indexing try except . try: keys.append(keyboard[index[0]][index[1]-1]) except indexerror: pass try: keys.append(keyboard[index[0]][index[1]+1]) except indexerror: pass try: keys.append(keyboard[index[0]-1][index[1]-1]) keys.append(keyboard[index[0]-1][index[1]]) keys.append(keyboard[index[0]-1][index[1]+1]) except indexerror: pass try: keys.append(keyboard[index[0]+1][index[1]-1]) keys.append(keyboard[index[0]+1][index[1]]) keys.append(keyboard[index[0]+1][index[1]+1]) except indexerror: pass but of course, when ran wasn't catching exceptions when subtracting 1 0, indexing last element of list instead. i test 0 values, means i'm using 2 different tests determine what's valid index, , using if statements way feel messier (as i'd have nesting in case). plus fee...

java - Run scheduled tasks chain -

i need run scheduled tasks 1 one different delays after previous task being executed. example. there tasks list , delays list. torun = {task1, task2, ..., taskn} delays = {100, 9, 22, ..., 1000} now need run task1 throgh 100ms, task2 after task1 through 9ms, task3 after task2 through 22ms , on. i using javafx. task can use ui update methods, changing nodes positions. forces me use platform.runlater() method, because if don't, have exception "not on fx application thread". know method runs runnable object after undefined amount of time. , depending of how time can vary have 2 ways. 2.1 continue use platform.runlater() method if call time < 1-2ms. 2.2 find solution, don't have yet. shortly actual task. record user actions mouse move, mouse click, , application events. after need replay actions. go through every action using scheduledexecutorservice.schedule() , , inside of every action task put next task scheduler. , goes wrong every time, or n...

How to send a newsletter with mailjet's Rest Java API? -

i see in v3 reference in mailjet's site http://dev.mailjet.com/email-api/v3/newsletter-send/ there following example: curl -s -x post \ --user "$mj_apikey_public:$mj_apikey_private" \ https://api.mailjet.com/v3/rest/newsletter/:id/send but can't find in code example how should done mailjet java api https://github.com/mailjet/mailjet-apiv3-java ? according response of mailjet's support java wrapper not completed , majority of rest api still don't cover. if going use mailjet-apiv3-java library should ready implement rest commands.

sql server - EF6 - Generating unneeded nested queries -

i have following tables: main_tbl: col1 | col2 | col3 ------------------ | b | c d | e | f and: ref_tbl: ref1 | ref2 | ref3 ------------------ | g1 | foo d | g1 | bar q | g2 | xyz i wish write following sql query: select m.col1 main_tbl m left join ref_tbl r on r.ref1 = m.col1 , r.ref2 = 'g1' m.col3 = 'c' i wrote following linq query: from main in dbcontext.main_tbl join refr in dbcontext.ref_tbl on "g1" equals refr.ref2 refrlookup refr in refrlookup.defaultifempty() main.col1 == refr.col1 select main.col1 and generated sql was: select [main_tbl].[col1] (select [main_tbl].[col1] [col1], [main_tbl].[col2] [col2], [main_tbl].[col3] [col3] [main_tbl]) [extent1] inner join (select [ref_tbl].[ref1] [ref1], [ref_tbl].[ref2] [ref2], [ref_tbl].[ref3] [ref3] [ref_tbl]) [extent2] on [extent1].[col1] = [extent2].[ref1] ('g1' = [extent2].[...