Is there any structure to write a book?

Question: I want to write a book but I don't know where to start. I'd like to know if is it there any structure for a book to be written, or if somebody could tell me how to start.
Comment: If you want useful help, you must tell the police where you are and what happened, not just call and say "help me" and then hang up.
Comment: This feels very broad to me.
Comment: Could you elaborate on what kind of book(s) do you have in mind? Technical books? Reference material? Text books? Fiction? etc.
Comment: @MonicaCellio - I agree that this is broad - perhaps too broad to be a useful question. But I'd like to let the community decide about keeping it open or not.
Answer: There are LOTS of ways to structure a book.  Depending on what you're writing, there may or may not be any expected frameworks.

Long-Form Fiction, such as speculative fiction novels, movie scripts, and semi-fanciful "alternate histories" usually progress lineally along one or more character's perspectives along a three-act progression, though more acts are non uncommon and strict adherence is not necessary.  Some genre fiction have more expected structures.
Non-fiction Reference Material, such as a wikipedia page or the manual for a piece of software, tends to begin with an overall review of the topic, follow with specific details or instructions arranged in some discernible order (complexity, alphabetically, or historical progression), and end with any needed reference materials.
Non-fiction polemics and short-form fiction both are highly variable in their form and structure.  Aside from the mechanical need to quickly attract a reader's interest, their choice of structure is entirely part of an author's craft and can be as important as word choice or phrasing.

As for how to actually write any of the above: start with an idea, add in various notes, and then sit down and write a first draft from beginning to end.  Skip ahead if appropriate.  Once your draft is done, read it once and then begin your editing process.  Be aware you may need to throw it all away and start again with a new first draft, on possibly an entirely separate project.
Comment: Excellent and concise answer. I particularly liked the mention of non-fiction books. I didn't really pay much attention to that until I read your answer.
Answer: Here's a terse summary of Peter Seibel's How to Write a Book blog entry:
Step 1 Write the index.
Step 2 Write a hierarchical outline.
Step 3 Write a flattened outline.
And Step 4 Write the book.
Seibel has written two technical books and you may take his approach as especially practical for a technical book.
Answer: It depends on the kind of book you're writing.
Fast-paced, action-packed books tend to leap straight into the thick of things and introduce their characters at the same time (Matthew Reilly kind of books. I know, he's not exactly an avant garde writer, but he is one end of the spectrum when it comes to explosions and many, many exclamation marks).
Modern romance novels that are highly successful tend to have the romantic interest pop up in the first chapter in a cute meet (forgive me if I have offended any sensibilities) with the protagonist or narrator.
If you're actually talking about what to put on the first page of the book, you could start with describing a particularly vivid mental image that sets the backdrop for the first scene in your story. Your imagination should take over from there.
The overall structure of books that I've read tends to go like this: Introduction (start slow, introduce characters, set tone for the story), buildup(things happen, information gradually becomes available), climax(the highest point of tension in the book or the main event all the other events have been building up to), and resolution (or the ending).
Don't let that formula confine you too much. Some of them have an ambiguous resolution (I know they call it a resolution, but the end of Twilight leaves you wondering if Edward turned Bella - more of a teaser, really), and some of them have the climax and resolution on the same page (the Notebook: The protagonist's love interest finally remembers him, which is the miraculous event you've been unconsciously waiting for all this while, and then the novel ends- Climax and resolution on the same page).
A shortcut would be to look up a few bestsellers that you think are similar enough to the book you want to write in terms of genre, mood, pacing and length, and then narrow it down to one or two of your favorite ones (or all of them, if you are like me). Use them (or it) as a guide, but don't overdo it, or all you'll get is another piece of fanfic. It would really help if you had strong original characters with quirks and idiosyncrasies that your references do not have.
Enjoy your journey!

Is there any structure to write a book?


Rails 3.1 + jQuery Mobile + Testing in Desktop Safari = refresh will break style

Question: I am following this: http://railscasts.com/episodes/199-mobile-devices to implement mobile version of my site. I am using the jQuery Mobile instead of jQtouch.
For development testing, I am using desktop version of safari and changing the user agent to iPhone. However, whenever I hit refresh on some pages, jQuery Mobile will not be loaded and there are no styling applied. I need to go back to the previous page and click the link again to see the mobile version.
I suspect that it has to do with caching, but I could not figure out what is causing it.
Answer: If you are using Page Speed, try disabling it.


Will golf and puzzle questions migrate here from SO?

Question: As far as I remember, one of (unstrict, as we can see) Area51 rules was that we will not create sites, witch may took part of SO's audience. For example, by this rule Ruby.stackexchange was declined.
But today this site was launched and CodeReview was also spotted. So, will moderators migrate codegolf, puzzle etc. tag questions here or they may stay a part of history?
Comment: I think this site should be able to grow from ground up, but, on the other hand, some questions on SO are indeed interesting enough to migrate here. So, I'd advocate being selective.
Comment: Just noting, nearly all such questions will be CW on SO and there's no way to revert CW. This might make imported questions a bit odd here.
Comment: @marcog: In theory mods now have the power to revert CW. However, we have had some trouble with that on this site.
Comment: I'm not sure, but perhaps there's a standard SE policy on this? I know some questions were migrated to programmers.se when it launched, but mod @ChrisF is weary of migrating too many there.
Comment: Questions won't really get migrated en-masse until the site proves itself as a full-fledged beta graduate. Then they will get migrated.
Answer: I'm not sure how this site would rob much from SO.  Most problems here are asinine in a real-world setting, and if anyone actually golfs for anything other than kicks, they should be shot.
Sure, the occasional question is fairly interesting and dare-I-say useful (move those to SO?).  Nevertheless, I think your view of this site is somewhat rosy.
Comment: You may have misunderstood the question. Code-golf had a special remit on Stack Overflow (most "challenge" type questions were closed), and there are about 200 existing code-golf questions there. New code golf obviously belongs here, but Nakilon is asking about the fate of the old ones. Especially as several have been duplicated on this site.


Can I reduce the size of my baseboard diffusers?

Question: We are going through a home remodel. I want to replace our baseboard diffusers because I feel they are too big for the vent. The size of them are 25inches. The dimensions of the vent are 12 Length x 2.5 width. I'm unsure what size I need. I've seen people say that you want one two times the size of the opening then I've seen people who use the exact size or a bit bigger.
Comment: The 25" diffusers must have one or two more dimensions you've failed to give. If the system works as built, changing the system may make it work less well, due to altering the disribution with additional resistance (the grille over a vent cover has a significant impact on the actual area of the vent cover, so it should always be larger than the vent behind it, unless the vent behind it is oversized.)
Comment: What other dimensions do I need to give?
Answer: The answer lies in two things:

The actual area of the duct opening
The need for diffusion around the room

Years ago I removed cumbersome, oversized diffusers spanning two duct openings from my 1950s home and replaced them with two modern, compact diffusers which were only slightly larger than the openings. I never saw problematic effects even in our severe climate.
As long as you don't reduce flow enough to leave the room uncomfortable and air is mixed adequately, have at it.
Answer: Diffusers do two things.  They diffuse.  They restrict flow.
Less diffusing might cause some parts of the room to be warmer or cooler, it might cause drafts to be felt near the register, it might be more easily obstructed by furniture.  Or none of those things might happen, or you might not care.  If the register is away from people and furniture, the air should mix all by itself.
More or less flow restriction will change the balance of heating and cooling between rooms.  Again, you might not care.  It happens all the time when you open and close doors.  If you replace all the diffusers make sure your new ones don't all provide less air flow.  That could be bad for the equipment or for energy usage.


What is the oxidation state of carbon atoms in Ethanoic acid?

Question: The oxidation states of $sp^2$ and $sp^3$ carbon in ethanoic acid  are $-3$ if we do not consider the electronegativity difference of these two carbons due to their different  hybridisation  but this is not the case with the thiosulphuric acid ($\ce{H2S2O3}$); here the oxidation states of sulphur here are +6 and -2. So why are we considering the electronegativity difference of two $sp^3$ and $sp^2$ sulphurs here?

Comment: Welcome to Chemistry! This seems like a [homework](http://meta.chemistry.stackexchange.com/questions/141/how-do-i-ask-homework-questions-on-chemistry-stack-exchange) question. We have a policy which states that you should show your thoughts and/or efforts into solving the problem. It'll make us certain that we aren't doing your homework for you. Otherwise, this question may get closed.
Answer: Typically when figuring oxidation state of an atom, electronegativity of different atoms of same element is considered equal. This means that in thiosulphate oxidation state of central sulfur would be somewhere around 4.
However!
Let us condider a very tricky case: ozone. Technically it consists of atoms of same element and the oxidation state of oxygen atoms should be zero. But ouch, auch, the central atom bears full positive chanrge in all feasible structures.... So, should ozone, disregarding electron shifts in covalent bonds, have oxidation state of atoms +1 (for central atom) and -1/2  (for two other atoms)? But this doesn't make much sense. This is a place where oxidation state abstraction breaks.
So, there are situations when oxidation state abstraction doesn't make much sence.
Thiosulphate is somewhate similar. The central sulfur behaves very muc like sulfur in sulfate, so by analogy it should be in +6 oxidation state. However, formally it is not the case. Here a clear conflict between formal abstraction and real life occurs, so people cope with it variously. One possibility is to arbitrarily say that the central sulfur of thiosulfate is in +6 oxidation state (and it makes sence). Another is to go formally (and it also makes sense). I saw both options in the wild.
TL;DR : formally the central sulfur in thiosulphate is +4; but people sometemes disregard it as the ion is very similar to sulphate with central sulfphur atom being +6.
Comment: @KumarGaurav It's not so much widespread, but it happens. For example, PH3, AsH3 and SbH3  are typically considered as 'reduced' -3 compounds, despite that hydrogen have electronegativity slightly above that of the elements in question.
Comment: @KumarGaurav ethanoic acid  is not the case, though. It is typically considered to have -3 and +3 carbons.
Answer: An sp2 carbon is more electronegative than an sp3 carbon but we generally don't consider the electronegative difference of the carbons while calculating the oxidation state.
Carbon is more electronegative than hydrogen hence the sp3 carbon will take the electrons from the hydrogen.
Oxidation state of sp3 carbon = $3(-1)= -3$
The sp2 carbon has a double bonded oxygen which is more electronegative than the carbon hence the carbon atom will lose 2 electrons to the oxygen. The oxygen of the OH group will also steal an electron from carbon hence giving a total of +3 oxidation state to the carbon.
Oxidation state of sp2 carbon =  $2(+1) + 1(+1) = 3$
Comment: exactly , just opposite in the of H2S2O3 (thiosulphuric acid) ,we consider the electronegativity difference of these two sp3 and sp2 sulphur ; why this kind of irregularities is practised  in carbon?


Batch mysql query editor

Question: I have a set of MySQL queries in PHP files. I want to mass-edit these queries, e.g. add an extra WHERE or UPDATE clause to all of them.
Is there any existing software that can do this?
Comment: Search + replace in a text editor?
Comment: Hopefully next time you'll properly abstract your database queries, to make this a *lot* easier. Let this be a lesson to you.
Answer: It's very unlikely that you'll find something that's capable of interpreting however you've chosen to implement your SQL query execution, in part because there's a plethora of approaches even using the out of the box PHP options.
As such, I very much suspect you'll need to search for whatever query execution function/method is in use and backtrack from there. (I suspect you'd need to do this anyway, as simply "adding a clause" would require human judgement/interpretation to achieve anyway.)
Hopefully your choose IDE will have a nice project/workspace-wide search that will make this a fairly trivial, if somewhat time-consuming, task.

Batch mysql query editor


potential difference between emitter-base and collector base constant, i.e 0.6 or 1.2v approx?

Question: i was solving questions on bjt, and i came across a question where i had to find voltage across emitter and collector and the answer was 2V, but i have read it's approx. 0.6v across both emitter base and collector base, then how does it amounts to 2v ?
Comment: Please use proper grammar and punctuation, it makes your question readable and it makes you look smart. Thanks
Comment: Are you sure that it's 0.6V across collector-base?
Answer: Your answer was for a specific load (voltage and resistance) and drive current. Depending on the circuit, the collector-base voltage can go from the collector breakdown voltage to about -0.6 volts or less. The first level occurs when the input base current is zero and the collector is at breakdown, and the second occurs when the transistor is in hard saturation, with a Vce on the order of 0.1 volts. Since in some high base-drive situations the base-emitter voltage can get larger than the nominal 0.7 volts, the voltage difference can be greater than 0.6 volts.
Answer: When a transistor is operating in its linear region, the base-emitter junction is biased on so it will develop a voltage of about 0.6-0.7 volts.  However, the base-collector junction is normally biased off.  Thus the collector-emitter voltage can be considerably higher than 2 junction drops and depends on the external circuitry.
Answer: The emitter-base junction is forward-biased (about 0.6V) but the collector-base junction is reverse-biased in normal linear operation.


What is the difference between a "prefix" and a "combining form"?

Question: According to ODO, mini- is classified as a combining form. How exactly is this different from a prefix (or an affix, in general)? Can combining forms also be prefixes?
Answer: Generally affix is used for morphological pre- and suffixes. So the /-z/ in Who goes there? is an inflectional affix (a suffix, in fact); this is also true of derivational affixes like -ation, -ize, -ism, be-, en- (and -en).
A combining form, on the other hand, refers prototypically to an allomorph of a (usually free) morpheme (like Malay satu /satu/ 'one') which appears when combined with a different morpheme as a word (like se- /sə/ in sepuluh 'ten'; compare dua 'two' and dua puluh 'twenty').
Mini- is a special case, what's called a libfix — a combining form like net- or -pocalypse that has escaped its morphological bonds and now pursues a new career in neologism creation.
Comment: @coleopterist: How did you fix that link?
Comment: You say *(usually) free*; your *usually* conforms to common practice where bound morphemes can have allomorphs as combining forms too. So what makes combining forms different from affixes? Moreover, undisputed affixes can have allomorphs too, such as plural *-s/-es*, or *-ise/-ize*. So I can't really see how combining forms are different from affixes at all, nor even how they could be a special category. I think what people mean is just nominal and verbal stems of Greek and Latin words used as affixes in English.
Comment: Often they are, but not always. The point of technical terminology is to describe behaviors accurately and consistently, rather than giving incomplete descriptions of irrelevant phenomena, like whether the root comes from Greek and Latin or not. That's not true of all such roots, and it's not universal for combining forms; that makes it a poor technical description.
Comment: @JohnLawler: I agree, which is why I called the whole concept amateurish. Correct me if you think a consistent, rigid definition can be formulated. The criteria you name do not exclude what is to be excluded, not do they include what is to be included—that is, they do not match what those who use this term "feel" must fall under *combining form*. So I don't think it is more than an intuitive idea of "difficult stems". I tried to convey that in my answer. What do you think?
Comment: As with all technical terms, a great deal of context is presupposed. Among professionals, rigidity is discouraged, since we can all get really stuffy when we need to, but it hinders communication. In dealing with questions that come from out of left field (like the ones here), with no presumption of shared context, and a million varieties of terminology applied any which way, there is some benefit in consistency and a certain rigidity may not be out of place.
Comment: @JohnLawler: A balance between rigidity and flexibility is usually best. In this case, several sources give definitions that vary a lot, and the whole just doesn't make much sense. The most striking similarity between all affixes labelled as "combining form" to me is their Greek/Latin descent; that is, this seems to be the best predictor. I really think that's what's going on in people's subconscious when they classify affixes as such.
Answer: There's a couple of distinguishing factors. A combining form is a modified version of another word (e.g. mini- for miniature) which can be joined to other words (mini + dress), combining forms (photo + graphy), or affixes (cephal + ic).
So a combining form has another form that it derives its meaning from (e.g. electro- and electric), whereas an affix is a modifier without a corresponding base word (e.g. the un- in unhappy is just a negating prefix). This also means that an affix can be attached to a word or combining form, but not another affix.
Combining forms are also often borrowed combining forms from Greek or Latin (-phile, -ography).
For example, "post-" would be a prefix, since it doesn't have a form which stands on its own, and needs to be attached to a full word for its meaning (after, behind) to come into effect.
Wiktionary
(Edited to incorporate additional discussion from the comments.)
Comment: There's a couple of distinguishing factors. A combining form has another form that it derives its meaning from (e.g. electro- and electric), whereas a prefix is a modifier without a corresponding base word (e.g. the un- in unhappy is just a negating prefix). Combining forms are also often borrowed combining forms from Greek or Latin (-phile, -ography). I believe "post-" would be a prefix, since it doesn't have a form which stands on its own, and needs to be attached to a full word for its meaning (after, behind) to come into effect.
Comment: How does that make them different from prefixes? Is _post-_ a prefix, a combining form, or both?
Comment: Thank you. Please incorporate your comment into your answer :)
Comment: Done! Cheers :)
Comment: *So a combining form has another form that it derives its meaning from (e.g. electro- and electric)* — that depends on how you look at it. Both the suffix *electro* and the adjective *electric* were borrowed from Greek through Latin and French, most probably, and so you can't really say one was derived from the other. The *-o-* was a theme vowel in Greek btw.
Comment: @Cerberus It's my (very amateur) understanding that combining forms are frequently borrowed from already existing combining forms in Greek or Latin, so it would make sense that electro- (the combining form) was borrowed from the Greek combining form, at the same time that electric (the noun) is also borrowed from Greek. The use "derive" was a bad word choice in this instance, since I don't necessarily mean that one evolved from another within English.
Comment: @Phire: Okay, then we are agreed.
Answer: The term combining form was probably meant for learners of English; it is not used on the same level as affix, although it signifies a kind of affix. It is commonly used to indicate nominal and verbal stems of Greek and Latin words used (mainly) as affixes in English. (An affix is meaningful sequence of letters or sounds that can be attached to other sequences of letters/sounds to form a word, but which is not an independent word itself with that particular meaning.)

The sequence of letters -ceive, for example, could be said to be meaningless on its own, because it cannot mean anything in English without some other element, like re- or per-. Then it is not considered a morpheme. (A morpheme is the smallest part of a word that still has an identifiable meaning and can be combined with other morphemes.) According to this approach, combining forms cannot exist as morphemes.
However, if you consider -ceive to mean something like "be the entity that something moves towards", or whatever seems to fit, then you treat it as a morpheme, and you say that receive consists of two meaningful parts, however vague or changeable their meanings may be. Because -ceive in receive exists as part of a word, not as an independent word, it is then a suffix there. (A sequence of letters/sounds can be an independent word in one sentence, and an affix in another; but -ceive is never an independent word, obviously. Or, at least, not yet.)
If you take the latter approach, you can use the word combining form for -ceive, as a special kind of suffix. However, the question remains, how are they special? The answer is: they are not really special linguistically. But for learners, it can be convenient to think of morphemes not in terms of affixes and independent words/stems, but in terms of "the form x is related to other forms, but it is only used in a certain situation, namely as an affix". That is more or less what "combining form" supposedly means, although it is apparently only used for Greek and Latin morphemes.
In the English word photography, for example, both photo- and -graphy are commonly called combining forms by those who use the term. Photo- can occur independently—although with a different meaning, so it is arguably a different morpheme there—, but -graphy normally cannot; it can occur with other prefixes, though, such as epigraphy and calligraphy. Then there are also photographic, telegraph, and telegram, which you could say contain allomorphs of -graphy, namely -graphic, -graph, and -gram. (An allomorph is an alternative form of the same morpheme, so with the same meaning and a similar, though different, form.) However, perhaps -graph- should be considered a morpheme, and -y a suffix signifying an occupation or system, -ic signifying an adjective. Then -gram- and -graph- can be considered allomorphs, as they were certainly in Greek, where the difference was merely related to pronunciation, not meaning—in so far as the two can be separated.
As you see, combining form leads to all kinds of problems, and it is a bit of an amateurish term. If you choose to treat certain parts of words as morphemes, it can be practical to present them as belonging to a fixed, clear-cut, special class; but this class will not sustain deeper scrutiny.
[Edit:] As to allomorphism, this occurs in affixes and non-affixes alike (see examples below). Of course the fundamental problem is: when are two sequences of letters to be considered allomorphs, and when entirely separate morphemes? Usually we take etymology into account for allomorphs, as in naming -graph- and -gram- allomorphs in English, or -th and -s in doth/does, or -ion/-ation, or flam- and flamm- in inflame/inflammation, or after- and aft- in afterthought and aft-deck, or in- and im- and il- and ir- in inhumane/impractical/illicit/irrespective, etc. Ultimately, it is a choice, not an immutable fact.
Comment: I'm not sure that the editors of the OED would normally be considered amateurish in their choice of terms.
Comment: @JonHanna: Oh, OK. First time I see it in the OED. I don't know why they chose that term: because it doesn't matter in context? They could just as well have used *affix*. Note how the OED does not use this term consistently, which leads me to think that they don't use it as a clear, definitive term; for *-graph* they say "termination"; for *pseudo-* and *-phile* they use "combining element"; for *fore-* they say "prefix"; and for *psycho-* "combining form". They just seem to call affixes from Latin/Greek something with "combining", most of the time. And Germanic suffixes "suffixes".
Comment: Thank you for the excellent answer. Could you please address @phire's point that (assuming that a combining form is _not_ an affix) prefixes are not "allomorphic" while combining forms can be?
Comment: @JonHanna: It can be convenient for learners, so that's probably why people use it. But I haven't seen it used in the OED? If you can come up with a satisfactory definition that includes and excludes the right things...because I have yet to see such a definition. I really think people just mean "affixes taken from Greek and Latin"...
Comment: @coleopterist: Done! My examples include various morphemes that I think are indisputably affixes, such as *aft(er)-* and *in/im/il/ir-*.
Comment: http://oedpublicpages.electricstudiolt.netdna-cdn.com/wpcms/wp-content/uploads/38pronunciation.png
Comment: Funny, the only definition of _combining form_ (or _compound(ing) form_) I've ever come across is that it is the form a(n independent) word takes when it functions as the first element in a compound. In English, that's usually just the same as the base form; in other Germanic languages, it might have an extra _-s_ or _-e_ or _-en_ or something; and in Greek and Latin, it most commonly entails adding a thematic vowel _-e_ or _-o_ (the latter quite productively so). So _bulls-_ is the combining form of _bull_ in the compound _bullseye_; but it's hardly an affix.
Comment: @JanusBahsJacquet: Right. It's just not a very useful term academically.
Answer: By "prefix" I understand mainly the usual prefixes used in Latin such as ab-,
ad-, con-, in-, ex-, inter- etc and their variants such as ab+f changed to aff- etc.
By "combining form" I understand mainly nouns that are used as a compound elements in compounds such as bookshop, boy-soldier, oil well etc.
Of course, there is a grey zone where you will find both terms applied.  multi- in multi-purpose vehicle  can be called prefix or combining form just as an author likes to call it.
It would complicate matters a lot to define the borderline between prefix and combining form.


My sql -u root can't connect from within MAMP

Question: I'm running a local wordpress install through MAMP, and I'm trying to access a mysql db that I can access in the shell (mac terminal) with mysql -u root. I'm trying to connect to the db using the a new instance of the wpdb object in a wordpress template file, and I'm getting a WordPress database error: [Unknown database 'DB_NAME'].
If I try to connect to one of the other db's installed through a mamp wordpress install, it knows about them. I'm trying to understand how MAMP defines its own root, and how I can access the db that I can call in the shell from my wordpress install within MAMP. I think that I may have to set a symlink somewhere in the MAMP install, but I'm not sure. This db is too big to access through phpmyadmin, so I would like to continue to access it through the terminal.
If anyone has found a workaround for this, I'd love to hear about it.
I found this entry:
Can't diagnose my MySQL root user problem
which sheds some light on my issue, but it doesn't solve it. I don't want to make it harder to access my root user db's through other apps.
Answer: Add a new user through phpmyadmin / shell and try with that rather than using root with no password.


How do you get soldiers in Prison Architect without losing or mods?

Question: I saw a friend have soldiers in his game, he had no mods, and it was not a Game-Over situation. How can I do that? I accidentally did It once, but I don't know  how.
Answer: You can't. I'm not sure how you were mistaken or are misremembering here- you should ask your friend instead.
There is no way in an umodded game to call in the army. The closest you can get is Riot Police- perhaps you were thinking of them?
The army can also show up in Escape Mode on the console version. Besides that, however, they only appear in the Uncontrolled Riot failure state.


Evaluate $\int_0^\infty{\frac{\tan x}{x^n}dx}$

Question: For$$PV\int_0^\infty{\frac{\tan x}{x^n}dx}$$
I can prove that it converges when $0<n<2$.
I know the ways to evaluate$$PV\int_0^\infty{\frac{\tan x}{x}dx}=\frac\pi2$$
but both of these 2 ways doesn't work.
First, using contour integration: the path used in evaluating the second integral doesn't fit in with the first one and I can't find a suitable path to the integral.
Second, seperating the integral: I had to calculate
$$\sum_{k=0}^{\infty}{\int_0^{\pi /2}{\tan t\left( \frac{1}{\left( k\pi +t \right) ^n}-\frac{1}{\left( \left( k+1 \right) \pi -t \right) ^n} \right) dt}}$$
which is unable to be solved by Mathematica.
I can't go further.
Answer: Szeto's computation of a contour integral is not wrong. The true issue is that the contour integral is not exactly the same as the original principal value in general. Here we correct his/her computation and obtain a closed form.
In this answer, I will use $\alpha$ in place of $n$ and save $n$ for other uses.

Step 1. It is conceptually neater to consider the Riemann surface $X$ obtained by joining
$$
\color{red}{X^+ = \{ z \in \mathbb{C}\setminus\{0\} : \operatorname{Im}(z) \geq 0 \}}
\quad \text{and} \quad
\color{blue}{X^- = \{ z \in \mathbb{C}\setminus\{0\} : \operatorname{Im}(z) \leq 0 \}}
$$
along the negative real line $(-\infty, 0)$. The resulting surface is almost the same as the punctured plane $\mathbb{C} \setminus \{0\}$ except that there are two copies of $(0, \infty)$, one from $X^+$ and the other from $X^-$. To distinguish them, we write $x + 0^+ i$ when $x \in (0, \infty) \cap X^+$ and $x + 0^- i$ when $x \in (0, \infty) \cap X^-$. This can be visualized as
$\hspace{5em}$
Then by pasting the complex logarithm on $X^+$ with $\arg \in [0, \pi]$ and the complex logarithm on $X^-$ with $\arg \in [\pi, 2\pi]$, we can create the complex logarithm $\operatorname{Log}$ on $X$ with $\arg \in [0, 2\pi]$. And this is the reason why we want to consider $X$. We also remark that complex analysis is applicable on $X$.

Step 2. For each $n \geq 1$ and $0 < \epsilon \ll 1$ we consider the closed contour $C = C_{n,\epsilon}$ on $X$ specified by the following picture.
$\hspace{6.5em}$
Here, the square contour has four corners $\pm n\pi \pm in\pi$ and each circular contour has radius $\epsilon$. Also the marks $\times$ refer to the poles $x_k = (k - \frac{1}{2})\pi$ of $\tan z$ which are all simple. We decompose $C$ into several components.

$\Gamma_n$ is the outermost square contour, oriented counter-clockwise (CCW).
$\gamma_{\epsilon}$ is the circular contour around $0$, oriented clockwise (CW).
$L = L_{n,\epsilon}$ is the union of line segments
$$
[\epsilon, z_1 - \epsilon], \quad
[x_1 + \epsilon, x_2 - \epsilon], \quad
\cdots, \quad
[x_{n-1} + \epsilon, x_n - \epsilon], \quad
[x_n + \epsilon, n\pi]$$
which are oriented from left to right. To be precise, there are two versions of $L$ depending on which of $X^{\pm}$ is considered. One is $\color{red}{L^+ := L + 0^+ i}$ on $X^+$ and the other is $\color{blue}{L^- := L + 0^- i}$ on $X^-$.
$\gamma^{+}_{k,\epsilon} \subset X^+$ denotes the upper-semicircular CW contour of radius $\epsilon$ around $x_k + 0^+ i$.
$\gamma^{-}_{k,\epsilon} \subset X^-$ denotes the lower-semicircular CW contour of radius $\epsilon$ around $x_k + 0^- i$.

Then our $C_{n,\epsilon}$ is written as
$$ C_{n,\epsilon} = \Gamma_n + \gamma_{\epsilon} + (L^+ + \gamma_{\epsilon,1}^{+} + \cdots + \gamma_{\epsilon,1}^{+}) + (-L^- + \gamma_{\epsilon,1}^{-} + \cdots + \gamma_{\epsilon,1}^{-}). $$

Step 3. We consider the function $f : X \to \mathbb{C}$ defined by
$$ f(z) = z^{-\alpha} \tan z $$
where $z^{-\alpha} := \exp(-\alpha \operatorname{Log} z)$. Then the original principal value integral can be written as

$$ \mathrm{PV}\int_{0}^{\infty} \frac{\tan x}{x^{\alpha}} \, dx
= \lim_{\epsilon \to 0^+} \lim_{n\to\infty} \int_{L_{n,\epsilon}} \frac{\tan x}{x^{\alpha}} \, dx. \tag{1} $$

On the other hand, by the Cauchy integration formula, we obtain
$$
\int_{C_{n,\epsilon}} f(z) \, dz
= 2\pi i \sum_{k=1}^{n} \text{[residue of $f$ at $-(k-\tfrac{1}{2})\pi$]}
= -\frac{2\pi i}{\pi^{\alpha} e^{\alpha \pi i}} \sum_{k=1}^{n} \frac{1}{(k-\frac{1}{2})^{\alpha}}
\tag{2}
$$
Now assume for a moment that $\alpha \in (1, 2)$. Then it is not hard to check that
$$ \int_{\gamma_{\epsilon}} f(z) \, dz = \mathcal{O}(\epsilon^{2-\alpha})
\quad \text{and} \quad
\int_{\Gamma_n} f(z) \, dz = \mathcal{O}(n^{1-\alpha}). $$
Moreover,
\begin{align*}
\int_{L^+} f(z) \, dz
&= \int_{L} \frac{\tan x}{x^{\alpha}} \, dx, \\
\int_{-L^-} f(z) \, dz
&= -\frac{1}{e^{2\pi i \alpha}}\int_{L} \frac{\tan x}{x^{\alpha}} \, dx
\end{align*}
and for each $k \geq 1$,
\begin{align*}
\lim_{\epsilon \to 0^+} \int_{\gamma_{k,\epsilon}^{+}} f(z) \, dz
&= \frac{\pi i}{\pi^{\alpha} (k-\frac{1}{2})^{\alpha}}, \\
\lim_{\epsilon \to 0^+} \int_{\gamma_{k,\epsilon}^{-}} f(z) \, dz
&= \frac{\pi i}{\pi^{\alpha} e^{2\pi i \alpha} (k-\frac{1}{2})^{\alpha}}.
\end{align*}
Combining altogether, we find that $\text{(2)}$ simplifies to
\begin{align*}
\left(1 - e^{-2\pi i \alpha} \right) \int_{L} \frac{\tan x}{x^{\alpha}} \, dx
&= -\pi^{1-\alpha} i \left(1 + 2e^{-\alpha \pi i} + e^{-2\pi i \alpha} \right) \sum_{k=1}^{n} \frac{1}{(k-\frac{1}{2})^{\alpha}} \\
&\qquad + \mathcal{O}(n^{1-\alpha}) + \mathcal{O}(\epsilon^{2-\alpha}).
\end{align*}
Therefore, letting $n\to\infty$ and $\epsilon \to 0^+$ yields
$$
\mathrm{PV}\int_{0}^{\infty} \frac{\tan x}{x^{\alpha}} \, dx
= -\pi^{1-\alpha} i \frac{(1 + e^{-\alpha \pi i})^2}{1 - e^{-2\pi i \alpha}} \sum_{k=1}^{\infty} \frac{1}{(k-\frac{1}{2})^{\alpha}},
$$
which simplifies to

$$ \mathrm{PV}\int_{0}^{\infty} \frac{\tan x}{x^{\alpha}} \, dx
= -\pi^{1-\alpha}\cot\left(\frac{\alpha\pi}{2}\right) (2^{\alpha} - 1)\zeta(\alpha). \tag{*} $$

This extends to all of $\operatorname{Re}(\alpha) \in (0, 2)$ by the principle of analytic continuation. For instance, by taking $\alpha \to 1$ we retrieve the value $\frac{\pi}{2}$ as expected. Also the following is the comparison between the numerical integration of the principal value (LHS of $\text{(*)}$) and the closed form (RHS of $\text{(*)}$):
$\hspace{7em}$
Comment: Thanks you for providing a correct answer as well as responding to my answer. I'm just a high school student and has had no 'real' training in complex analysis. I cannot see where I had a mistake with the principal value in my original solution. Could you please point out? Also, it would be great if you could add to your answer to briefly talk about how you derived your final result. Thanks!
Comment: nice answer (+1)...but i don't exactly see how you get (*). Namely where does the $\cot$ comes from? can you hint me in the right direction, i'm getting a bit rusty with this stuff
Comment: @Szeto, The issue here is that the principal value integral is not the ordinary integral. It takes cares of simple poles of $\tan$ at $(k-\frac{1}{2})\pi$ for $k = 1, 2, 3, \cdots$ by excising the $\epsilon$-neighborhood around each pole, integrating $x^{-n}\tan x$ on the resulting excised domain, and then letting $\epsilon \to 0^+$. Comparing this procedure with your contour integral, you can find that you owe extra terms which come from the contour wrapping the poles of $\tan$. Taking account of those contributions corrects your computation.
Comment: @tired, I rewrote my answer so that it is mostly self-contained. I hope that this clarifies your question.
Answer: I found a solution to this problem which is not so rigorous, so I'm not very confident and might delete it if some fatal errors are found.
My solution only applies for $n>1$.
To evaluate $\int^\infty_0\frac{\tan x}{x^n}dx$, we consider the contour integral $$\oint_C\frac{\tan z}{z^n}dz$$ where the branch cut is taken along the positive real axis and a keyhole contour is used.

We can decompose $C$ into 4 parts:
(1) Small loop about $0$, expected to approach zero as the loop size tends to zero. This is the part which I'm not certain about.
(2) Straight line integral on the upper real axis $$\int^R_0\frac{\tan t}{t^n}dt$$
(3) Large loop about $0$, which should also vanish as its radius($R$) tends to infinity.
(4)Straight line integral on the lower real axis $$\int^0_R \frac{\tan t}{e^{2\pi ni}t^n}dt$$
There are poles at $\pi(-\frac{1}{2}-k)$ ($k$ is positive integer) of residue $-1$ at each.
By residue theorem, we obtain
$$\int^\infty_0\frac{\tan t}{t^n}dt +
e^{-2\pi ni}\int^0_\infty \frac{\tan t}{t^n}dt=
2\pi i \sum^\infty_{k=0}\frac{-1}{[{(\frac{\pi}{2}+k\pi)e^{\pi i}]}^n}$$
Thus,
$$(1-e^{-2\pi ni})\int^\infty_0 \frac{\tan t}{t^n}dt=
2\pi i \sum^\infty_{k=0}\frac{-1}{[{(\frac{\pi}{2}+k\pi)e^{\pi i}]}^n}$$
After some messy algebra,
$$\int^\infty_0 \frac{\tan t}{t^n}dt=
-\frac{2^n}{\pi^{n-1}}\csc(n\pi)\sum^\infty_{k=0}\frac{1}{(2k+1)^n}$$
which the sum clearly converges only when $n>1$.
The result makes me think of the Riemann Zeta function, so I conjecture that we might able to extend the region of convergence of the summation by analytic continuation.
Indeed, I believe there are some flaws in my solution, since in no way does the answer approach $\frac{\pi}{2}$ when $n \to 1$.
Comment: By exploiting the symmetry of the "Hurwitz" decomposition of $\tan(z)$ I got that the principal value of $\int_{0}^{+\infty}\frac{\tan x}{x}\,dx$ is exactly $\frac{\pi}{2}$, and $$\text{PV}\int_{0}^{+\infty}\frac{\tan t}{t^\alpha}\,dt$$ cannot be convergent for $\alpha\geq 2$ due to the non-integrable (and non-eliminable through symmetry)  singularity at $t=0$.
Answer: By applying $\frac{d}{dz}\log(\cdot)$ to the Weierstrass product for the cosine function we have
$$ \tan(z) = \sum_{n\geq 0}\frac{8z}{(2n+1)^2 \pi^2-4z^2}=-\sum_{n\geq 0}\left(\frac{1}{z-(2n+1)\frac{\pi}{2}}+\frac{1}{z+(2n+1)\frac{\pi}{2}}\right) $$
uniformly over any compact subset of $\mathbb{C}\setminus\left\{\ldots,-\frac{3\pi}{2},-\frac{\pi}{2},\frac{\pi}{2},\frac{3\pi}{2},\ldots\right\}$. Similarly,
$$ \cot(z) = \frac{1}{z}+\sum_{n\geq 1}\left(\frac{1}{z-n\pi}+\frac{1}{z+n\pi}\right) $$
uniformly over any compact subset of $\mathbb{C}\setminus\pi\mathbb{Z}$. We may notice that
$$ \text{PV}\int_{0}^{+\infty}\frac{\tan x}{x}\,dx = \sum_{n\geq 0}\text{PV}\int_{n\pi}^{(n+1)\pi}\frac{\tan x}{x}\,dx=\int_{0}^{\pi/2}\cot(x)\sum_{n\geq 0}\frac{8x}{(2n+1)^2\pi^2-4x^2}\,dx $$
and the RHS clearly equals $\int_{0}^{\pi/2}\cot(x)\tan(x)\,dx = \int_{0}^{\pi/2}1\,dx = \frac{\pi}{2}$. Similarly
$$ \text{PV}\int_{0}^{+\infty}\frac{\tan x}{x^\alpha}\,dx = \sum_{n\geq 0}\text{PV}\int_{-\pi/2}^{\pi/2}\frac{-\cot x}{\left(x+(2n+1)\frac{\pi}{2}\right)^{\alpha}}\,dx\\=\int_{0}^{\pi/2}\cot(x)\sum_{n\geq 0}\left(\frac{1}{\left((2n+1)\frac{\pi}{2}-x\right)^{\alpha}}-\frac{1}{\left((2n+1)\frac{\pi}{2}+x\right)^{\alpha}}\right)\,dx $$
for any $\alpha\in(0,2)$, but I do not believe this is an elementary integral (even by including the $\Gamma,\psi$ and Bessel functions among the elementary functions) if $\alpha\neq 1$.


How long, at most, did women delay marriage during the time of Prophet Muhammad as per records?

Question: I want to know if there are any records of women who were  unmarried (not divorced or widowed) for a long time(more than 20 years) during the time of Prophet Muhammad. Because if it was a tradition at that time to give women in marriage at an early age, I would like to know what were the longest they had been delayed.
Comment: There's not much which was documented neither during the days of the prophet nor in pre-Islamic Arabia. Also as there are disputes about the ages of rather known people such as 'Aisha and Khadija -at their marriage with the prophet-. How would we know that the age of a rather unknown Muslima  at the time of her first marriage would have been reported somewhere. This is just my logic it is however posisble that such a report exists.
Comment: For example [Wikipedia](https://en.wikipedia.org/wiki/Asm%C4%81%27_bint_Abi_Bakr) suggests that Asma' the daughter of abu Bakr was born 27 years before Hijra and married a-Zubayr before the hijrah and was pregnant with her first (born) son 'Abdullah which may lead to the conclusion that her marriage age might be around 25 years.
Comment: @Medi1Saif It was a curious question. I did not want an accurate answer, rather reports which may exist in documentaries. Thank you for the above example.
Comment: Then you should re-phrase your post, for example you might ask are there records of women that have been unmarried until the age of 20 or later?
Answer: There are two findings that might be of use for your inquiry:
Asma' the daughter of abu Bakr the older sister of 'Aishah and the wife of az-.Zubayr ibn al-'Awwam and mother of 'Abdullah ibn az-Zubayr (who was her first -born- son).
According to Muslim sources and as stated in wikipedia she was born 27 years before the hijrah and married short before the hijrah and was pregnant with 'Abdullah when moving to Medina. This leads to the conclusion or assumption that she might have been around 25 years old when she got married.
Also note there's a woman who never got married among the sahabh this woman is called Umm Shareek and she was one of the believing women who gave herself to the prophet () mentioned in (33:50):

... and a believing woman if she gives herself to the Prophet [and] if the Prophet wishes to marry her,  [this is] only for you, excluding the [other] believers. ...

and further

You, [O Muhammad], may put aside whom you will of them or take to yourself whom you will. And any that you desire of those [wives] from whom you had [temporarily] separated - there is no blame upon you [in returning her]. That is more suitable that they should be content and not grieve and that they should be satisfied with what you have given them - all of them. And Allah knows what is in your hearts. And ever is Allah Knowing and Forbearing. (33:51)

Ibn Sa'ad narrated in his at-Tabaqaat al-Kubra the following statements:
 In the following I'll translate from Arabic, these translations are mine take them carefully.

قال الواقدي حَدَّثَنَا مُوسَى بْنُ مُحَمَّدِ بْنِ إِبْرَاهِيمَ التَّيْمِيُّ، عَنْ أَبِيهِ، قَالَ: «كَانَتْ أُمُّ شَرِيكٍ امْرَأَةً مِنْ بَنِي عَامِرِ بْنِ لُؤَيٍّ، وَإِنَّهَا وَهَبَتْ نَفْسَهَا لِرَسُولِ اللَّهِ فَلَمْ يَقْبَلْهَا رَسُولُ اللَّهِ فَلَمْ تَتَزَوَّجْ حَتَّى مَاتَتْ
  Al-Waqidi (Muhamamd ibn 'Umar) said: Musa ibn Muhammad ibn Ibraheem at-Tayyimiinformed us from his father who said: Umm Shareek was a woman from the bani 'Aamir ibn Lu'ay, and she was amoing the women who gave themselves to the Messeneger of Allah, but he didn't accept her and she remained unmarried until she died. (See #11964 here)

This suggests that she is from Quraish as Lu'ay is among the clans of Quraish.

وقال الإمام الشعبي في تفسير قوله تعالى: {تُرْجِي مَنْ تَشَاءُ مِنْهُنَّ} [الأحزاب: 51] قَالَ: «كُلُّ نِسَاءٍ وَهَبْنَ أَنْفُسَهُنَّ لِلنَّبِيِّ -صلّى الله عليه وسلم- فَدَخَلَ بَعْضَهُنَّ وَأَرْجَأَ بَعْضًا فَلَمْ يَنْكِحْنَ بَعْدَهُ، مِنْهُنَّ أُمُّ شَرِيكٍ»  (See also in tafssir ibn Kathir)
  The imam a-Sha'abi said in his tafseer on Allah the Almighty's words: (You, [O Muhammad], may put aside whom you will) (33:51): "All women gave themselves to the Prophet Allah's prayers and blessings be upon him, so he toke some and put aside some others and they didn't marry after that among those was Umm Shareek. (Wak'i narrated something similar as stated in the Hadith #11965 in the link above from ibn Sa'ads Tabaqat).

Ibn Sa'ad on this topic narrated different narrations on this topic one of them saying the prophet () accepted her, but divorced her before consummation of the marriage. The above statement also could lead to the interpretation that he either refused her or divorced her after consummation.
Imam a-Dhahabi quotes her in his Siyar a'alaam an-Nubala' as follows:

أم شريك
   امرأة أنصارية . النجارية .
  Umm Shareek, a woman fom among the Ansar from the family of an-Najjar.
عن قتادة  : أن النبي صلى الله عليه وسلم قال : إني أحب أن أتزوج في الأنصار ؛ ثم إني أكره غيرتهن قال : فلم يدخل بها .
  Qatadah said: The prophet Allahs prayers and blessings be upon him said: I'd love to marry a woman from among the Anssar. but I hate (reject) their jealousy so he didn't consume the marriage.
نعم ، وروى عروة بن الزبير ، عن  أم شريك  : أنها كانت فيمن وهبت نفسها للنبي صلى الله عليه وسلم  .
  Yes and it was narrated from 'Urwah ibn az-Zubay from Umm Shareek that she was among those women who have given themselves to the prophet Allahs prayers and blessings be upon him (this was also compiled in Musnad Ahmad see here in Arabic)

Ibn 'Abd al-Barr in his Al-Istee'ab fi Ma'rifati al-Ashaab الاستيعاب في معرفة الأصحاب (a collection of biographies of Sahabah) however tried to find a midway solution as in the  narrations of historians Umm Shareek was said to be from among the muhajereen and some refer to her as a Dawsiya (from the tribe of Daws in Zahran) or al-Ansariyah (in many ahadith) and he said she might have been married either to a person from this tribe or from the bani an-Najar (who are from the Khazraj in Medina). There's also an attribution to the tribe of Kinanah mentioned in the Arabic Wikipedia site on her. Most of these narration agree that she was called Ghaziyah bint Jabir ibn Hakim غزية بنت جابر بن حكيم.
Imam at-Tabarani called her: غزية بنت جابر بن حكيم الدوسية أم شريك Ghaziyah bint Jabir ibn Hakim a-Dawasiya Umm Shareek in his al-Mo'ajam al-Kabir -see here in Arabic- when confirming that she was among the woman that gave themselves to prophet().


Spectrogram app for the Mac

Question: Where do I find a real time spectrogram analysis application for the Mac?  Freeware or Shareware if possible.
Answer: Spectrogram is a free real-time spectrum analyzer VST plug-in for Macintosh. The spectrum may be shown in 4 different modes: "Spectrograph view" - "Waterfall view/ 3D" - "Spectrogram view" - "Power view" . Settings include: input choice (mono/stereo), FFT Size choice (1024/4096), magnitude and scroll/frame speed.
Answer: AudioXplorer is pretty good, open source (BSD license), and it can do both real-time and file analysis.  It shows an oscilloscope, spectrum, and spectrogram/sonogram.

One flaw is that the frequency axis and spectrum level are both linear instead of being log-scaled frequency and dB, and I don't see an option to change that.
Answer: This one is the best as of 2023: https://friture.org/

Spectrogram app for the Mac


Will running an LED designed for batteries on a NEXUS dynamo hub damage the LED?

Question: I have a question about LEDs on 6V Shimano dynamo hubs. I built up an old Schwinn with a Nexus dynamo hub, and the headlight I'm using is based on an LED 6V headlamp. The LED is a Chip-on-board design, and I've wired it directly to the two terminals on the hub without using the frame as a ground.  I have the pulses set up to alternate between the headlight and the tail lights. The light works great, but I wasn't aware that the Shimano dynamo is putting out reverse-polarity pulses as well as the ones properly oriented to light the LED. Is this bad for the LED bulb? Will it burn out prematurely because of the reverse pulses?
Comment: It's a little iffy.  The dynamo is likely designed to drive lot more current than the LED uses, and the voltage regulation would be relatively poor.
Comment: @DanielRHicks essentially all bike dynamos are AC, though the word "dynamo" refers to a DC source in many contexts. I haven't found a complete adaptor except expensive 5V regulators with a USB socket, but the design is fairly simple: bridge rectifier - capacitor - voltage regulator (if the LED comes with a current regulating driver) or current regulator (for a bare LED). I'm working on something similar to allow a light that also works off a 5V battery pack. Downside is the lack of a standlight without more complex electronics
Comment: I'm reminded that there are AC dynamos and DC ones (perhaps more properly called "generators").  Probably AC is predominant, and generally unsuited for powering a "bare" LED lamp.  A reasonably astute electronics hobbyist could easily rig an adapter, however (and there may be some for sale on the Interweb).
Answer: Reverse pulses at low voltage probably won't damage the LED, but the COB (chip on board) that gives the flashing modes might not be able to cope with the full reverse voltage.
The problem is that the hub dynamo is more accurately a constant current source, and will supply about 500mA. One common trick is to run two 6V lights in series off a hub dynamo, and most dynamos will give full brightness from both... they put out 12V. The actual voltage you get out of it might be clamped by a zener, but it's unlikely to be a 5W zener that can take the full power of the hub forever. Not that you want that anyway, it's extra drag.
I have run bare 5W star LEDs straight off a SON hub dynamo (well, with a diode and capacitor to reduce flickering) because they're designed to take 500mA and that's what the dynamo supplies. It worked really well, just using a chunk of aluminium channel as a heat sink/weather sheild/reflector. I don't really know about longevity, after ~10,000km/a year or so I got a proper light cheap so switched to that.
So if your 6V LED is actually a 1W light it might be getting 12V or more. Whether it survives that is anyone's guess. Worse, even a 5W light is likely to be getting +6V on that half of the wave, then -12V on the other half when it's not drawing any power. I suggest a basic diode or bridge rectifier in series, capacitor in parallel to give you DC.
Comment: I suspect the LED itself will be fine, protected by the driver, but the drive circuit won't last long
Comment: +1 for pointing out the dynamo is a source of current rather than voltage - so the voltage can rise
Answer: LEDs don't like negative voltages. They generally fry at some 3x-5x their normal forward voltage.
Then again, you don't have a bare LED, but a LED and a LED controller and it is the controller that is likely to suffer first. The bad thing is, we don't know much about it.
Another bad thing is that the 6v hub is actually 6v when properly loaded w/ 6V, 3W bulb. Otherwise it can go very high, like 50V.
You'll get prettu much extra complexity if you try to do the proper thing.
You can as well opt for a simple & stupid solution like hub => bridge rectifier => 1.5W white led (bare, without controller). It will behave almost like a bulb, except for the brighter light and about half the drag.
Answer: 6v is probably low enough to not damage the LED, but you might be vulnerable to a voltage spike. You could use a regular diode in series to help protect the headlight.
Comment: I don't see how a diode in series is going to help.
Comment: The poster is concerned about running an LED light on AC output. As other posters have also pointed out, a diode in series forms something like a half-wave rectifier, except an LED is not a resistive load. With a resistive load, all the voltage would drop across the rectifier diode. With a diode load, the voltage drop will be split between the rectifier diode and the load diode according to their respective V_f specs, but reverse voltage load on the headlight will be still reduced. Forward current will be almost unaffected by the rectifier diode.
Comment: @DanielRHicks the forward voltage drop of the diode lowers the voltage seen by the light, and the diode also prevents the reverse polarity half of the wave from being seen by the light. The latter is probably more important. But more information is needed in the answer to really know.
Comment: Try measuring actual output from a hub dynamo. It's nowhere even close to nice 6v.
Comment: Using a diode in series will split the amount of reverse voltage that the headlight receives, which seems to be what the poster is concerned about. Depending on the parameters of the diode there should be minimal impact on the brightness.
Comment: That did not make any sense at all.
Comment: @BetterSense it would be useful if you could take these comments and use them to improve your answer. That's the main thing comments are (supposed to be) for. Hit the "edit" button and have a go...
Answer: I think the best solution is to get a light built for that particular hub. That way I can be sure that it's engineered to work properly with that system. It's a shame--that light looks so good with this bike.
.
Comment: You could probably find a way to mount the electronics of a simple dynamo light inside the existing light housing to get the best of both.


Suggesting a book to understand politics theory and the organization of states

Question: I am a politics and history hobbyist but my engineering life didn't give me enough time to dive more into politics and think about more advanced concepts and improve my formal political knowledge. So, in this regard, i want suggestions for books to formally understand the organization of a nation, the different structures it has, how they relate together, understanding different political systems and how they relate to economy; Kind of books from authors like : Karl Marx, Jean-Jacques Rousseau, Vladimir Lenin or modern political philosophers.
Comment: This question was likely closed as too broad because the books written about this topic could fill a whole library. Which of them are worth reading and which aren't would be a matter of personal opinion.
Comment: Voting to re-open. There is definitely space for answers based on professional opinion in this answer. Just like a surgeon could recommend surgery books, a political theorist can recommend books influential and important in the field of political theory.
Comment: John Locke is mandatory for understanding Natural/Individual Rights and the principles which inspired the Declaration of Independence and the Bill of Rights. Friedman & Murry Rothbard to understand government's role in economics. Marx, Hegel, Lenin & Hitler's Mein Kampf to understand tyranny & oppression.
Answer: I would suggest first the classics such as Plato, Machiavelli, and then John Locke and Adam Smith to understand the capitalist grounds of today. More recently, I would suggest Jason Brennan's Against Democracy for a delightful criticism of democracy.
Answer: This Q. supposes there's been a "formal" treatment of nations that's universally satisfactory the way a good physics textbook might be.  While various people talk as if this is the case, politics is more of a strange art, or a proto-science, (like alchemy), than it is a hard science; and this art presently has several competing "formal" theories and schools that attempt to describe what nations are, why things are the way they are, what's feasible, and how to achieve political goals; there's also endless critiques between competing schools that are as rivalrous as competing religious sects.
About the only formal approach that's not contentious is historical, which consists of studying various theories for the last few thousand years.  Which ideally would allow students to learn from history, so that when they finally get around to studying the present day and its contentious competing theories, the student will better be able to distinguish the promising ideas from the less useful ones.  Whether students of politics actually are made more able by such studies seems less clear.
The contentious formal approaches are all the same in the abstract.  Some partisan political pope declares a set of certain truths, and their students narrowly study the books of whoever their pope commends.  For devoted students there's two possible outcomes:

The student becomes a lifelong adherent of their pope's political theories or truths.
The student finds too many inconsistencies, becomes a heretic, and either follows another school's pope, or, if he should live so long, starts his own school...

As an alternative to these, the student can follow the example of engineering -- many excellent engineers and inventors were not scholars of science, but nevertheless wound up contributing to it.  For politics the method would be to find a problem, (unsolved), study various approaches, and select or devise some feasible remedy, then test it, note the results, and perhaps share those with some like-minded community.


Is an integrated graphics core needed?

Question: I am building my first desktop and before I order the parts I need to know if an integrated graphics core is needed in a CPU if I am going to use a high end graphics card attached through an expansion slot. If not is one required in the motherboard or can the graphics card just be plugged in?
Comment: Closed for off-topic might make sense, but "not-constructive"? No, the plug-in will often override the mobo GPU or you'll disable the on-board in BIOS. It's a simple yes/no question: on-board is not required.
Answer: If you plan to only use a dedicated graphics card, then no - the internal graphics core of the CPU would be useless.
Maybe you would be able to use something like Nvidia Optimus to save power by only using the dedicated GPU for graphically intensive tasks like gaming or GPU computing, and automatically switching to the internal GPU for everything else. However, I don't know if that technology is available for desktop computers.
In any case, the internal core (even in combination with the dedicated GPU, if possible) could only be used if your motherboard provides the necessary connections from the CPU to the southbridge, and some kind of graphics ports (VGA, DVI, DisplayPort or HDMI).
Comment: Optimus is only on laptops as far as I know
Comment: Lucid's Virtu functionality is sort of similar, and is starting to pop up.
Comment: Thanks, I don't like to have everything ordered then find out that something has to be included in a part that I spent hundreds of dollars on.
Comment: @JamesLewis: The integrated cores on Intel's Ivy bridges aren't "extra money."  A complementary non-GPU Intel does not exist for those CPUs.
Comment: what i mean is that i don't like to pay for something then find out i ordered one that relied on something that isn't there because if something is missing i need to order a new one. this is because the CPU i wan't to order has no graphics core.

Is an integrated graphics core needed?


Tracing the request.xml sent using apex callout

Question: I make an apex callout to an external service by consuming the WSDl file.I use WSDL2Apex class which I generated from WSDL file. I send a XML file as a request formed in my apex class to make a callout. When I check the debug log I see something like CALLOUT REQUEST which has some apex schema ....{Some way of shwoing the request}... Is there a way to see complete request.xml in debug log?
Comment: @SfdcBat It does in Developer Edition orgs. Again, in a Sandbox it might be significantly truncated to keep the log size down.
Comment: Have you tried setting the Callout settings to "Finest"? I'm not sure it'll help, but it's worth a shot.
Comment: Are you making the Callout from a Developer Edition org or a Sandbox? If I recall correctly only Developer Edition orgs show the full callout SOAP request in the logs. Or at least that was the case historically.
Comment: @DanielBallinger I am using sandbox. I don't see the request.xml as I see in Soap UI
Comment: @sfdcfox I have it set as finest. But did jot get the complete request xml that I am passing. Basically I am trying to see what values I am passing in the request. Whether the values are set correctly when sending request. I had to debug an incorrect request since the end system was not receiving any values.
Comment: @SfdcBat The CALLOUT_REQUEST that you can access in a sandbox may have the SOAP request contents. It would just be formatted as Apex objects in JSON rather than SOAP/XML.
Comment: @DanielBallinger wondering would it also show the values that I set for each variables in the request?
Answer: You can't see the full CALLOUT_REQUEST from a Sandbox. See the idea - View Callout Request and Response XML in Sandbox.

We can't do this without blowing up the debug logs. Debug logs can only be 2MB, and your request and/or response can be 12MB.  Even if it's only 1MB each, that's the end of your debug log.
We have the same issue with String.  If we wrote out the value of each string every time it was changed, the logs would be consumed by the string variables. For these, we truncate, so you can get an idea of the contents of the variable.  A truncated request or response would be nothing but frustrating, as all you'd get would be the first part of the header.
If you know your request or response is small, and won't consume your entire debug log, you can output the body directly by calling something like system.debug(req.getBody()).
If you want to see it you will need to use a Developer Edition org.

It's a bit clunky, but you could use a secondary external service to receive and log the SOAP request. I've seen suggestions for requestb.in. I went so far as to to create an Apex REST resource that would save the POST body to a custom object. See Debugging an Outbound Message using a public facing Apex REST web service


how to make 3D game physics or collision detection

Question: I really need to know how to make collision detection. I can only do axis-aligned-bounding-boxes. I have heard of other methods. I heard of something called a minimal oobb. but I can't figure them out. I'm still in school and I'm pretty good at math. But I don't know the first thing about physics. I know I could use Bullet physics but I really would like to know how to do it myself. I don't really know about anything other than aabbs and oobbs. and as I said before, aabbs are all I can do. So please show me what methods there are and where I can learn how to do them. Thanks in advance :D
Comment: It depends on what you want to accomplish.  If you are doing this for learning, by all means dig into various methods of simulating physics.  But if you are trying to create an application that requires simulated physics, do not reinvent the wheel.  Do some searching and I am sure you will find existing libraries you can use.
Comment: I know I can use a library  but I want to know how to do it myself.
Answer: I think this book is best for you...
http://www.amazon.com/Real-Time-Collision-Detection-Interactive-Technology/dp/1558607323
Comment: I'll consider it. I was hoping for an online explanation but I guess everything ain't for free. I'll try to look a little longer but if nothing else I'll buy it. thanks for the answer


How to map webdav folder seamlessly in windows

Question: I have a webdav folder (generated by java webdav server), which I can access via "My network places" on WinXp (after mapping).
I would like for the user to see it via "My Computer" as a system folder (or something similar). Is there anyway to do that?
Answer: You could map it to a drive, but I don't think you can map it to a folder.
I'm not sure what you're trying to achieve / mean by "system folder".


Why aren't all Professors Ravenclaws?

Question: Ravenclaw is for all the smart wizards. Presumably, anyone who ended up as a Professor must have been pretty smart. So why are there Professors not from Ravenclaw?
Comment: Seems like a fallacy to think teachers are inherently the smartest of a group.
Comment: "Ravenclaw is for all the smart wizards" so all the others are dumbasses ? Plus the "main characteristic" of a Ravenclaw is to pursue knowledge, not be smart, you can pursue knowledge and fail to acquire it, just look at Lockhart !
Comment: not everyone that is a teacher set out to become one. Lupin being an example
Comment: BTW, for anyone reading this: the thought behind the question is a logical error called an _[associative fallacy](https://en.wikipedia.org/wiki/Association_fallacy)_ which goes like this: _Ravenclaws are smart; Professors are smart; Professors ought to be Ravenclaws_. (Yes, I know this is old. I don't know why it popped up on my feed.)
Comment: I had a college prof who was a certified genius and, apparently went from never playing chess to Master level in a year. He could __not_ communicate with other human beings, though. He was a _terrible_ prof because he didn't know how to teach others what was obvious and intuitive to him. He was _really_ good at other things, though. Being "smart" does not a good teacher make.
Answer: Hufflepuffs are quite resourceful and reliable, very good qualities to have for a teacher trying to teach a difficult subject.
Slytherins are quite tricky and manipulative, and knowing how to use that to slip knowledge into a student's mind would be quite like them.
Gryffindors are courageous, and what sort of courage it must take to teach a classroom full of spell-potent young wizards.
In short: There are more qualities to being a teacher than just "knowing everything".
And, more to the point, the most scholarly student of them all in the series, Hermione Granger, was in house Gryffindor. So clearly there's more to being chosen for Ravenclaw than simply 'You are the smartest'.
Comment: Furthermore, I would say the qualities of Ravenclaw - pursuing knowledge - wouldn't necessarily mean you would be a good teacher, or even want to be. Not all researchers and experts can teach or even talk to others about their fields - that takes a different sort of skill.
Comment: @AnthonyGrist It just means your primary attribute is intelligence. It's not a *negative* thing.
Comment: @AnthonyGrist Just like being sorted into Gryffindor means that there's *nothing* to you except courage? Not really sound logic.
Comment: "So clearly there's more to being chosen for Ravenclaw than simply 'You are the smartest'." I think it's more that being Sorted in to Ravenclaw means there's nothing to you *except* your intelligence.
Comment: @AnthonyGrist Lockheart.
Answer: Intelligence isn't limited to those who are in Ravenclaw, and it isn't the only characteristic that the Sorting Hat looks for when assigning students to Houses. It's perfectly possible to be incredibly intelligent - more than enough to potentially be Sorted into Ravenclaw - but demonstrate something else that ultimately means you would be better suited in another of the four Houses.
Just look at Hermione, who was the smartest student in her year at Hogwarts, but was Sorted into Gryffindor because she demonstrated potential for great bravery, which evidently outweighed her intelligence.
Answer: There are two or three assumptions here that need to be debunked. Firstly, the idea that teachers have to be the smartest - in fact, if the wizarding world is anything like the real world, many of the smartest and brightest may well have shunned teaching for other pursuits. Secondly, the idea that intelligence is inherently a bookish thing, and that it is the most important trait of a teacher (really it's just one of a number that teachers need). And thirdly, the idea that the Houses and their students are all so obviously not alike.
The beauty of the different House traits is that they are all so broad as to mean that any one individual could show characteristics of all 4 of them. Just look at Severus Snape (perhaps one of the more complicated characters in the novels): he is tricky and manipulative, a born Slytherin who deceived Voldemort (and the protagonists). Yet he was also "the bravest wizard I have ever known" (according to Harry) due to his working as a spy against Voldemort (Gryffindor's primary trait). His brilliance at school in potions (as demonstrated by the Half-blood prince book he left) show he had the ingenuity characteristic of a Ravenclaw. And his loyalty to Dumbledore and to his affections for Lily, a loyalty and dedication that lasted right to the end, show he had a bit of Hufflepuff in him too.
And let's not forget the very real possibility that people change, with time. Snape again, may be a good example of this. What House would he have been sorted in, if he was Sorted around the time of the 7th book, instead of as a child?
Answer: According to Pottermore, Professor McGonagall was the premier Transfiguration academic of her time (and before her, we of course have Albus Dumbledore's academic achievements). Both were in Gryffindor, and both - leaving aside all OTHER considerations - were clearly more academically qualified to teach Transfiguration than any competitor, from Ravenclaw or otherwise.
Answer: This question begins with an incorrect assumption "Presumably, anyone who ended up as a Professor must have been pretty smart." This is easily dismissed by reviewing Professor of Divination, Sybill Trelawney, She clearly does not fit in the category "pretty smart".  Another large character/professor may also be identified, as a tough fit for "pretty smart", who I will leave unnamed for those who have not progressed through the entire series.
As "pretty smart" is not a requirement for professorship, a house has little to do with becoming a professor. Not to mention the facts presented in other answers concerning the distribution of Intelligence across houses.
Comment: Hagrid as well, while intelligent, would not really ever be reffered to as "pretty smart" either, but because of his knowledge and understanding of all the mystical creatures made an ideal professor in that area.
Comment: @Monty129 - see " Another large character/professor" :)
Comment: "Large Character". Heh.
Comment: There are quite a few professors who are not particularly smart, depending on your classification of "smart". Snape was not particularly smart because he decided to spy on two of the most dangerous and powerful wizards of all time. Dumbledore was not smart because he relied on teenagers to save the world and didn't ask for help when he put on a cursed ring that started killing him. Quirrell was not smart because he allowed himself to be enthralled by Voldemort while in Transylvania. Binns is not very smart because he didn't notice he literally died and kept on teaching. And so on.
Answer: This is a fairly common assumption about Ravenclaws, borderline a stereotype.
Here's what Pottermore Sorting Analysis has to say about Ravenclaw:

That's the reason Hermione is not a Ravenclaw: She is not open-minded, creative, or tolerant, although she is well-rounded, all Ravenclaw traits.

First of all, just because somebody is from another house doesn't mean they aren't smart (ex: Hermione, and even Harry has relatively good grades through the series.)
Secondly, most professors at Hogwarts don't seem to be overly well rounded (See quote above.) Could you see McGonagall being the potions master and Snape being the Transfiguration teacher? Sure, they can probably do it well, but they likely haven't completely mastered every single subject as much as they have mastered their specialty.
After a thorough search of the JKR website, I found nothing on how a teacher of Hogwarts is qualified, although I suspect that they need only a Outstanding NEWT in the specific subject that they want to be qualified to teach.
Third, certain traits from other houses might overpower Ravenclaw traits. Let's use McGonagall.
According to Pottermore, McGonagall was a Hatstall and So was Flitwick, both between Gryffindor and Ravenclaw. While they both possess all the Ravenclaw and all the Gryffindor traits, McGonagall has a higher ratio of Gryffindor traits and Flitwick had a higher ratio of Ravenclaw traits, although they had both.
Comment: That Pottermore quote seems fairly low-quality retconning, to be frank; Hermione is shown to be quite open-minded and creative throughout the series. No idea where it could be coming from.
Comment: @TylerH Hermione is extremely close-minded, as demonstrated by she refused to hear a word against SPEW and remained convinced that her opinion was the right one.
Comment: The word for that is stubborn, not close-minded. Close-minded would be refusing to consider House Elves as anything but eternal servants who don't deserve any rights.
Comment: Hermione is tolerant but not the most open minded and creative person. If a Ravenclaw read something he/she may detect errors or inconsistencies or things that the author are not saying directly.  Hermione on the other hand are more literal and believes something without doubt or reject something if doesn't fit wit her ideas.

Why aren't all Professors Ravenclaws?


Kitten suddenly won't use litter tray

Question: I have had a kitten for over 3 weeks now he's been perfect at using his litter tray and still using it however he is choosing to poo in another place too I have added another litter tray to the place he keeps going too now I've just found him in a different place weeing not far from the litter tray! It's fresh litter every day I really do not know what to do!
Comment: often when a cat stops using the litterbox it is a sign of pain and possible urinary inffection or other problems when eliminating,so you have to take your cat to the vet if the vet finds your cat to be ok please add this information to your question it will be helpfull in finding the answer.but first take him to the vet.
Answer: Edit: Trond Hansen is right - the problem could be health related, and sometimes it is hard to see it at first since cats like tend to hide their illnesses, so visiting a vet would be the best start before looking for other causes.
Besides urinary infection (which concerns rather urination) there could be other reasons:

the litter tray could be too hard to access - it could be to high, some litter boxes have doors or covers that cats are afraid of..
the litter tray could be to small to be comfortable
the litter tray could be in a place that is not enough intimate, peaceful and the cat could be afraid of doing their things there
the cat may not like the contents of the litter tray - if you use bentonite clay - try to change the size of the grains, usually the smaller grains are preferred
if you use scented litter cats sometimes don't like it, also my cats didn't like the silicate litter
check the surface on which your cat likes to poo, for instance my cat loved to urinate on paper or soft materials lying on the floor, you could try to fill the floor of your litter box with the same material
constipation could be the reason - the cat can blame the litter tray for his problems
Comment: This does not explain why the cat was using litter tray fine earlier
Comment: as i mention in my comment to the question any illness have to be excluded before one starts speculating in other causes.so one need to go to the vet first.
Comment: @sonevol since it is a new cat, in the place where he was from he could have used another type of litter box, so when he saw this one in his new home, he continued to use it, but then it appeared that it is easier, better not to use it and use the floor instead
Answer: You can try two things simultaneously.

Make the litter box more attractive

Try changing the litter type and use trial and error to find right litter. Make sure there is no source of noise nearby.

Make the unwanted sites repelling.

First use good cleaners to completely get rid of earlier poop smell. Then use cat repellents.
Also try making the use of litter boxes rewarding by offering treats when used.

Kitten suddenly won’t use litter tray


Looking for Windows VPS with full admin rights

Question: I am looking for a Windows VPS provider that will allow me to install any applications that I want on it.  I tried the GoDaddy VPS plan, but it wouldn't let me install the windows updates that were required for SQL 2008.  Do I need to go up to full dedicated or is there a provider that can give me full admin control?
Comment: Product and service recommendations, including service recon, are off topic per the updated [FAQ](http://serverfault.com/faq).
Comment: Amazon EC2. Windows 2008 R2 instance. Done.
Answer: Most VPS providers will give you full control (the "P" stands for "Private", it's yours), but if they are based on Virtuozzo then you will not be able to install updates or install device drivers.
You cannot install device drivers because Virtuozzo is not hardware virtualisation, rather it is software virtualisation. If you download a Windows update you run the risk of it breaking the virtualisation.
You cannot install device drivers for the same reason, you might do something funny in the kernel that will break virtualisation. This might not be a problem for you, but if you want to run the VPS as a VPN endpoint with a single hardware NIC (extranet), you will most often end up installing a software NIC as the intranet. My favourite is the Microsoft Loopback Adapter. Despite being signed, Virtuozzo won't run it.
Virtuozzo also does some funny things with VPN/SSL acceleration that prevents the .NET Framework 3.5 from installing and the VPN services for Windows Server 2008 from starting.
You can get around the latter by enabling VPN support on the host but this is a ticket to support. For me, they didn't understand the limitations of their own product and thought I wanted help installing a VPN.
If you can live with the limitations of Virtuozzo (there are a few), I would suggest KickAssVPS. If you want hardware level virtualisation, try Hyper V Mart.
If you look around at WebHostingTalk, Hyper V Mart had some nice lifetime 25% off vouchers floating around.
Hyper V Mart also have a sister site, Database Mart. If you're running the VPS only as a SQL server you may find it cheaper to buy SQL server hosting.
Comment: Where Virtuozzo is concerned, the "P" in "VPS" stands for "Pseudo".
Comment: That's perfect thanks!  I signed up for hyper-v mart, that sounds a lot better then the virtuozzo solutions out there.  I didn't think I was asking for a lot to be able to install SQL Sever 2008, but its good to know what the limitations are.
Answer: Personally, I'm surprised that there are Windows VPS providers that don't give you full control.  I know Anchor Systems give you full control over your Windows VPS (disclaimer: I know this because I work there).  I would imagine that most providers do the same, though; a quick question to the sales department should elicit an appropriate answer.
Comment: Womble man you seem to work everywhere. Didn't you say the other day you worked for a registrar as well?
Comment: ZOMG, a company that does more than one thing!  HOW IS THAT POSSIBLE?!?!?!?!!!?!?!?!?!?!?!!!111!!!!one!!!!eleventy!!!  See https://www.anchor.com.au/domain-name-registration/domain_order.py, specifically, "Anchor is an accredited Australian domain name registrar".  Now, back under your bridge.


how to deal with exposure measurements long before inclusion using cox model

Question: I have a longitudinal data with exposure air pollution and outcome cardiovascular disease. The inclusion starts from 2010 to 2017 and then I followed until 2021. I have measurement of pollution from 1989 to 2021 as continues measures. I use a cox regression, pollution as time-varying covariate and I have left truncation. Then I use age as time (event age at CVD) and consider competing risk of death. Now, my question is how to deal with exposure (pollution) (I have multiple rows as exposure for each individual)? how can I use all information of my exposure and is it an issue that I have the information way back the inclusion?
Comment: @ EdM I appreciate your input.
Comment: The `@` call-out only works if the individual is already in the corresponding thread of comments. I found this anyway.
Comment: I think I can help you with an pretty informative answer but I need you to be patient for some time (maybe days) as I am busy now.
Comment: Your pollution measurements are yearly averages? I mean do you have one air pollution value for each year from 1989 to 2021?
Answer: At each event time, the Cox mode uses the current values of the covariates for all those at risk of the event. That said, it's possible to devise new covariates that represent some aspect of the history of measured covariate values, like a running average perhaps weighted in some way with respect to time.
Your question thus requires you to apply your understanding of the subject matter. Is it today's air pollution that contributes to today's risk of CVD or death? I would guess not, except maybe in extreme circumstances. Is it lifetime exposure to pollution? Exposure over the previous 5 years? Or 10 years? Exposure during youth? If you want to use a Cox regression, you have to convert the history of exposure to some value that is related to today's risk of the event.
This might be better handled with a joint model of exposure and outcomes. I'm not an expert on that. For an introduction, look at these answers from Dimitris Rizopoulos, who has developed tools for such models, or this blog post.
Comment: @Dimitris Rizopoulos Dear Dimitris, your input is highly appreciated as well.
Comment: @user358238 as Dimitris Rizopoulos isn't already involved in this comment chain, using the `@` here won't get his attention. It only works if you comment directly on one of his questions or answers, or if he has already commented on the question or answer that you are addressing.
Answer: The PhD I am currently working on focuses specifically on this topic so I think I can give you some good tips.
Important point:

If your outcome is incidence of cardiovascular diseases,
then you do not need to define competing risks for death! It will
be just a time-dependent Cox Proportional Hazard model (Cox PH). This is what you will also find in most of the literature.

Next...
If your air pollution data is yearly averages corresponding to each year between 1989 and 2021, then defining a time-varying Cox PH model will be quite simple.
Very recently me and colleagues published a paper (open access) that I will use as reference to avoid creating multiple tables in the answer.

Your "basic" cohort and outcome tables will need to look like Table 1a and 1b (you don't need Table 1c as you already have your exposure table). In Table 1a you have the basic cohort information, while in Table 1b you have the outcome.  In Table 1a the "Last follow-up date" refers to the date your observation leaves the follow-up, that is due to censoring (observation , death or administrative end of the follow-up, which in your case is 31/12/2021).
Also, I assume your exposure data (exposuredata dataset) looks more or less like this:

ID
year
exposure_value

1
1989
...

1
1990
...

Now you need to merge Table 1a and 1b so that you still only have one row per subject. In some way, you need to select which outcome you are exactly interested in, in terms of ICD. This merge with give you a table like this (replace the ... with your dates):

Table 2:

ID
Enrolment date
Last follow-up date
ICD
outcome date

1
...
...
I25.1
...

From Table 2 you need to define a new date column (new_exitdate) which will have values equal to either "Last to follow-up date" or "outcome date", whichever comes first. Also, you need to define an indicator for event (event): 1 if the observation has the event (cardiovascular disease) during the follow-up or 0 if he/she doesn't.
Eventually, you will only need to have the following columns: ID, "enterdate" (which is equal to "Enrolment date"),"new_exitdate" and "event".

Now you have Table 2 ready to be split so we can link the exposure to it! When I worked on this stuff the first time, I got my ispiration from this working example (particularly model B).
To do the time splitting in R you can use a simple code:
 library(lubridate);library(survival)
 low<- year(min(table2$enterdate)); up<- year(max(table2$new_exitdata))
 cutyr <- low:up
 splitdata <- survSplit(Surv(enterdate, new_exitdate, event) ~., table2, cut=cutyr)

Now you have your splitted data which includes multiple rows per observation, each of which corresponds to an ID-year pair.

You can simply merge splitdata with your exposure data :) by ID and year!
ATTENTION: be careful in this moment because you can merge your exposure using the same year (e.g. assign 2010 exposure to 2010 time) but you can also do a different assignment, for instance you can assign the exposure of the previous year (e.g. assign 2009 exposure to 2010 time). You need to run some sensivity analyses to see how the effect changes when you change assignment. Remember: in no way you can assign future exposure to a time. For instance, if the time is 2010 you cannot assign 2011 exposure as it makes not sense!

Considering that you super long exposure data before the start of the study, you might be interested in using different exposure averages instead of single years. For instance, you want to assign 5-year or 10-year exposure average. Then you just need to define a 5-year average by row. For example for time 2010 you can assign averages of values from 2006 to 2010. There are some nice papers that looked how risk estimates change when you use averages for different exposure time frame (e.g. here)
You can create averages across multiple years in R (with data.table) with something like this:
exposuredata<- exposuredata[, 5yrave:=rowMeans(Reduce(cbind, shift(exposure_value, 0:5))), by=ID]
To understand this part I recommend to study Figure 3 of the paper, which corresponds to the Definition of individual summaries for epidemiological studies (Step 3) section.

You can run your cox model!
The code will be something like this:

model<-coxph(Surv(enterdate,new_exitdate, event) ~ exposure + covariates, data)
I do not recommend using age as main time scale as you wish to do, rather I would control for it in the model using a spline term maybe. (something like ns(age, df=5)). However, in your splitdata dataset age needs to be calculated as difference between the birthdate and new_exitdata at each time point. There are other ways to control for it, such as stratifying by year of birth, but just ask if you need!
Also, remember that the selection of the covariate must relatively careful. Because I imagine your exposure is from outdoor predictions, then using area-level covariates (such as neighborhood deprivation) is recommded to account for confounding.
I think this is enough for now and I tried not too specific, but if you need details or clarifications on sometihng, ask and I can edit the answer.
Also, there might be a few mistakes in the text, please just gently point them out. Cheers


Do photons have a duration?

Question: When light is emitted (or received) one photon at a time, what is the duration of each pulse? Is it related to the wavelength? Is it possible to create a laser pulse (or a radio wave) shorter than the wavelength (period of oscillations)?
Comment: Perhaps interesting: [Existence of monochromatic pulses](https://physics.stackexchange.com/a/312113/46708)
Answer: This depends on the light source, obviously - some sources produce longer pulses and other sources produce shorter pulses. However, the general rule is that the pulse duration is limited not by the wavelength but by the bandwidth of the pulse, that is, the lenfth $\Delta \omega$ of the interval of frequencies that contribute significantly to the pulse's spectrum. Generally speaking, the pulse duration $\Delta \tau$ is constrained by the bandwidth via
$$
\Delta \tau \ \Delta \omega \gtrsim1,
$$
which is essentially the Heisenberg uncertainty principle minus all the quantum mechanics.
In general, if you want to make a pulse with a single wavelength, then this requires you to have an infinitely long pulse. If you want to have a pulse that's shorter than the carrier wavelength $\omega_0$, then the bandwidth $\Delta \omega$ will be larger than $\omega_0$ and you will have a broad, multi-octave spectrum where your original $\omega_0$ might still be relevant to describe the finer details of the spectrum but will be essentially impossible to infer from a qualitative look at the latter.
For more details, see my answer to the closely related question How can a wavelength be defined for a laser where a photon's travel distance over a pulse duration is less than a wavelength?.
Comment: Thank you for the answer and the link, +1 to both for being helpful and informative. Essentially you answer "no" to the second part of my question, because the broader spectrum would always contain wavelengths shorter than the pulse duration. Understood. My main question though is the duration of a single photon. The uncertainty principle gives one full oscillation for virtual photons (this has a deep physical meaning although unrelated here). Are you saying that the duration of a real photon is defined by the width of the spectral line (bandwidth) though the uncertainty principle?
Comment: Photons are simply excitations of some underlying classical mode. That mode can be monochromatic but it doesn't need to be, and unless the mode lasts for infinite time (or longer than your experiment, in which case that idealization is appropriate) then the mode will be a wavepacket exactly as described here. The only difference between a classical pulse and a single-photon state is the counting statistics as brought out by e.g. Hong-Ou-Mandel interference. The same is true for a sequence of single-photon pulses, if that's what you meant by 'one photon at a time'.

Do photons have a duration?