Hiding Row in DataGridView Very Slow

Question: I have a DataGridView in a Winforms app that has about 1000 rows (unbound) and 50 columns. Hiding a column takes a full 2 seconds. When I want to hide about half the rows, this becomes a problem.
    private void ShowRows(string match)
    {
        this.SuspendLayout();
        foreach (DataGridViewRow row in uxMainList.Rows)
        {
            if (match == row.Cells["thisColumn"].Value.ToString()))
            { row.Visible = false; }
            else
            { row.Visible = true; }
        }
        this.ResumeLayout();
    }

I did some testing by adding by addingConsole.WriteLine(DateTime.Now)around the actions, androw.Visible = falseis definitely the slow bit. Am I missing something obvious, like setting IsReallySlow = false? Or do I have to go ahead and enable Virtual Mode and code up the necessary events?
Answer: It looks to me like you should be using row filters instead.
Try using a DataView as your binding source and use DataView.RowFilter to hide rows or show rows of your choosing.
DataGridView myGridView = new DataGridView();
DataView myDataView = myTable.DefaultView;
myGridView.DataSource = myDataView; // DataView that allows row filtering

myDataView.RowFilter = string.Format("thisColumn <> '{0}'",match);  // this will hide all rows where "thisColumn" = match

Answer: In most cases the property DataGridViewAutoSizeColumnMode makes a DGV slow.
Your performance increases drastically when you change all columns to Mode DataGridViewAutoSizeColumnMode.None. Afterwards you can reset it in the same way to the previous state.
For Each col As DataGridViewColumn In myDGV.Columns
   col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
Next

You will see that hiding some of 1000 columns now takes only 1-2 seconds. With other properties (SuspendLayout, Hiding the whole form etc.) I could not find any effect.
Answer: As mentioned above its the DataGridViewAutoSizeColumnMode that kills the performance. Instead of looping through every row of the DatagridView and changing the autosize mode, do it instead for the whole Datagridview, by initially turning it off and then turning it on again after you have performed the required row logic
YourDatagridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None

     // Perform row visibility here...

YourDatagridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells

Answer: Just a question.. Is it possible to pass that match parameter to the database query or procedure and get the rows which are not matching the records. That way you just dont have to worry about showing/hiding and It would be faster as well as you will no longer be looping.  This would also work as the number of records increase with time..
Just a thought which may not be applicable for you..let me know.
Answer: To implement the optimization to speed up the hidding of rows in a DataGridViewRow based on the reset of the AutoSizeColumnsMode property you can use this class:
Public Class DataGridViewUtil
    Private dgv As DataGridView
    Private sizeColumnModeBackup(-1) As DataGridViewAutoSizeColumnMode

    Public Sub New(dgv As DataGridView)
        Me.dgv = dgv
    End Sub

    '''
    ''' Prepare datagridview before we do the row hidding to speedup it
    '''
    ''' <remarks>We use a method based on reseting the AutoSizeColumnMode
    '''  property to None, therefore it will be necessary to call
    '''  HidingRowsSpeederAfer() when we finish hiding rows</remarks>
    Public Sub HidingRowsSpeederBefore()
        ReDim sizeColumnModeBackup(dgv.Columns.Count)
        For Each col As DataGridViewColumn In dgv.Columns
            sizeColumnModeBackup(col.Index) = col.AutoSizeMode
            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
        Next
    End Sub

    '''
    ''' Restore DataGridView state changed when HidingRowsSpeederBefore()
    '''  was called
    '''
    ''' <remarks>This procedure must be called after the row hidding has been
    '''   done and requires a previous call to HidingRowsSpeederBefore()</remarks>
    Public Sub HidingRowsSpeederAfter()
        If dgv Is Nothing Then
            Throw New NullReferenceException("The assigned datagridview is null")
        End If
        If sizeColumnModeBackup.Length < dgv.Columns.Count Then
            Throw New Exception("Mismatch on internal SizeColumnMode array, " &
                    "maybe you forgot to call HidingRowsSpeederBefore()")
        End If
        For Each col As DataGridViewColumn In dgv.Columns
            col.AutoSizeMode = sizeColumnModeBackup(col.Index)
        Next
    End Sub
End Class

How to use it:
    Dim dgvUtil As New DataGridViewUtil(yourDataGridView)
    dgvUtil.HidingRowsSpeederBefore()

    '... do your row hidding chores here

    dgvUtil.HidingRowsSpeederAfter()

Hiding Row in DataGridView Very Slow


Help identifying bug on rhubarb

Question: Today I discovered these guys on my rhubarb hanging around the flowery parts. They look way bigger than aphids (2-4mm). Any idea what they are?
Answer: I don't know what the bugs are but they're probably just after the nectar in the flowers; you need to remove that flower stalk asap. Rhubarb should never be allowed to flower because it takes energy away from the rest of plant, reducing the number of stalks, the part you want. Keep an eye on it ongoing to nip out any further flowering shoots.
Comment: I know that there's the rule of "don't let your rhubarb flower", but  my personal experience tells me it's not _that_ crucial. The rhubarbs  I am familiar with (multiple cultivars, different gardens) always had more stalks than we needed, _despite_ the flowers, which are quite impressive. Enough water and a bit of nutrition via compost is more important than cutting out the flower stalks.
Answer: Looks like a harlequin ladybug. The beetle shape is of course familiar and the colour markings are not typical of anything except the huge variety of markings ladybugs present. Ladybugs go for aphids so they won't be chewing on the rhubarb as such; examine the rhubarb flowers to see if there are aphids busy there. If you have any other crops with aphids on try moving one of these beetles to that area and see if it says thank you very much.

Help identifying bug on rhubarb


How Internet Assigned Numbers Authority (IANA) handles free ip address holes in their ip allocation pie?

Question: Let's say an internet service provider (ISP) bought 1024 ip addresses from IANA and after 1 year that ISP business fails and it returned those ip addresses back to IANA. Now there must be a hole of free ip addresses that is created in the ip address pie. How IANA handles these free holes which eventually accumulate overtime.
Comment: I'm voting to close this question because it is nothing to do with programming.
Comment: I don't think IANA is involved.  Any free addresses will be handed back to the relevant [regional internet registry](https://en.wikipedia.org/wiki/Regional_Internet_registry)
Comment: Where can I ask computer network related questions?
Answer: I dont know how IPv6 are assigned but I'm familiar with IPv4. First ISP's reserve IP classes not specific IP addresses so for example, they reserve IP class A IP 126.96.36.199/8 Which gives them so many hosts IP range that the ISP can internally allocate to it's users, So if the ISP went out of business only one free IP class will be free for others to use.
Also, IANA allocate IP blocks to Regional Internet Registries(RIRs) around the world which are 5 (Africa, Europe, ...) continents. Those RIR will then allocate smaller blocks to the ISP which in turn will allocate single IP address to its customers, so the whole system is hierarchical in nature.


Allow me to save an answer

Question: I browse Stack Overflow quite frequently and I often find that when I come across a helpful answer I want to be able to save the best answer for later. It would be nice if I could save those snippets/answers to my account so later I can quickly find what I was looking for.
Comment: This is not quite what you're looking for, but may be close enough. See that star to the left of a question? You can use that to mark a question as a favorite, for later review from your profile. See [How do favorite questions work?](http://meta.stackexchange.com/questions/53585/how-do-favorite-questions-work).
Answer: You deliberately mention answers, however, would marking the question as a favorite work for you?
FAQ entry on how Favorites work
Otherwise, the best option might be a note/snippet tool (such as Evernote or Springpad etc) that you use for saving information from the web which you can reference later on.
Comment: That does indeed work and I was unaware of the feature. It's not exactly what I was after, but it gets me close :) Thanks.

Allow me to save an answer


Accurate Rainfall with TBRG

Question: For an accurate flood forecast, up to what height maximum from the ground level one can put the TBRG without any obstacles and still receive accurate rainfall?
Answer: The top of all rain gauges need to be 30 cm above the ground. The lateral placement of all rain gauges is a distance that is twice the height of the nearer tallest item (tree, building, fence, etc.).

Accurate Rainfall with TBRG


How much power should I run to my workshop?

Question: I have a work shop currently powered with a 20 amp breaker coming from my main panel. I want to dedicate that to a small hot water heater, and run more power for other appliances. I was thinking of running more power from my house's subpanel. I'd like to also power a small heat/ac window unit, microwave, plus some receptacles and lights. Would one more 20 amp circuit be enough, or should I run two 20 amp circuits?
Comment: Is the shop a separate building?
Comment: What make and model is your electrical panel? Is this workshop attached to the house, or in a separate outbuilding? What size are the wires running to the workshop, and are they run using a cable or individual wires in a conduit?
Comment: Describe better your panels and the CB configuration Main Panel Feeder (is this the 20amp CB) to Sub Panel CB, Sub panel CB (is 20Amp?) etc..
Comment: one is pushing it if you want to AC+microwave at once; two more 20 amps should be fine.
Comment: how far away is your shop from the panel? do you have to worry about voltage drop?
Answer:
power a small heat/ac window unit [ How much current will that use ?  I am thinking at least 20 AMPS ]
A microwave - fixed (like over range or in wall) it must have a dedicated circuit - moveable countertop models 20 Amp
Receptacles 20 Amp
lights 15 AMP

Will one more 20 amp be enough ? No - you will need at least 3 more depending .

Do you have a sub panel that feeds your shop or in the shop ?
Do you only have a 20 Amp run from the main to the shop sub panel ?
What CB Amperage is in the main panel feeding the shop sub panel ?

If you have 20Amp CB in your main panel feeding the Sub panel in your shop - you will need to upgrade the sub panel feed CB upgraded, Wiring from Main to Sub panel upgraded, Sub Panel might also need to be upgraded.
Comment: where does one get a 2,200 watt microwave or AC (20A)? my biggest window AC uses 800w (7A), and a typical BIG counter microwave uses ~1500w (13A)
Comment: better safe than sorry for sure; i just think the estimates are a bit pessimistic in the energy star age...
Comment: @dandavis depends on your microwave. Mine is internally equipped with a Slow Blow 20 amp fuse. In the NEC you will see 20amp. Circuits are de-rated so a 2200 watt device requires more than a 20Amp breaker, 1600 Watts derated is 20 Amps. Regardless the NEC code is what matters and a 10 amp breaker is not going to be acceptable for the window AC ; Part VII of Article 440, 440.32 210.23(a) 210.23(b) . Most likely it will have two outlets and op will surely attempt to use the other outlet - BTU rating and other factors - 20 Amp is a practical expectation.
Comment: I have not ever seen a microwave for residential use with a 20 amp plug the internal fuse has nothing to do with its rating. Better to understand the loads than chime in.  Most AC units are also 15 amp plugs with a few I have seen at 20a. We don't know if it is a detached building or not.
Comment: @EdBeal read the ops question again - note op is not asking to run one unit, but multiple units a 1000 watt microwave and a 1500 watt heater / or 1200 watt ac unit is over 2200 watts - as typical with these things people ask about the majors and start plugging in extras as well. The op will need more than a 20 amp circuit.


How to delete by attribute from shapefile in SAGA command

Question: I have lot of shapefiles to erase polygons with same attribute form them. It is usually an easy task when do manually, but how can I use SAGA-GIS command?
Any help?
Comment: Is each saga_cmd an independent command? How can I join these two commands in one script? How to save modified shapefile? Can you write example? I cant't deal with that task:(
Answer: Not a SAGA-GIS user but looking at the Module List, my guess would be to:

Select your polygons by attribute
saga_cmd shapes_tools 4 -INPUT [-FIELD ] [-EXPRESSION ] [-CASE ] [-COMPARE]

Delete selection from shapes layer
saga_cmd shapes_tools 7 -INPUT


The whole website is out of whack after deleting Cache from within the Magento Admin Panel

Question: Magento 2.4.2-p1
Porto theme

We have:

Installed fresh Magento 2.4.2-p1
used the Magento Migration Tool to migrate from Magento 1.9.4
installed the Magento Porto theme
Amasty installed a bunch of their extensions which broke the site; they then asked us to request that our hosting company disables the Pagespeed module which they have done but it broke things even more so they asked that the hosting company turns the Pagespeed module back on but it was not good so they advised to keep it off for that account in our VPS.

This was then working fine (as Amasty fixed their end and hosting disabled Pagespeed for that account) even yesterday and this morning but then I decided to delete all the different Caches by going to the Admin Panel and clicking the different buttons to delete Cache. Afterward, the website broke completely where it still has the colors, etc. but displays everything kind of in 1 column in the body of the front end and everything on the back end is text-based only. I've gone back to hosting asking them to make sure the Pagespeed module is turned off for that account. They have done that but it did not fix the problem. The hosting company is suggesting we turn the Pagespeed module off for our entire hosting account but I'm afraid that will break the Magento 1.9.4 websites?
Any idea of what might be going on or how I can find out what is going on and how to fix this?
I have done the following via SSH but it did not help:
php bin/magento cache:flush
php bin/magento cache:clean
php bin/magento indexer:reindex

UPDATED:
I just found this article and asked our hosting company to delete Redis Cache as it has previously resolved the same issue:
Magento site is frequently getting CACHE issue and failing to serve CSS, site is getting broken page
Answer: Deploy content and check after that
php bin/magento s:s:d
This will generate all the static content which you might have flushed


Why Some objects or prefabs don't respond to mesh collider?

Question: I imported some assets and, I used some prefabs from that assets. Some of them responds when I add the component of mesh collider to it and disable the ability of going through with it. But some of the is not is not. I can still go through them. Is it a good practice to add 3d cube and disable that or, is there any other way to disable of going through it?
Answer: I remember having something like this happen to me as well.

Is it a good practice to add 3d cube and disable that or, is there any other way to disable of going through it?

If it works, it works. But personally, I just manually add a primitive collider (box, sphere, cone etc) for simple meshes and a mesh collider (https://docs.unity3d.com/Manual/class-MeshCollider.html) if I have a complex mesh.
As for the meshes not responding to collision, try checking the static checkbox.
If a game object is static, it will not move. See: https://docs.unity3d.com/Manual/StaticObjects.html
Comment: Yeah It will work but I think that It's not kind of good adding lot of mesh colliders for the child objects of a prefab or adding primitive colliders for them. I had to cover up about 700 mesh colliders for child objects becuase of this problem.
Comment: I see. Mesh colliders are more costly to solve though. Did you fix your problem though?
Comment: I solve my problem up to some level by adding each mesh collider for children objects. Still I need to know how to activate the mesh collider for parent object that enables the collider to the children objects as well.
Answer: Following from @user1026622's answer. Mesh colliders do not collide with each other, unless the convex option is checked. This is fine for low poly models but not recommended for higher poly models.


Technique to sync medium/large amounts of data

Question: I implemented sync for my app (with a REST backend), it works well but there are some problems:

Blocks - Since I don't want to overwrite possible inputs of the user during sync, I block the UI (progress overlay) during sync. This of course affects negatively the user experience.
Size - If the data is large the request may take a lot and there may also be out of memory errors processing the response.

So I'm thinking how to improve this. For point 2, I thought to simply paginate the request, i.e. send how many entries I want and a reference date (e.g. creation date) to make the database query simpler.
But point 1 is a problem independently what I do for point 2, as long as the user can manipulate data during sync, there's a possibility this this data will be overwritten with the sync result. I could for example lock the client database during sync, such that only the sync process can write to it, and queue the client operations, but what happens when these operations try to e.g. increment some data which was just changed by sync and this leads to a different result than what the client intended to do.
My app is about personal grocery management so the requirements are not super strict, if an update is lost or something it's not tragic. I'm looking for a balanced solution, which is easy to implement while keeping a fairly good UX.
Comment: I would need to know more about the architecture to offer a meaningful answer. You speak of a client database, so I presume their is a client app that has a local DB, which I presume is being synced with the server DB and is done for performance reasons? Why is it not feasible to have a server app that interacts with the DB to provide the client views and interface into the DB?
Comment: Might be interesting to take a look on this example: https://meteorhacks.com/understanding-mergebox/ DDP is a protocol which fixes the kind of issues you mention. Their approach may be of good use for this issues. It shows how to reduce the amount of data synced and how to solve conflicts.
Answer: Blocks
The problem you are referring to for scenario 1 is consistency, that is, having 2 stores holding the same information and needing them to be consistent.
In a distributed environment like this, optimistic concurrency can prevail, meaning, instead of locking, allow for anything to change at any time, and build-in a mechanism to track overlaps.
First step, is there any data which truly has overlaps?  Or is your data set truly just a set of items?  If the latter, then if you are in a situation where items can be added by any client, and they replicate down, then you simply need each client to keep track of which items have not yet been pushed.
If there can be overlaps, for example, you are managing documents (sounds unlikely), then you either have locking, or allow concurrent updates and flag overlaps as a problem to be resolved by the consumer.  Examples of this pattern:

Software version control systems like git, mercurial, subversion, etc.
Evernote
Google Docs

If you have ever worked with software version control, you'll recognize the idea of a merge conflict and/or overlap.  That is the same problem you have.  Source control systems like Vault avoid this problem by each client treating each file as read-only until a file is "checked out", which creates a mutually exclusive lock across all clients.  Git, on the other hand, will identify conflicts, merge them if it can do so, and if not, force the end user (developer) to manually merge.
Evernote allows my wife and I to each edit our grocery list.  To minimize conflicts, we sync as often as possible, but there will always be a chance of us having conflicting changes, which has happened.  Evernote simply appends conflicting document versions on top of each other with markers indicating there was a conflict.
In a case where concurrent changes are rare, usually this sort of optimistic concurrency is ideal.  In a highly concurrent transaction system, locking may be a better approach.
Size
As far as data size, you have two options I can think of:

Pagination
Streaming

Pagination is probably the way I'd go because it's simpler to code, usually, and easier to track your progress, and in a way, gives you more control.  With my recommendations for handling consistency above, hopefully pagination becomes a non-issue.
Streaming may be an alternative for you too and would reduce the risk when it comes to consistency since you'd have a single round-trip.  Streaming basically means to change this data flow:
results = getResultsFromServer();
for (result in results) {
  doSomething(result)
}

to:
getResultsFromServer((result) => {
  doSomething(result)
})

In the former, the entire result set must be buffered so that you can iterate over it, even though you only consume the data one at a time in a forward-only manner.  In the latter, you only need one item at a time.  I implemented this approach once for a large report that would overwhelm our production servers when a customer ran it for a very large date range.
Answer: I think I understand that your main concern is that the input is directly bound to the local database, and the sync also writes to the local database. So if the user saves some value during sync, it is undefined as to which information will be shown. (Last one wins.)
One solution that I often use for UI is having the user editing a copy of the data and only saving it back to the database after they have chosen to save it (even if that is an implicit choice like clicking off the input, applicable to things like To Do lists). That also makes canceling an operation pretty easy: throw away the edited copy.
Doing something like that will help with your sync story, because you can persist the changes from sync to the local database without disturbing the user's input. And if they "save" during a sync, you can wait to save until after the sync finishes. You wouldn't need to block. If you need the "in progress" data to be persistent (say, in case the device crashes), you could still save it... just in a different place in the database.
As far as incrementing some value and arriving at a different result, this is a classic case for using idempotent operations. A simple example to illustrate:
AddQuantity(1); // result depends on previous quantity
SetQuantity(13); // result does not depend on previous quantity
                 // can be applied numerous times w/o changing result
                 // idempotent operation

Using literal numbers is contrived of course, but 13 could be pre-calculated and carried in the queue, instead of calculating it afterwards via the AddQuantity method.

When you get multiple users synchronizing the same items, you are going to run into concurrency conflicts. One user updates and syncs, while another is updating from an old version, and when the second user goes to sync, they overwrite the first user's changes.
At that point, usually the answer is some sort of concurrency control like Optimistic Concurrency with version numbers (or ETags). The server will then raise a conflict if you try to update an old version of the item. It will be up to you on how to handle that conflict. You could display a message to the user and ask them what to do. (Hint: they will probably always choose to overwrite the server version with their version.) Or you could silently take one of the versions as authoritative. Or you could try to apply an algorithm to merge the differences (if applicable to your situation). Basically, do what provides the most value for your app, with trade-offs you can live with.
Note that if you are syncing while the user is editing something, you have the opportunity to detect updates to the item they are changing and display a banner "This item has been updated by another user."


Are the Doctor Who books canon?

Question: Are the Doctor Who novels considered canon? Do they tie into the storylines, or are they one-off adventures/monster-of-the-week stories?
I'm asking specifically about the New Series Adventures, featuring the 9th, 10th, and 11th Doctors.
Comment: They're not, because there's no such thing as Doctor Who canon: http://www.paulcornell.com/2007/02/canonicity-in-doctor-who.html
Comment: last weeks *episode* of Doctor Who is barely canon half the time...
Answer: That is actually two different questions, I think, with different answers:
Are They Canon?
As Micah points out, Doctor Who famously has no canon, as everyone involved in producing the show has very notably avoided ever making any statements about what is or isn't canonical. The closest I think we have is Russel Davies once mentioning that they didn't worry too much about what happened in the books when they wrote the episodes.. but then again, most Doctor Who writers barely worried about what happened last season on television when they wrote episodes, so that's not a big change.
The status in the RTD era can basically be summed up as: "This show has almost no internal consistency anyway, on top of which, The Time War, so there.)
Do They Tie In With The Storylines?
Yes, but very little. This is actually something new to the NSA books; in the previous novels like the Virgin New Adventures there was, to my knowledge, never any references made to plots from the novel written into any future episodes. This may be partly because the novels often continued with a Doctor's incarnation well past the end of his televised run.
In the NSA, there is carryover from the televised product into the novels: a lot of the 9th Doctor's novels included the whole "Bad Wolf" plotline as part of them. Also, there was at least one case where a NSA plot was referenced, though offhandedly, in a television episode. (The Doctor mentions a trip to the Justicia system, which happened in a novel.)
Mostly, however, the NSA novels cover things that happened "in between" the television programs. They will roughly follow the basic plot of the show -- they will, for example, change companions in the novels around the time they change companions on TV -- but they are, for the most part, stand-alone.
Comment: Another example, the 8th Doctor in the Miniepisode "The Night of the Doctor" names some of his companions, Charley, C'rizz, Lucie, Tamsin and Molly, all from Big Finish audio productions. It was the first time that the television series directly referenced Big Finish characters.
Comment: In general, Moffet seems to be slightly more worried than previous writers about keeping some loose kind of "canon", likely due to his being a big classic Who fan himself; he even found a classic-canon-friendly way to give The Doctor more regenerations.
Answer: I think the most answerable question is how the New Series Adventures and other books fit into the Doctor Who stories - the novels are independent of the television storylines, save that they may feature the same characters and/or races as the television series.  All of the ones I've come across fit the one-off adventure/monster of the week description (though that doesn't preclude a story arc occurring that I'm yet to encounter).
As to whether or not they are canon, I think the essay Micah linked to gives a good summary.  Specifically, there has been no indication that the books are canon, with one exception:

The closest we ever got to a BBC pronouncement on canonicity was a couple of years after the end of the original series of Doctor Who. The show's last production team declared that Virgin's Doctor Who novels, the New Adventures, were an official continuation of the series, overseen by the last producer, John Nathan-Turner, with the last writing team onboard, heading towards the aims that that team had put in place.

The Doctor Who landscape this was announced in has since changed significantly, as Virgin lost the rights to Doctor Who novels and the reboot has occurred.
Overall I think the best summary is that the books can be considered canon unless the television series contradicts them.
Answer: The BBC oversaw Virgin's New Adventures and considered them TV Tie-in, meaning they fit within the established story set by the TV series. Same goes for the Missing Adventures, the Past Doctor Adventures, New Series Adventures and the Telos novellas. TV sets the stage, the books flesh it out. Remember, key phrase "TV Tie-in".
There is no Doctor Who canon and never could there be. Yes, there is official Doctor Who and there is Doctor Who continuity. Not all Doctor Who fits in to the main continuity of the series. Many of the BBC's Eighth Doctor Adventures deliberately took place in alternate universes like in Blue Angel. Sometimes the series deliberately wrote itself out of the time line like Alien Bodies to The Ancestor Cell and beyond, all taking place in a paradox ridden and some say aborted time line. Neat trick. Some eras of Doctor Who didn't take place in our universe, so no effect was mane in the time line, like the Doctor Who Big Finish 8th Doctor main range. Then there are Short Trips and Side Steps. Again, real life Doctor Who, but set in alternative universes, or take adventures on a different path than that of the established history of the Doctor. The comics of the Seventh Doctor often took place in alternative story lines as well. But they were all official Doctor Who.
A TV adventure is forty five minutes now. That's like 50 to 60 pages of script? The audios have the freedom to go further with a story tan 45 minutes. The novels have practically no bounds. 300 pages some of these stories. In depth ad jam packed at times. Just consider the Wilderness Years to be a time when Doctor Who glaciered out. It was a time when Doctor Who could do anything. but the New Adventures were the continuing stories of the Seventh Doctor's life. No doubts. Probably the best series of DW novels ever written.
Answer: I'd have thought that anything Doctor Who broadcast by the BBC is canonical, with a slight grey-area over BBC Radio (where a number of Big Finish audio plays have been broadcast). Of course, that would make Dimensions in Time canonical!
Comment: This doesn't sound like you're sure. If you *are* sure please cite a source.
Answer: There is no established canon for Doctor Who. Doctor Who canon is this: There is no canon. If the BBC say it's official Doctor Who, then it is 100% bonafied Doctor Who. TV show takes precedence, but the novels and audios are official.
The BBC has never said there is a Doctor Who canon. The TV show is publicly owned by the British people, bless them, and it's a rule that the TV show be self contained because one has to buy a book, or buy an audio adventure. The rights belong to the BBC but the medium changes the economics. Even with this stipulation, nothing says other mediums "don't count". That's silly.
If it still boggles the mind to include such a vast rich history of our hero, just remember the TV show gives you every thing you need, but that in no way, diminishes the history outside the television medium.
Answer: Sorry. That's just not true. Doctor Who DOES have a canon. it has always had a canon. BBC Law dictates that ALL original BBC Drama Series have self-contained continuities. The viewer must "get the whole story" from JUST watching the tv show. Anything that the television viewer could not get from watching the tv show is not canon, nor will it ever be.
It is interesting that people keep linking to Paul Cornell's BLOG when discussing this. First off, it's a BLOG, not an official pronouncement from the BBC. Second, it's riddled with factual errors. One such error is that the Virgin New Adventures were "the official continuation of the series overseen by the last production team". It is well-known that John Nathan Turner had nothing to do with these books. It is less well-known however that the series wasn't actually cancelled in 1989, simply rested. Thus the show as set to continue ITSELF.
As far as "official", bs. BBC Drama (or presently BBC Wales) makes the tv show "Doctor Who". BBC Worldwide (which has nothing whatsoever to do with the tv show) licenses out the copyrights of the show to outside businesses who then produce merchandise. This merchandise has nothing at all to do with the Production Office. This merchandise includes action figures, posters, puzzles, books etc. Every producer in Doctor Who history has stated that they have nothing to do with this merchandising, and people like Letts, Turner and Davies have publicly stated that they don't even read etc. most of it.
What is interesting is that all the people who scream the loudest that "There is no canon!" are people like Cornell, Orman etc. In other words the people who write all these novels. They KNOW what they are producing is licensed merchandise that is no more canon than a pair of TARDIS boxer shorts, but they won't admit it. So they post factually inaccurate blogs about how "Canon doesn't exist" and about how the books "were the official continuation".
Let me just state this clearly: NOTHING that isn't part of the tv show is canon. Kate Orman will cry from the rooftops that there's "no such thing as canon", thereby convincing herself (and sadly others) that her books are equal to the tv works of Davies, Holmes or Dicks. Prior to actually writing for the show, Cornell would not shut up about how "there is no canon". But there IS a canon. it's the TV show. Kate Orman has NEVER written for Doctor Who. What she has done is write licensed merchandise using Doctor Who copyrights. The fact that certain books (e.g. Human Nature by the aforementioned Cornell) and audios (e.g. Jubilee) have been adapted for the tv show shows that they aren't canon. RTD also totally ignored things like the Torchwood audios, because they aren't canon.
The next time someone smugly declares "there is no such thing as canon in Doctor Who" or "the books/comics/audios/whatever are every bit as real as the television show" take a closer look at WHO is saying it, and WHY they are saying it. Most likely they're someone who has written loads of this merchandise, and are trying to elevate it to the same status as the TV show. Cornell's infamous blog was written before he wrote for the TV show. What he had done up to that point was a lot of books, audios etc. None of it was canon. Bernice Summerfield does not exist in the Doctor Who canon.

The policy is even cited Cornell in his anti-canon BLOG. There is an online PDF at the BBC's website explaining their policy. What people forget is that the BBC is NOT a business corporation like ITV or CBS or FOX. It is a publicly-funded public service, that is monitored and controlled by the British Government. Attempting to equate Moffat(or any other BBC-employed Producer) with Lucas or Whedon or Roddenberry is a mistake. It's chalk and cheese. BBC Programmes are funded by the UK Public's tax money and Licence Fees. All BBC employees are essentially civil servants working to provide the Public with a service(in this case Entertainment). Yes, that DOES sound silly, but that was the way the BBC was since before World War II, and the basic structure has never changed, although it's far more slickly-run today. BBC Enterprises(now BBC Worldwide) was set up as the BBC's commercial arm, originally to sell BBC shows to other countries(thereby making more money to pump back into the BBC). Soon, they branched out, and realised that they could sell the rights to other companies to produce merchandise using BBC copyrights. The money the BBC made from these licensing deals could likewise then be put back into the BBC. But, it's MERCHANDISE. It's unrelated to the Doctor Who continuity/canon/whatever you want to call it itself.
Yes, this is long and "rambling". But there are SO MANY errors in the usual "there is no canon! The producers have never stated a canon position!" bs lie. Again, Paul "No Future" Cornell has shouted tha "there is no canon position!" because he has written so many of these books. Did you ever hear Robert Holmes say "there is no canon"? Barry Letts stated publicly that the Production Team had nothing at all to do with the spin-offs like books, comics etc. RTD totally ignored things like the Torchwood audios, and publicly stated that the 'Looms' don't exist in canon.
The problems are:a)the people who make this spin-offery will obviously want it to be "just as real" and that's why the Virgin authors will never miss an opportunity to say how "there's no such thing as canon" b)anyone(including me) who has spent a LOT of money on spin-offery doesn't like the ''idea'' that they've spent money(and subsequently time) on something that "doesn't really exist". But like it or not that's how it is.
The bottom line which people miss is this:Doctor Who itself doesn't need its own canon policy. In fact, if it tried to define its own canon policy, it would literally be illegal. That's because all original BBC Television Drama has the exact same canon policy. Again Doctor Who is a BBC copyright, and is funded by BBC tax pounds. The Doctor Who production Office is NOT an independent company like Lucasfilm. It is a department of BBC Drama. The producer is a salaried BBC employee, NOT some Lucas-type maverick. Whatever canon policy the BBC dictates, Doctor Who follows. It is not the place for even Russell T. Davies or Steven Moffat, let alone a hired writer like Paul Cornell, to state what the policy is. You don't ask the guy who works the drive-through window about McDonald's Corporate Policy, do you?
Comment: Incidentally, even accepting the BBC as the arbiter of what is canon, the 'it must be from the show' doesn't hold water -- see [this BBC Press Release](http://www.bbc.co.uk/pressoffice/pressreleases/stories/2010/04_april/08/doctor_who.shtml) regarding the Doctor Who games. Excerpt: "Players will encounter new and original monsters, in stories which form part of the overall Doctor Who canon."
Comment: I suspect that "must get the whole story from JUST watching the tv show" means that they are not allowed to force viewers to buy a book, or visit a web page, just so they can follow the TV show. That's a totally sensible thing for a TV broadcaster to say, but it's totally different from saying that they reject everything outside the TV show.
Comment: I'm not really familiar with BBC policy - do you have a link that I could read for more info about the BBC's position on all info being available through the TV show?
Comment: It's a lovely rant, but can you back it up?  You've stated various things that are sensible enough.. but they aren't consistent across different SciFi franchises; see Star Wars for a simple example.  Do you have anything from the BBC, or the writers to back up your statement?  Incidentally, the lack of a single writer or group performing governance may be part of why you commonly get the 'No Canon' response.  Star Wars shows a good example of a [defined canon policy](http://starwars.wikia.com/wiki/Canon) -- got anything equivalent for Doctor Who?

Are the Doctor Who books canon?


Animate triangles – rotate "roll" along all their sides

Question: I'm animating a lot of triangles. Every triangle will roll along its edge over and over again.
I have tried animating the pivot point with an empty but that method is getting too complex with many triangles.
Is there any easier way to do it?
Comment: The [Animation Replicator with Offset addon](https://www.youtube.com/watch?v=nVRn2SXTXGs) might help.
Answer: You can use animation nodes. Here you have a simple setpup on how to animate polys changing its pivot point.
Comment: please include a blend file at least, if this is intended to make someone interested in animation nodes you can give them something that will run and show what you mean. screenshots are such a pain to try to recreate in a nodeview (especially if someone hasn't used the add-on before).
Comment: If you don't provide more info, this is practically a non-answer. (even if animation nodes is a very good solution for this)
Comment: @JorgeLosillaMartínez  Without an explanation on what the logic is behind this node tree, very few users will find this answer useful. Please add more detail to it.


Is a room with only a shower the same as a normal bathroom?

Question: In terms of the halachos in Shulchan Aruch Orach Chaim Siman 85 (which places is it ossur to say Krias Shema) would a small room with just a shower head have the same dinim as a room with a toilet or a room with just a bathtub?
Comment: @DoubleAA You're allowed to think Torah when naked, if I remember correctly
Comment: I heard that a rabbi of this generation (I can't remember who) told his students to review their learning in the shower that wasn't attached to a room with a toilet
Comment: @ba While unclothed? And if not, what were they doing hanging out in the shower?
Comment: In a changing room, where people are only sometimes unclothed it would be ok to talk about Torah, but one should not say Bruchot or Hashem's name (eg. Shalom aleichem). It's not the same a toilet, where there could be excrement. However, modern toilets remove the waste entirely, and once the smell is gone it's arguably just a changing room.
Comment: @ba Yes, you are correct. When naked you are allowed to think Torah, but not say it. But you are not allowed to even think it when excrement is present. Couples are recommended to think good thoughts (i.e. divrey torah) when alone together.
Answer: Did you also see Siman 84? It talks about a Bathhouse, which is what a room with just a shower or tub is.
However, a modern bathroom, where everything is flushed away probably also has the din of a bathhouse.
Siman 85 applies where the waste is actually present.


Duplicity + Amazon S3 Glacier. How Much "Unfreezing" to Resume Backup

Question: It's been a couple of months since I last did a Duplicity backup [to Amazon S3] and, in the meantime thanks to an automatic 30-day rule I have on my Amazon buckets,  my S3 backup has been moved from the 'normal' Reduced Redundancy storage to Amazon Glacier.
Now, when I run duply <backupname> verify -v9 I see the output getting hung up at the end with the following [This is after leaving it running overnight, as each restore from Glacier takes several hours]:
-------------------------
Chain start time: Sun Dec  1 14:49:39 2013
Chain end time: Fri May  1 20:18:38 2015
Number of contained backup sets: 16
Total number of contained volumes: 1438
 Type of backup set:                            Time:      Num volumes:
                Full         Sun Dec  1 14:49:39 2013               318
         Incremental         Wed Dec 11 13:21:16 2013                 1
         Incremental         Wed Dec 18 19:48:07 2013                15
         Incremental         Tue Dec 31 18:45:25 2013                 4
         Incremental         Sat Jan  4 18:06:42 2014                 9
         Incremental         Sat Feb 15 15:14:59 2014                15
         Incremental         Sat Feb 15 15:43:26 2014                 1
         Incremental         Mon Feb 17 10:18:31 2014                 3
         Incremental         Mon Feb 17 10:24:57 2014                 1
         Incremental         Wed Feb 19 14:35:22 2014                 1
         Incremental         Wed Feb 19 14:38:52 2014                 1
         Incremental         Sun Mar  2 22:37:32 2014               514
         Incremental         Wed Jul  9 20:12:22 2014                26
         Incremental         Sat Dec  6 22:57:27 2014               262
         Incremental         Fri May  1 18:37:57 2015               266
         Incremental         Fri May  1 20:18:38 2015                 1
-------------------------
No orphaned or incomplete backup sets found.
Using temporary directory /tmp/duplicity-Q5My3G-tempdir
Registering (mktemp) temporary file /tmp/duplicity-Q5My3G-tempdir/mktemp-DGtqcn-1
File duplicity-full.20131201T144939Z.vol1.difftar.gpg is in Glacier storage, restoring to S3
Waiting for file duplicity-full.20131201T144939Z.vol1.difftar.gpg to restore from Glacier
File duplicity-full.20131201T144939Z.vol1.difftar.gpg was successfully restored from Glacier
Registering (mktemp) temporary file /tmp/duplicity-Q5My3G-tempdir/mktemp-AQObTq-2
Waiting for file duplicity-inc.20131201T144939Z.to.20131211T132116Z.vol1.difftar.gpg to restore from Glacier
File duplicity-inc.20131201T144939Z.to.20131211T132116Z.vol1.difftar.gpg was successfully restored from Glacier
Registering (mktemp) temporary file /tmp/duplicity-Q5My3G-tempdir/mktemp-U6R9NX-3
File duplicity-inc.20131211T132116Z.to.20131218T194807Z.vol1.difftar.gpg is in Glacier storage, restoring to S3
Waiting for file duplicity-inc.20131211T132116Z.to.20131218T194807Z.vol1.difftar.gpg to restore from Glacier
File duplicity-inc.20131211T132116Z.to.20131218T194807Z.vol1.difftar.gpg was successfully restored from Glacier
Registering (mktemp) temporary file /tmp/duplicity-Q5My3G-tempdir/mktemp-6ZNOgl-4
File duplicity-inc.20131218T194807Z.to.20131231T184525Z.vol1.difftar.gpg is in Glacier storage, restoring to S3
Waiting for file duplicity-inc.20131218T194807Z.to.20131231T184525Z.vol1.difftar.gpg to restore from Glacier

Now, I was kind of expecting the latest difftar file to have to be unfrozen from Glacier, in order for Duplicity to carry on from where it left off last time. But, given backups are incremental, I'm puzzled as to why it seems to be 'unfreezing' further [earlier] difftar files. I've cancelled the command for the moment but I need to find out whether it's safe to try again. If Duplicity needs to  unfreeze a handful of difftar files, before resuming, that's fine. But with over 80GB backed up, I can't afford to let it unfreeze my entire backup archive.
Anybody got any ideas on this?
Last time, Duplicity was on my radar, I know there was talk of adding support for Glacier and the Waiting ... to restore from Glacier message suggest this has been done. However, as my backup files have been moved to Glacier by an automatic bucket rule, rather than explicitly through Duplicity itself, I'm not sure whether or not this has messed things up, as regards being able to resume that backup.
Answer: I would expect you could run an incremental update without running verify first. The man page says

Duplicity does not require access to archive files except when restoring from backup.

but based on my testing verify (at least) counts as a kind of restoring.


is it possible to spell check PDF files?

Question: Is it possible to spell check PDF files? In Preview.app the "Edit > Spelling & Grammar > Check Document Now (⌘;)" is disabled. I'm working on a LaTeX document in Emacs and would like to use the OS X spell checker. A solution for accessing the built in spellchecking dictionary from Emacs would also be acceptable.
Answer: I would install aspell with a package manager like brew and then run that on the .tex file. Unless I'm mistaken emacs has support for aspell built-in.
You can also turn on spell checking in your terminal (iterm2) or emacs GUI.
Comment: @patrix I am on OS X and installed aspell with homebrew `brew install aspell --lang=en`. I then added this to my .emacs

`(setq ispell-program-name "/usr/local/bin/aspell")
    (setenv "ASPELL_CONF" nil)
    (autoload 'flyspell-babel-setup "flyspell-babel")
    (add-hook 'latex-mode-hook 'flyspell-babel-setup)`

Spell check an entire buffer with M-x flyspell-buffer and check a word for spellings with M-x ispell-word, choose an alternative from the numbers or add to your dictionary with `i`. I'm using Carbon Emacs. Other dists my need you to install emacs' aspell manually.
Comment: That's a good list of options you are mentioning. Can you please add some details on how to install aspell and/or turn on spell checking in Terminal?
Comment: This did not completely answer my question since it uses a custom dictionary file and not the OS X dictionary. But it is possible that this is still the best solution so I'll accept it for now :)
Comment: http://stackoverflow.com/a/19026248/240004 has good instructions on how to install emacs, aspell, and homebrew in a manner I prefer.


What is the difference between 'EVERY TIME' and 'EVERY SINGLE TIME'

Question: I just heard this in conversation among my friends. Is there in difference between to say every time and every single time.
Answer: There's not really any difference in meaning, only in emphasis.
When you add the word single, you are intensifying the emotion with which something is said, whether that be frustration (as in the first example) or elation (as in the latter):

Every time we plan a picnic, it rains.
  Every single time we plan a picnic, it rains.
Every time I go on a date with Carol, I don't want the night to end.
  Every single time I go on a date with Carol, I don't want the night to end.
Comment: My gut feeling is that it's more often used as a negative than a positive, but I don't know how to test this.
Comment: @Andrew -  I concur. As I was writing my answer, I noticed it was much easier to think of usages where the saying is being used in anger or frustration.
Answer: In your usage

single

is used as an intensifier to bring attention to how often something happens.
It is the same as saying

Each and every time we plan picnic, it rains.
Whenever we want to have a picnic it rains.

Strictly speaking, it probably doesn't rain when you are planning a picnic, but when you are trying to picnic.

Each and every time we want to picnic, it rains.
Whenever we sit down to have a picnic, it rains.


Is the MODULE.schema.yml required when you define the MODULE.settings.yml?

Question: Is the MODULE.schema.yml required when you define the MODULE.settings.yml? It seems that it also works when I remove the MODULE.schema.yml file from install/schema.
Answer: It is not absolutely required but strongly recommended to have one.
By default, Drupal doesn't validate the schema, but it does in tests and there is an issue that will enable it if you use the provided example.settings.local.php/development.services.yml. That's why you don't see an error right now when you install, but you'll see it when you write your first test.
It is currently used to ensure the saved configuration has the right data type (e.g. a float and not an integer); not doing that correctly can break stuff and the ability of translating the configuration. More things might follow later, for example a module that generates a settings form.
Answer: The settings.yml is only needed when you want to have default values to start with in your config after the module is installed.
Comment: schema.yml has absolutely nothing to do with database tables, you mean hook_schema().
Comment: You are right I got them confused, I edited my answer
Answer: MODULE/config/install/MODULE.settings.yml file is not mandatory.
MODULE.settings.yml file is basically used for configure default values. and that will only affect when you install module first time.
Two options available for reflect changes in MODULE.settings.yml:

Uninstall MODULE and Install it again!
Use MODULE.install file and
hook_update_N(&$sandbox)

e.g.
Filename: MODULE/MODULE.install
    /**
     * Write a line or two here about what the updates are for.
     * This is shown to users on the update.php page.
     */
    function mymodule_update_8001(&$sandbox) {
      $config_factory = \Drupal::configFactory();
      $default_value = 'Test';
      $config_factory->getEditable('MODULE.settings')->set('config_field_key', $default_value)->save();
    }

Reference Link
Comment: Do you mean that it is necessary to uninstall the module and install again if the settings.yml updated?
Comment: Please check my updated answer, I hope it will help you.


WCF MSMQ Unit testing

Question: I have created a custom msmq service with WCF, which uses a custom binding as it needs to do some custom logic at the channel layer, where it calls another wcf service. The service is going to be a core pience of functionality for our systems for at the the next few years. i want to do what I can to make sure the service is robust, but, i'm not sure where to start. Ie testing the response, should I create a mock queue object? how do I test the service is calling another service ?
Comment: I'm also interested in how to go about unit testing msmq functions
Answer: Best way I have found to unit test msmq services is to actually unit test the service implementation, then do an integration test using msmq with a mock repository. To see if writes are working.

WCF MSMQ Unit testing


Should a metal inline junction box on an extension cord be grounded?

Question: I have a 12 gauge stranded wire extension cord, but I could not find a switch that I needed to connect in the middle. So, I used a regular wall switch and box.  My question is, should I simply connect the ground wires back together and not connect them to the box, or should I connect them to the box too?  What is the safest option?
Answer: If the box is metal, it should be connected to the ground conductor in the cord.
Imagine this scenario: the hot wire comes loose inside this box, and makes contact with the box itself (which is not connected to ground). You go to turn on the switch and touch the box while standing on the ground. Because the box is energized by the hot wire, and you're a path to ground, you get a shock (or worse).
The safety ground wire is designed to reduce this risk by ensuring any conductive surfaces are firmly bonded to ground. In the scenario above, if the box were grounded, a short would happen as soon as the hot wire contacted the box. This would flip your circuit breaker, so you'd know something was wrong. Way better than having the box sitting there energized -- an invisible danger just waiting for someone to touch it!
So: ground the box and ensure the ground conductor continues on past the switch. And make sure you're using a properly grounded outlet to feed this cord.
Comment: I might point out that OSHA does not like this type of modification to extension cords. The NEC doesn't say you can't do it ,but 400.9 Splices and 400.10 Pull at Joints and Terminals help you to understand what you need to do. I would suggest if you must add this switch, you also add a GFCI male adapter on the end of it for protection. Stay Safe.
Comment: One might also use two shorter extension cords and put an in-line 12/3 GFCI between them.  I just got some 20A units for under $10 with a locking end.
Comment: If you must do this, in addition to properly grounding of the box, you should also use the proper fittings for the cord going into and out of the box, i.e., "listed for the purpose" of flexible cords, as compared with, say, Type NM-B "Romex" cables.  Realize that your fire insurance will not be amused if your handiwork results in a hazard.
Answer: Thank you all very much for your help!  Before I heard back from you all I changed the entire assembly into a plastic box with a plastic faceplate.  But your comments  here have confirmed to me that getting rid of the metal box was the best thing.


Ethernet light doesn't go on

Question: I have just bought Pi, and I have no monitor to plug into it, so I thought I would do the DHCP trick. I installed the latest Raspbian wheezy (2013-02-09) on the SD and connected the ethernet cable into the router. But when I plug the power cable in, the light on the router does not go on, and the pi doesn't show up in the address list. What could have I done wrong?
Comment: When you power it up, does the activity LED flicker for a while, implying that it's booting up? I don't think mine connected to the network automatically, but I'm not sure.
Comment: @IanHowson it's not `activity`, it's `sd card access`, i don't know why they marked it this very confusing way
Comment: Silly point, but do you know that Ethernet cable works? You imply that the light on the router does not show that there is any activity between pi and router, this to me would either say faulty cable, or corrupt Raspbian write to SD card
Answer: the latest raspbian does DHCP just fine, on the other hand, you might have missed something when creating your SD card. i'd recommend to get any cheap HDMI cable to connect your raspberry to any tv (ask your friends?) and see if it actually boots up.
also, the raspberry has 4 LED lights next to the USB connector, red one is power and the green one next to the read means "sd card access", it's supposed to blink from time to time during the boot. if it does not -- again, check your SD card.
Comment: thanks for the answer. yes when i plug everything in, only the power led gets lit. the sd card access led remains off. i'll start with that!
Answer: When you plug in your ethernet cable and the Yellow and Green LED lights next to the cable fail to light as expected, here's something to check first:
Log in to your modem and look at the port configuration settings.  On my modem, this is found under advanced settings.
Ports can be configured to automatically sense the type of ethernet connection.  In my case, the ports I was trying to use were set to 1000 Full Duplex.  The Raspberry pi 3 can only do 100 Full Duplex, so the modem never set up an actual physical link on the port for the pi.  Further, the Link Active and Link Activity lights never came on on either end of the connection.
I changed the setting to auto and rebooted the pi.  The Link Active and Link Activity lights immediately started working and the PI had the internet.
Answer: I had the same problem, my red Pwr light would come on but nothing else. Turned out to be that my SD card was somehow corrupted. I formatted a fresh one and everything worked fine again, all my lights are back.

Ethernet light doesn't go on


Equation of the line that cuts equal $x$ and $y$ intercepts and passes through $(2,3)$.

Question: If I use the intercept form or simply find the slope by dividing the $y$-intercept by the $x$-intercept then the slope will be equal to $1$. But logically there must be two lines satisfying the given condition as seen in the graph below, the other having slope equal to $-1$. How do I mathematically show the existence of the other line and why the method I used only a gave one answer.
Answer: The purple line is not a solution: the $y$ and $x$ intercepts have opposite signs.
Answer: Generally intercept  means the length  between intersection of axis and line and the origin, with sign. So there is only one line which satisfies this.


How to identify data frame which scale bar corresponds to in ArcMap?

Question: I need help to identify the data frame (from several data frames) that corresponds to a scale bar in ArcMap?
Comment: Zoom in/out on a data frame and see which one changes. How many data frames do you have? (note: there is a View Previous button that will restore your extent to what it was before you zoomed, no damage done)... if your scale bar doesn't change it's because it's been turned into a graphic and doesn't belong to any data frame - that's *really* bad practice and should be removed.
Comment: And note once you do figure it out, or better yet at time of creation, you can name graphic elements in their properties. That way you could call it `dataframe1scalebar` or something. Of course, more descriptive names for all elements, including dataframe names (especially with that many) are recommended.
Answer: The suggestion by @MichaelMiles-Stimson is a good one.
Alternatively, you could type some code into the Python window of ArcMap:
mapDoc = arcpy.mapping.MapDocument("CURRENT")
scaleBar = arcpy.mapping.ListLayoutElements(mapDoc,"MAPSURROUND_ELEMENT")[0]
print scaleBar.parentDataFrameName

If your scale bar is the only Map Surround Element in your map then the above will work.
If you have multiple Map Surround Elements then go to the Size & Position tab of the Properties for the Scale Bar and give it a name - in the graphic below I have let it stay as the default of "Scale Line".

Now you will be able to isolate that one Map Surround Element (or at least the first Map Surround Element named "Scale Line") by using:
scaleBar = arcpy.mapping.ListLayoutElements(mapDoc,"MAPSURROUND_ELEMENT","Scale Line")[0]

Answer: In the table of contents window, when you activate a certain data frame, anything that you do thereafter will correspond to that specific data frame contents. If you add anything it will belong to the activated frame. This might help you in knowing to which data frame will your scale bar belong to when you add. If you have few data frames you could remove the scale bars then add them again with this in mind.


Why does MySQL give me "ERROR 114 - Table Full"?

Question: I have a MySQL database table with 31,107,600 rows in it.
It's using InnoDB.
This is on a CentOS 7 system.
The table has these columns:

id
timestamp
mac
data
direction
site_id

I want to create an index, so I run this command:
ALTER TABLE MY_TABLE ADD INDEX idx_my_index (mac, site_id, timestamp);

It takes about 30 seconds, and then gives me this:
ERROR 1114 (HY000): The table 'MY_TABLE' is full

My MySQL is using the default /var/lib/mysql to store its data. Currently, the partition that folder is on has 12GB free, and my database is only 2.7 GB in size, so as far as I can tell, it should have more than enough space.
Why am I seeing this error? Online searches show that perhaps it is using a temporary table, and hitting restrictions on the size of the temporary table? Could it be that? Or something else? How can I confirm this?
Answer: While the ALTER TABLE statement is running, observe your space usage on all file systems using df. See if space on another file system, particularly a small one, is rapidly decreasing, e.g. if you have /tmp on tmpfs.


A question about fields of real numbers

Question: Assume that the continuum hypothesis holds. If $F$ is an uncountable field of real numbers, does $F$ always contain a proper uncountable subfield? Are there many specific uncountable fields of real
numbers whose existence can be proved without assuming the axiom of choice?
Comment: If $a$ is transcendental and $b$ is algebraic and nonzero over
$\mathbb{Q}$ then $ab$ is transcendental. If $K$ is obtained
by adjoining all real transcendentals to $\mathbb{Q}$
then $K$ contains $a$ and $ab$ and so also $b$. Thus $K=\mathbb{R}$.
Comment: Perhaps you would get a more interesting question by asking whether there is an uncountable subfield $F$ of $\mathbb{R}$ for which the existence of a proper uncountable subfield cannot be proved without using some form of the the Axiom of Choice.
Comment: Correct me if I am wrong. I believe we can define a field $K$ by adjoining to $\mathbb{Q}$ all elements in $\mathbb{R}$ transcendental over $\mathbb{Q}$, without axiom of choice. The extension $\mathbb{R}/K$ must then be algebraic and hence $K$ or any extension of $K$ must be uncountable. I think this answer the second part of the question. It is not obvious to me how to define a uncountable subfield of $K$ without $AC$. Suppose, I want to prove that it is impossible to prove the existence of a uncountable proper subfield of $K$ is there any obvious path to proceed?
Answer: Take a compact Cantor set $K \subseteq \mathbb{R}$ of Hausdorff dimension zero.  Actually we need all cartesian powers $K^n$ of dimension zero as well.  The field $\mathbb{Q}(K)$ generated by it is uncountable, but still of Hausdorff dimension zero, so it is a proper subfield.
edit
That field consists of the values of rational functions $w(x_1,\dots,x_n)$ of many variables with rational coefficients, where the variables range over $K$.  There are countably many such things, so you just have to show any one of them has dimension zero.  The domain of any such $w$ (that is, the set where the denominator does not vanish) consists of an increasing countable union $\bigcup_k A_k$ of sets where the gradient is bounded, so that $w$ is Lipschitz continuous on each $A_k$.  So the image of $w$ on $K^n$ is again a countable union of sets of dimension zero.
plug
G. A. Edgar & Chris Miller, Borel subrings of the reals.  Proc. Amer. Math. Soc. 131 (2003) 1121-1129
LINK
Borel sets that are subrings of $\mathbb R$ either have Hausdorff dimension zero as described, or else are all of $\mathbb R$.
Comment: @Garabed: This is not correct.  The hypothesis is zero Hausdorff dimension (of all Cartesian powers), not merely zero Lebesgue measure.  For example, the standard middle-thirds Cantor set has Lebesgue measure zero,  but the additive group it generates is the whole line.
Comment: Interesting!  This answer mixes field theory and metric geometry in a way I have not seen.  Could you give some more details and/or references as to why $\mathbb{Q}(K)$ has Hausdorff dimension zero?
Comment: Note that the field $\mathbb{Q}(K)$ is actually Borel.
Comment: Thanks alot for your answer. Your argument seems to show that if
K is any set of real numbers having zero Lebesgue measure, then the
field Q(K) also has zero Lebesgue measure. This gives us a method
of obtaining a very large number of uncountable real fields all
different from R, without using the Axiom of Choice.
Answer: I think the following argument ought to answer your first question, but I haven't checked the details. An uncountable subfield F of R will contain an uncountable polynomially independent subset (by Zorn's lemma). And any proper subset of that polynomially independent subset will generate a proper subfield of F.
Comment: Yes, this definitely works.  It shows that any uncountable field has uncountably many uncountable subfields.  It does not use CH, but it does use AC (for the existence of transcendence bases).
Comment: What is the definition of a "polynomially independent subset"?

A question about fields of real numbers


Creating a node type module in Drupal 7.x

Question: I am having some deep trouble getting around creating a node type with Drupal 7.x.
My aim is to create a node type that has some form elements within a table grid. Using any of the existing modules is coming across as a challenge because I can't find anything specific to my needs, hence I decided to explore module building and then enabling it as a node.
The tutorial I have is :
http://drupal.org/node/231019 (Create new content type for Drupal 6.x) .. .there isn't any exact tutorial available for Drupal 7.x
I have followed every step but am unable to see the content type appear in my node module.
Anybody has pointers to any resources for this?
Thanks
Comment: Just something to check: Did you enable your module?
Answer: Download and look at those wonderful examples


How to get NetBeans 7.4, Ruby and MySQL to play together (on Windows)

Question: The tags say it all, really. This is a project that used to work on earlier versions, but not now. If you know the answer, just stop reading and tell me how.
An existing project is working fine on older releases of NetBeans and MySQL. I am just trying to get it working on the latest release of everything. Nothing fancy. Just plain vanilla Ruby on Rails on Windows/MySQL.

Clean install of Netbeans 7.4. No problems.
Clean full install of MySQL 5.5. No problems. Includes Java connector.
Clean install of ruby and rails from community: http://plugins.netbeans.org/plugin/38549. No problems.
Everything is working just fine.
Webrick starts and runs. Absolutely no surprises to this point.

I tried to gem install MySQL: it fails, but it is not unexpected. I have no interest in pursuing that line. Ditto for MySQL 2. It's always hard building native libraries on Windows.
I tried to gem install all/any of the following:
 * activerecord-jdbc-adapter
 * activerecord-jdbcmysql-adapter
 * jdbc-mysql
They install just fine, but the end point is always the same:

cannot load com.mysql.jdbc.Driver.

I think I know what this means, but I have no idea how to fix it. Is it a classpath problem? Is it a bug? Is it an incompatibility just about to be fixed? Is it because I'm using Windows? Who knows? I can't think of anything else to try, and the forums are full of these errors with no solutions that seem to fit my problem.
Comment: @peter: thanks for the edit. You wouldn't have an answer too, would you?
Answer: I am not sure, but maybe the blog post Installing MySQL on Windows 7 x64 and using Ruby with it will help.
Comment: Thanks. I hadn't found that one. Unfortunately it's 2 years ago, and it's based on straight ruby, not Netbeans. That makes the gems a bit different. There are probably enough clues to find the answer to my problem, but this isn't quite it.


How were the Orishas born?

Question: Orishas are the deities that form the Yoruban pantheon. Their ruler is Olorun. However, while I was reading up on them, I was unable to find out about how the Orishas were created. How were these gods born?
Answer: It looks like it depends. I listed a few examples below.
At least a number of them are primordial deities. Orunmila, for example, was present at the beginning of creation.
The primordial Orishas "emanated directly from God without any human aid," according to Britannica.
Wikipedia says that Obatala was "brought to life by the smooth breath of Olodumare". Orunto is also a son of Olodumare.
Ogun is also primordial.
Erinle was a great hunter who became an orisha.

How were the Orishas born?


Is there a limited supply of Titanite?

Question: Is there a limited supply of Titanite in Dark Souls 2? I know that in the first game, you could find merchants that never ran out of Titanite Shards but the only merchants I've found so far have a limited supply.
Comment: I am pretty sure there is not. A lot of the 'unlimited' supplies get unlocked later in the game. (For example there is a merchant that sells unlimited Large Shards and another that sells boltstones. I just don't know where the regular titanite one is.
Answer: There is an unlimited supply of all forms of Titanite.
All Titanite up to Chunks are sold in unlimited supply by the NPC Stone Trader Chloanne.
Chloanne is found in Harvest Valley, until you talk to her so much she runs out of new things to say, in which case she'll go to Majula. You can pretend it's your fault.
Get unlimited Titanite Shard by clearing Iron Keep, unlimited Large Titanite Shard by clearing Drangleic Castle, and unlimited Titanite Chunks by clearing the Undead Crypt. When you get through the final boss, Titanite becomes infinite.
The only one that is left is Titanite Slab, which can be farmed off of the stone soldier in Drangelic Castle.
Although not part of the regular titanite upgrade path, Twinkling Titanite can be farmed off of the Archdrakes in Shrine of Amana. Alternatively they can be Acetic farmed in Dragon Aerie(5x?) and the Giant Memories(2x).
Comment: What about `Twinkling Titanite`
Comment: I had assumed the question was about the regular Titanite upgrade path, and answered as such. I have updated my answer to include twinkling titanite.

Is there a limited supply of Titanite?


How to find the optimal lines?

Question: Does anyone know anyway or any algorithm that can exactly and/or
numerically find lines $\left\{ l_{i}\right\} _{i=1}^{n_{k}+2}$ that maximizes $$\min_{1\le i<j\le n_{k}+2}\text{angle}\left(l_{i},l_{j}\right)$$ in $\mathbb{R}^{n_{k}}$ for some sequence of integers $1<n_{1}<n_{2}\cdots<n_{k}<\cdots?$ Thanks a lot.
Comment: I'm pretty sure this can be turned into some version of a sphere packing problem.
Comment: Equivalently, one can talk about points (in place of lines) of real projective n-spaces. (Of course, projective n-space corresponds to $\ \Bbb R^{n+1}$). The metric of the projective n-space comes from the euclidean unit $\ S^n.$
Comment: @user44191  Just wondering, suppose that the question were regarding sphere packing instead, would you be able to find the coordinates of the optimal points for infinitely many dimensions? Thanks.
Answer: Bukh and Cox provide exact constructions for the infinite sequence $n_k\equiv 1\bmod 3$. Sloane maintains numerical solutions for $n_k\leq 16$. Computer-assisted proofs of optimality have been obtained for $n_k\leq 6$; see this paper and references therein.
Edit: The Bukh–Cox construction is contained in the proofs of their Lemma 16 and Theorem 3. In what follows, I isolate the construction for convenience. (Throughout, I use their notation whenever possible, so your $n_k$ is replaced by $d$, for example.) Put $k=2$ and $N=\binom{k+1}{2}=3$, and let $A$ denote any $k\times N$ equiangular tight frame. See this survey for general information on these objects, but in this case, we may take
$$ A = \left[\begin{array}{rrr}1&-\frac{1}{2}&-\frac{1}{2}\\0&\frac{\sqrt{3}}{2}&-\frac{\sqrt{3}}{2}\end{array}\right].$$
If we denote the columns of $A$ by $x_1,x_2,x_3$, then notice that each $x_i$ has unit norm and $|\langle x_i,x_j\rangle|=\frac{1}{2}=:\beta$ for every $1\leq i<j\leq 3$. Take
$$ C:=\frac{1}{\beta}(A^\top A-I)+I. $$
Then the diagonal entries of $C$ are $1$ and the off-diagonal entries of $C$ are $\pm1$. One may further show that $\lambda:=\lambda_\mathrm{max}(C)=\frac{1}{\beta}(\frac{N}{k}-1)+1$. Since $d\equiv -k\bmod N$ by assumption, we have $b:=\frac{d+k}{N}\in\mathbb{N}$. Put $\epsilon=\frac{1}{b\lambda-1}$ and consider the matrix $G:=(1+\epsilon)I-\epsilon(C\otimes J)$, where $I$ is the identity matrix of size $Nb=d+k$ and $J$ is the all-ones matrix of size $b$. One may show that $G$ is positive semidefinite with rank at most $d$, and so $G=XX^\top$ for some $X\in\mathbb{R}^{d\times (d+k)}$. The columns of $X$ are unit vectors that achieve equality in the Bukh–Cox bound (i.e., Theorem 2(a)). It follows that the lines they span maximize the minimum interior angle.
Comment: Thank you for your answer. I'll look into the papers that you refer to. Thanks.
Comment: Just wondering, if Bukh and Cox have provided exact, probably implementable,  constructions for the infinite sequence, then why does Sloane maintain numerical solutions only for finitely many dimensions, with respect to the question? Thanks a lot.
Comment: Sloane posted the numerical solutions in the 90s, and I'm not sure how regularly he updates his table (if at all). Meanwhile, the Bukh--Cox result is quite recent.
Comment: Okay, thank you for the information. But it seems in Bukh and Cox's paper that d and k need to satisfy a special modulo equation and that the bound(s) they established rely on another maximin function. So where can one find the optimal lines for the question? Thanks a lot.
Comment: @Tanger - Their construction is spread across a couple of proofs in their paper, so I updated my answer with a description.

How to find the optimal lines?


iOS mail inbox does not show addresses

Question: I use a catch all email address on my domain, and would like to be able to figure out what address is being sent spam email.  Unfortunately, I can't find a way to see what address an email in my inbox was sent to. Is there a way to determine the addressee of an email in iOS 8?
Comment: Inbound email shows the "To:" field on my phone, perhaps you only have one email account configured?
Comment: ah, I see now in other emails there is a to field, must be something in particular about this spam that prevents mail from being able to read it from the headers.
Comment: That likely means there is no "To:" header, instead your domain was likely used in a "BCC:".  Additionally BCC's never appear in the headers after the email is received, the mail server may however generate an "X-Apparently To:" header that will be visible if you can see all headers.
Answer: You would likely have to have an email app capable of displaying the raw headers of the email to trace this information. I do not believe the iOS 8 Mail app has this capability; it simply displays the most user-friendly information (your catch-all To: address). However, if you can access the same account through the Mac OS X Mail application (or Outlook, etc.), you can view the raw headers there.

iOS mail inbox does not show addresses


Fractional integration and cointegration with R

Question: I am currently reading about fractional integration in the context of error correction models. Does anyone know of a package in R that has a function for Sowells maximum likelihood estimator of d?
Answer: Well now we have partialCI: An R package for the analysis of partially cointegrated time series by Matthew Clegg, Christopher Krauss and Jonas Rende
Answer: The CRAN Task Views page for Time Series Analysis lists the fracdiff package: Fractionally differenced ARIMA aka ARFIMA(p,d,q) models.
The package is described as follows:
Maximum likelihood estimation of the parameters of a fractionally differenced ARIMA(p,d,q) model (Haslett and Raftery, Appl.Statistics, 1989).
The documentation says that the package can perform the following methods:

Geweke and Porter-Hudak (GPH) (1983)
Reisen (1994) estimator
Haslett and Raftery (1989)

Regarding Sowell's method from 1992, a number of academic articles (example) report that they obtained the FORTRAN code from Fallaw Sowell. Probably, you could request the code and port it to R (if he or the licence approved of that)?!
I couldn't find an existing package with the implementation.


IPad mini MD531LL/A and MD528LL/A

Question: What is the difference between Apple iPad mini MD531LL/A and MD528LL/A I want to purchase a new iPad and I don't know what this means is there a difference between the two?
Comment: Which Apple Store are you shopping for these part numbers?
Answer: The part numbers you refer to are not actual model numbers, but indicate which country the part would be sold through and hence the pricing and warranty country of origin.
MD531LL/A appears to be the original iPad mini (Late 2012) Model: A1432 WiFi only, white, 16 GB with resolution of 1024 x 768 pixels and an 2.4 GHz Apple A5 CPU. The MD528LL/A is the same but in black.

IPad mini MD531LL/A and MD528LL/A


Android 5 date and time pickers are not accessible

Question: Basically I've just got a new Android 5 phone and I've encountered a severe problem. I use the TalkBack screenreader service, and I cannot find any way to select a time in the new time picker in Android 5. Furthermore, the date picker is a pain to use (although at least it is usable).
Answer: Never mind I figured it out you have to navigate to the circular thing and then make the scroll gesture which is right-then-left to increment the number and left-then-right to decrement it.


Are Gaussian Mixture Models stochastic or deterministic?

Question: Each time we generate a gmm model, we obtain slightly different clusters. Can we hence say gmm is stochastic? We obtain the same clusters if a random seed is set; does this mean given a random seed, gmm model is deterministic?
Answer: This is not directly related to Gaussian mixture models, but rather to how computers generate (pseudo) random data. Loosely speaking, there are two algorithms, one that generates a random seed, and a second that generates (pseudo) random data based on this seed. If you manually set the seed, the second algorithm always generates the same data. This what you actually see in your example.


NSDistantObject Protocol for iphone

Question: I've been reading through the docs on how the NSDistantObject class and I can see that it is more or less a binary protocol for sending objects from one NSPort to another. What I'm curious about is the possibility of using this in an iPhone application to share data. Is it possible to have two applications talking to each other on distinct phones using this protocol if the connection is established by a server, or even if its not? (I'm sort of thinking of torrents) Also, how does this interchange format compare to typical data serialization methods such as JSON?
Answer: Not currently possible as NSDistantObject is only available for the OS X Foundation framework.
Source.

NSDistantObject Protocol for iphone


Servo Speed Control

Question: I work in a robot using arduino, and i have a few questions:
It is possible to increase the speed of a servo, for example a parallax?
It is possible to measure the current that pass through a servo?
Comment: Assuming the on-board controller is already driving the motor with full effort, the only way to increase speed is to lessen the load at the servo output, increase the voltage, or change the servo.  You can of course measure the current, perhaps by measuring the voltage drop across a very small sense resistor.  Generally speaking, continuous rotation servos (presumably what you mean when you reference parallax) are rather crude (and arguably open loop, not "servos" at all once so modified) so before investing much effort you may want to start with something better.
Comment: If you are powering the servo from the arduino 5v rail you could try to power it from something else, if you use a battery pack or powersupply, then put the Vin of the servo directly to that instead of using the arduino 5v rail. It is not healthy to run high current stuff from the arduino rails anyways.
Answer: Part 1: Can I increase the speed of the servo motor?
Solution #1 :
You can run your servo motor at its maximum rated voltage, which will give you the fastest response. If angle is all you want, that should be ok.
Solution #2 :
If speed control is just as important, you're better off using a DC motor with an encoder. You will have to write a PI control loop, but in return you will be granted a fine-tune control and potentially superior performance.
Solution #3 :
If you need to hold a physical load accurately at a certain angle, then I would go for a stepper motor. But you need to make sure that you do not overload it, as it will cause a misstep.
Part 2: Can I measure the current?
The simplest and cheapest method, is to connect a current sensing resistor to your servo and measure the potential difference using the analog input. Since the resistance is known, you can calculate the current using the formula I = V/R.
Two things to make sure:
1) Your resistor power rating is not exceeded.
2) The voltage difference has to be large enough to be measurable. (e.g. 2 ohm resistor gives .05V @ 100mA, .5V @ 1A and your Arduino analog input may have the resolution of roughly 0.005V)
What? Did I hear you say that the accuracy isn't good enough? Well actually you can buy an op amp to amplify to the scale that you need. Or to make life easier: buy one from Adafruit. :p
Hope this helps.
Answer: The speed of most servos cannot be changed in your code (unless your code is limiting the speed by changing the position in small increments with long delays between your writes). Most servos, in my experience, try to get to the set position as fast as the physical motors can possibly move while keeping the motion somewhat motors. However, motors can only go so fast, so you are limited.
One thing to note: some servo motors can be powered at higher voltages, but still controlled at 5V. With the increase in voltage, it might allow the motor to go a little faster, although the results will vary based on the servo's electrical characteristics and the motor driver's algorithm.
As for the current, you can buy cheap current sensors online that can be interfaced with the Arduino. You will want to measure the current (in series) flowing either from your power source to the VCC of the stepper, or from the GND of the stepper back to the GND of your Arduino.
Comment: Thank you very much, your answer was so complete and helped me so much, now things are so much clear. Sorry for my English, I am not a native speaker.

Servo Speed Control


How does one know if my buddy pokemon becomes feedable for the next heart?

Question: There's some sort of circle gauge on the buddy pokemon that falls as time runs after the feed but I'm not sure when it becomes feedable. I'm guessing there's some indication but it's not clear enough.
Answer: Depends on what you mean by "feedable". There are two main things:

Feeding the buddy to fill the gauge and get hearts:

The indicator you mentioned is divided into 6 sectors and is fully
filled when you feed
your Pokemon 3 regular berries (Pinab, Nanab, or Razzberry) or 1
Golden Razzberry. At this point you buddy will receive one heart and
joins you on the adventure, so you can earn hearts for walking,
battling, interacting with new pokestops. This state will last for 3
hours, so each sector will represent 30 minutes. However, you will
be able to refill the gauge only after 2 sectors were completely
depleted so the earliest would 1 hour after initial feeding. The
indicator will change appearance to reflect sectors in the buddy
play mode at this time. If you do it right on the hour, you might
need only 1 berry to refill the gauge, but the timing is tricky, so
you might need 2-3 regular berries or 1 Golden Razzberry. Once you refill the indicator, your buddy will gain another heart (up to 3 on regular state) and it will take another hour to repeat the process.
Using Poffin fills up the gauge and all the 6 hearts (3 doubled) and will last for 6 hours. Each sector on the gauge represents an hour, but feeding your buddy will not have any affect until those 6 hours elapsed.

Feeding your buddy to get him superexcited without the Poffin. This can be done every 30 minutes, but will not count before 30 minutes has passed since the previous activity, so the easiest way to manage it would be setting a timer for 30 minutes right after feeding a berry. After several iterations the hearts for the main activities are doubled and you can get more hearts by filling the gauge fully again. There are separate tutorials on activities and timing to get this done.


Why do we need so many transistors in a chip, and how are they managed?

Question: My knowledge is very vague as all we have are visual diagrams etc, but we have memory address and registers, the ALU being the heart(apparently). Single core CPUs process one instruction at a time AFAIK and multi-core have parallelism to some degree. So where do the millions of transistors come in and how do 32 registers manage everything. We have FPU's I know, how many transistors would these use roughly. Any way to get a fairly simple idea of what the bulk of the transistors do, why more means faster and how the registers 'manage' everything.
Comment: I think this is below the resolution of CS; maybe this question would be better off on [electronics.SE]? ([This question](http://cs.stackexchange.com/questions/3390/how-does-a-computer-work) may be helpful.)
Comment: [Why does more transistors = more processing power?](http://electronics.stackexchange.com/questions/5592/why-does-more-transistors-more-processing-power) on the [Electrical Engineering](http://electronics.stackexchange.com/) SE might be of interest. (I am somewhat proud of [my answer](http://electronics.stackexchange.com/a/45099) there, but it *might* be a little too technical.)
Comment: Why do you say that the registers manage the CPU? That seems like saying that a piece of paper on my desk manages me; isn't it the other way around?
Comment: fairly similar to this question [how does a computer work](http://cs.stackexchange.com/questions/3390/how-does-a-computer-work). the question seems to be about how the different transistors are allocated across different fns of the cpu. actually ALU mentioned takes a significant part... as for last question "how the registers 'manage' everything" is not very meaningful, registers do not "manage" anything, its more eg that a compiler "manages" the use of registers through optimization etc.... one can write working code that uses almost no registers.
Answer: This is a huge question. To fully answer it would take far more space than you'd want to read (not to mention that I suspect that there's a limit on the length of any SE answer), but I'll try to give you an idea of what goes on in the CPU.
First, a transistor (when used in a CPU) is essentially a switch, like a light switch except that you don't have to turn it on or off manually. Rather, it is controlled by an electrical current. The most important thing to understand is that modern computers are two-state devices: the only thing that really matters is whether a wire has a current or not.
One then begins the process of chip design by, for example, deciding how an integer (or other data) will be represented. For integers, say, the chip designers generally decide to them by ganging wires together in a logical unit, so with a collection of four wires it would be possible to represent 16 possible patterns: $\mathtt{0000}, \mathtt{0001}, \dots \mathtt{1111}$, where a pattern like $\mathtt{1101}$ would represent a voltage in wires 1, 2, and 4, and no voltage in wire 3 and this collection might be interpreted as the number 13. In this example, we'd have what's known a a 4-bit chip. A modern computer would have either 32 or 64 wires treated as a unit.
It happens that with a suitably-connected collection of switches (aka transistors), one can do things like add two numbers, compare two numbers for equality, decide whether a number is zero or not, and so on. Often, all of these operations are often done at once, simultaneously, and the relevant one is chosen by the current instruction, which determines which of the various results to use, and where that result will be sent. All of this traffic control is also controlled by switches, depending on what the current instruction is (in the program being executed). In addition, things like memory and registers which store information can also be implemented by these switches.
To get a feel for the number of transistors used, an adder circuit in a $n$-bit computer might require about, say, $20n$ transistors, an $n$-bit register might require $50n$ transistors, and the traffic control circuitry to sent the results to the right place might require several hundred more for each bit. It's not hard to imagine that with a lot of functionality and a wide data path (the number of wires ganged together) a modern CPU could easily take millions of transistors.
As to why "more [transistors] means faster", the answer is "not necessarily", but in general, doubling the width of the data path, say from 32 bits to 64, gives you the ability to manipulate larger numbers in a single instruction at the cost of requiring more transistors.
Finally, the registers don't really "manage everything". A register is simply a very fast storage unit, capable of storing and retrieving information far faster than, say RAM memory. For that reason, things like the current instruction are often stored in a special register (called the instruction register), simply because access to its bits is very fast. The current instruction actually "manages everything", and it's stored in a register for speed.
This is a very abbreviated explanation---I've left out a ton of detail and glossed over a lot of technical matters, but I hope it at least gives you a sense of what goes on in a modern computer. [entering duck-and-cover mode in expectation of howls of complaints from computer engineers]
Comment: The 'more means faster' came from the many years when Moore's Law (transistor scaling) and frequency scaling were happening at almost the same rate. In many people's minds they're still conflated a bit. One other thing to mention- there's an impression here that everything is linear; however, there's a number of places where the number of transistors will be polynomial or higher in the number of stages, or elements, or wires.
Comment: This is a great short answer. If you want the long and detailed answer from an extremely gifted author and famous early Windows programming guru, I recommend the book, Code, by Charles Petzold. I've given away 7 or 8 copies of this book, and I recommend it to anyone who wants to know how modern computers work.

He begins with simple logic building blocks that can be build from electrical relays and follows progression all the way to a simple CPU with memory access. With each developing chapter you see where all the transistors go.

His book web page: http://www.charlespetzold.com/code/
Comment: Still cannot account for the *billions* of transistors required. I don't think the number of registers or the data path has changed over the many generations of the i7 CPU. Unless, say, duplicating a core requires something like 500 million transistors.
Answer: Typically one bit of cache memory requires 6 transistors (some designs use more or less, with different tradeoffs; see http://en.wikipedia.org/wiki/Static_random-access_memory), so modern CPUs with large caches spend a lot of transistors there.
Modern CPUs also execute multiple instructions concurrently, so there are multiple execution units (ALUs) on the chip, each of which is fairly complex.
Certain mathematical algorithms in the FPU can be accelerated by table lookup plus interpolation; the reciprocal square root instruction in Intel SSE units, for example, is implemented with a table that gives 12-bit precision almost instantly; this table is essentially a chunk of ROM on the chip -- that is, still more transistors.
Answer: there are several questions here & will just focus on one of them. the transistors on a chip is "roughly" proportional to the surface area used for the transistors. so you can find diagrams of a chip that show the graphical boundaries of different subsystems and simply use the formula that # of transistors in a region is equal to the proportion of area of that region to total area times total number of transistors on the chip.
example in this paper:

A 65 nm 2-Billion Transistor Quad-Core Itanium Processor Stackhouse et al

fig 1 shows the graphical boundaries on the chip. see fig 4 that gives area and # of devices in the millions for the separate functions of the CPU. the exception is that it appears that cache circuits are very dense and have much more transistors per area, it seems to have 3x the transistors at 2/3 the area. apparently on this chip it looks like about ¾ the transistors are dedicated to fast cache.
Answer: The simple answer is transistors are the basic components of logic gates, registers and storage devices. their various configurations make possible the or and not and flip-flops that comprise the higher order registers and processors. Look up the 7404 (not gate)7408 (and) and the 7432 (or gates). the basic 7474 and the 74279 are storage configurations. I am not  sure if national semiconductor still publishes the actual schematic but texas instruments does.
Comment: You are digging up lots of old questions, posting answers that don't seem to be adding much (or in a very convincing form). Before answering, please consider carefully if you can truly add something that prior answers fail to provide, and take care to present it in a digestible form, adhering to scientific standards (references, proofs, ...)
Comment: For one thing, I don't see any reference that can be recognized as such in your post. Then, you only seem to say "they are the basic building blocks of logic gates, which CPUs are build of". Other answers already say the same in a much more elaborate and explanatory way.
Comment: I did not see any actual circuitry answers to the questions. I think clarity and simplicity add to the discussion. not really interested in your opinion of my contributions or rating of my answers. in fact I find your response rather snobbish and condescending. maybe you should adhere to the same expectations and stop trying to control others right to free speech.
Comment: 1) As a moderator, I'm warning you to adhere to our standards in order to help you avoid disappointment. 2) I don't care about your opinion of my statements. 3) Free speech does not apply here. This is a website owned by a company, with a community given mandate to moderate.
Comment: using this case in point I did present references, in fact I cited the BIBLE of TTL logic written by TI. I thought that the individual posting this question was unclear about logic electronics and need some on to point them to the basics. what about this does not add to the discussion?
Comment: what ever, considering that some on this 'site ' actually think that making a reverse logic system will actually cool a chip I 'm not surprised at your response. I find very little here to be any thing 'computer' or 'science' it is more delusional dribble of those who feel catfish should have kittens. and folly to be as humorous entertainment for long time professional making >$300K/yr  .