How can I tell whether a generator was just-started?

This only works in Python 3.2+: >>> def gen(): yield 0; yield 1 … >>> a = gen() >>> import inspect >>> inspect.getgeneratorstate(a) ‘GEN_CREATED’ >>> next(a) 0 >>> inspect.getgeneratorstate(a) ‘GEN_SUSPENDED’ >>> next(a) 1 >>> inspect.getgeneratorstate(a) ‘GEN_SUSPENDED’ >>> next(a) Traceback (most recent call last): File “<stdin>”, line 1, in <module> StopIteration >>> inspect.getgeneratorstate(a) ‘GEN_CLOSED’ So, the … Read more

C#: yield return range/collection

No, there isn’t I’m afraid. F# does support this with yield!, but there’s no equivalent in C# – you have to use the loop, basically. Sorry… I feel your pain. I mentioned it in one of my Edulinq blog posts, where it would have made things simpler. Note that using yield return recursively can be … Read more

Rails 3: yield/content_for with some default value?

You can use content_for? to check if there is content with a specific name: <% if content_for?(:page_title) %> <%= yield(:page_title) %> <% else %> <%= default_page_title %> <% end %> or <%= content_for?(:page_title) ? yield(:page_title) : default_page_title %> Then in your views you can specify the content like <% content_for :page_title do %> Awesome page … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)