deferred-execution

Add defer attribute to javascript_include_tag Rails

我怕爱的太早我们不能终老 提交于 2019-12-03 01:08:34
Is there some way to add the defer attribute easily using the javascript_include_tag helper in Rails? I.e., is there some easy way to turn <%= javascript_include_tag "blah.js" %> into <script defer src="blah.js"></script> <%= javascript_include_tag "blah.js", :defer => "defer" %> This will get you (in development): <script defer="defer" src="/assets/blah.js" type="text/javascript"></script> You can also do <%= javascript_include_tag "blah.js", defer: true %> which is more consistent with other switches. 来源: https://stackoverflow.com/questions/10982375/add-defer-attribute-to-javascript-include

Using LINQ .Select() to cast into new type is TOO slow?

 ̄綄美尐妖づ 提交于 2019-12-02 04:30:36
Current project, broke head over this problem: Client Repository: public class ClientRepository { // Members private masterDataContext _db; // Constructor public ClientRepository() { _db = new masterDataContext(); } public IEnumerable<ClientName> GetCorporateClientNames() { return _db.corporate_client_tbs.Select(o => new ClientName { id = o.id, name = o.company_name }).AsEnumerable(); } public IEnumerable<ClientName> GetRetailClientNames() { return _db.retail_client_tbs.Select(o => new ClientName { id = o.id, name = o.name }).AsEnumerable(); } // Define return type public class ClientName {

Why is this LINQ query not executed when using foreach?

爱⌒轻易说出口 提交于 2019-12-01 03:21:20
When creating new objects in a LINQ statement, for example: var list = new List<string>() { "a", "b", "c" }; var created = from i in list select new A(); With class A looking like this: class A { public string Label; } And then modifying properties in A with a foreach loop: foreach (var c in created) { c.Label = "Set"; } Why are the values not set when accessing the objects in the IEnumerable afterwards. E.g. the following assertion fails: Assert.AreEqual("Set", created.ElementAt(2).Label); I wonder why this happens. I would expect the foreach-statement to execute the query, and trigger the

Why is this LINQ query not executed when using foreach?

佐手、 提交于 2019-11-30 23:30:54
问题 When creating new objects in a LINQ statement, for example: var list = new List<string>() { "a", "b", "c" }; var created = from i in list select new A(); With class A looking like this: class A { public string Label; } And then modifying properties in A with a foreach loop: foreach (var c in created) { c.Label = "Set"; } Why are the values not set when accessing the objects in the IEnumerable afterwards. E.g. the following assertion fails: Assert.AreEqual("Set", created.ElementAt(2).Label); I

What is a browser event loop?

蓝咒 提交于 2019-11-30 06:29:19
I have been doing some web application programming using GWT and have been confused by the term "browser event loop". I have encountered situations where I need to execute deferred commands and "do something" after the browser event loop completes. I would like to know as to what exactly it is and what happens during the event loop process and in which order? A browser event loop is a thread started by the browser that is constantly scanning for and running different events, just like it sounds. As events occur they are put in the event queue and run in turn by the one event thread. Your

How is transforming this iterator block a functional change?

我怕爱的太早我们不能终老 提交于 2019-11-29 09:02:24
Given the following code snippet: public class Foo { public IEnumerable<string> Sequence { get; set; } public IEnumerable<string> Bar() { foreach (string s in Sequence) yield return s; } } is the following snippet semantically equivalent, or is it different? If it is different, how do they function differently? public class Foo2 { public IEnumerable<string> Sequence { get; set; } public IEnumerable<string> Bar2() { return Sequence; } } This question is inspired by this question which is asking a different question about a similar situation. The two are not equivalent. The semantics of how

What is a browser event loop?

£可爱£侵袭症+ 提交于 2019-11-29 06:13:04
问题 I have been doing some web application programming using GWT and have been confused by the term "browser event loop". I have encountered situations where I need to execute deferred commands and "do something" after the browser event loop completes. I would like to know as to what exactly it is and what happens during the event loop process and in which order? 回答1: A browser event loop is a thread started by the browser that is constantly scanning for and running different events, just like it

yield returns within lock statement

我与影子孤独终老i 提交于 2019-11-28 10:45:43
if i have a yield return in a lock statement does the lock get taken out on each yield (5 times in the example below) or only once for all the items in the list? Thanks private List<string> _data = new List<string>(){"1","2","3","4","5"}; private object _locker =new object(); public IEnumerable<string> GetData() { lock (_locker) { foreach (string s in _data) { yield return s; } } } Edit: This answer was wrong, but I can't delete it as it was marked as correct. Please see @Lockszmith's answer below for the correct answer. Paraphrased: The lock is NEVER released between each yeald return. NOTE:

Understanding jQuery Deferred.pipe()

吃可爱长大的小学妹 提交于 2019-11-28 07:30:17
I am trying to implement the jQuery Deferred.pipe() method for the following scenario: Add a user in DB via $.ajax() Get response whether user was added correctly or not. If successfully added, get all the user list from server via $.ajax() Display the list via jQuery templates This is something which I tried: var addUserSuccess = function( data ) { if ( data.returnCode !== "success" ) { return $.Deferred().reject('Error saving user'); } getUsers(); } var addUser = function() { return $.ajax(url, { type: "POST", data: { username: 'test' }, contentType: "application/json", dataType: "json" });

Deferred evaluation with lambda in Python

帅比萌擦擦* 提交于 2019-11-28 03:13:22
问题 In a loop, I am trying to defer the comparison the two value()s of two Nodes to a later time. class Node(): def __init__(self, v): self.v = v def value(self): return self.v nodes = [Node(0), Node(1), Node(2), Node(3), Node(4), Node(2)] results = [] for i in [0, 1, 2]: j = i + 3 results.append(lambda: nodes[i].value() == nodes[j].value()) for result in results: print result The results are all True (because i,j==2,5 for all the lambdas). How can I defer the execution of the lambda until it is