Posts

c# - How to run 2 async functions simultaneously -

i need know how run 2 async functions simultaneously, example check following code: public async task<responsedatamodel> datadownload() { responsedatamodel responsemodel1 = await requestmanager.createrequest(postdata); responsedatamodel responsemodel2 = await requestmanager.createrequest(postdata); //wait here till both tasks complete. return result. } here have 2 createrequest() methods runs sequentially. run these 2 functions parallel , @ end of both functions want return result. how achieve this? if need first result out of 2 operations can calling 2 methods, , awaiting both tasks `task.whenany: public async task<responsedatamodel> datadownloadasync() { var completedtask = await task.whenany( requestmanager.createrequest(postdata), requestmanager.createrequest(postdata)); return await completedtask; } task.whenany creates task complete when first task of of supplied tasks completed. returns 1 task completed can resu...

php - mysql query AND with OR not work -

in query want write logic , operation or . query not work. select * `data` `city`='mycity' , performdate='4' , (curtime() >= `valid_from` or curtime() <= `valid_to`) , perform_type='ptype' i think (curtime() >= `valid_from` or curtime() <= `valid_to`) this logic not work untested --- $time = curtime(); select * data city = 'mycity' , performdate = '4' , perform_type = 'ptype' , ($time >= 'valid_from' or $time <= 'valid to'); source: http://www.techonthenet.com/mysql/and_or.php

ruby - Rails 4 HABTM has_many :through -

team, looking specific (newbie) situation on rails 4 association. have 3 models: class brand < activerecord::base has_many :lines, dependent: :destroy has_many :products, through: :lines, dependent: :destroy end class line < activerecord::base belongs_to :brand has_and_belongs_to_many :products end class product < activerecord::base has_and_belongs_to_many :lines has_many :brands, through: :lines end this configuration works when trying check products under specific brand (or line ) , viceversa: different brands (or lines ) available specific product . however, when comes delete/destroy there issue. getting rspec error: activerecord::hasmanythroughcantassociatethroughhasoneormanyreflection: cannot modify association 'brand#products' because source reflection class 'product' associated 'line' via :has_and_belongs_to_many. we have made research on exception, checked rails api, no luck, examples found showing different model configu...

python call a function with kwargs -

i have function: def myfunc(): kwargs = {} = 1 b = 2 kwargs.update(a=a, b=b) newfunc(**kwargs) and newfunc def newfunc(**kwargs): print its not giving value of 1 whats wrong ? two things. first, kwargs argument in myfunc empty dict, won't pass parameters. if want pass value of a , b newfunc , can either use kwargs = {'a':1, 'b':2} newfunc(**kwargs) or newfunc(a=1, b=2) in both cases, 'a' , 'b' in kwargs dict of newfunc function. second, should extract argument kwargs dict in newfunc . print kwargs.get('a') should suffice.

Crashlytics : Android Studio Gradle Error related to XML -

i getting error while building app crashlytics error:(2) error parsing xml: prefix must not bound 1 of reserved >namespace names there com_crashlytics_export_strings.xml added crashlytics automatically. mind file added module project inside main project . main project doesn't have file. use android studio plugin. has following content. <?xml version="1.0" encoding="utf-8" standalone="no"?> <resources > <!-- file automatically generated crashlytics uniquely identify individual builds of android application. not modify, delete, or commit source control! --> <string xmlns:ns0="http://schemas.android.com/tools" name="com.crashlytics.android.build_id" ns0:ignore="unusedresources,typographydashes" translatable="false">0acfc26a-32c4-4a2e-b19b-fullkey</string> </resources> while building following file generated. @ xmlns:ns0 turn xmlns:ns1 in generated ones ...

c# - In repository pattern, should I use database model as my View model or should I create separate ViewModel for that? -

self explanatory, have model map 1:1 db example: public class user { [key] public int userid { get; set; } public string firstname { get; set; } public string lastname { get; set; } } is there downside if use in view cshtml example : @model user or should create viewmodel this public class userviewmodel { [required] public string firstname { get; set; } [required] public string lastname { get; set; } } and bind view @model userviewmodel the idea of programming view should not know data comes ... using database model in view breaks sign . the best use viewmodel , , in future pleased choice example, view might 1:1 database table, imagine designer wants add recent "messages", that's new table call based on user... with viewmodel can add , edit view , controller, if use 1:1 need create brand new viewmodel... then, views have viewmodels , don't... messy! to out, can use automapper viewmodels construction, a...

SQL server 2012 - return variable value from a dynamic script -

i'm trying run dynamic script return variable can pass in rest of script. i've couple of ways of google, think still haven't got syntax correct, therefore getting error or null value returned. can please advise i've gone wrong. for example: return value variable @table_name asia database , set variable appended table name retrieved table , t5148 id table turn table name variable. have set variables script sits when other scripts loops thank you declare @table_name nvarchar(50) declare @database nvarchar(50) declare @id nvarchar(50) declare @sql nvarchar(max) set @database = 'asia' set @id = 't5178' set @sql = n'select @table_name = ''@database''+table_name ''@database''+tables (nolock) id = ''@id''' exec sp_executesql @sql, n'@table_name nvarchar(50) output', @table_name output select @tran_table if not wrong, need : declare @table_name nvarchar(50) decl...