Best practices and anti-patterns in creating indexes in SQL Server?

Question: What are the things that you would consider when defining indexes, clustered and non-clustered, for SQL Server? Are there any anti-patterns that DB newbies should be aware of?  Please explain the "Why" or provide references if possible.
Answer: An index is basically a "cheat sheet". It allows the DBMS to find a particular value (or range of values) on disk without having to scan the whole table. Generally, you pay a little bit of penalty on INSERT / UPDATE / DELETE by having an index, but rarely so much that it's a bottleneck on its own. A good DBMS will only use indexes when they help query performance, so there aren't a lot of hugely negative anti-patterns here; it doesn't usually hurt you very much if you have extra indexes (unless you're talking about very highly transactional tables). That said, careful indexing across the board will help you make sure that the really important ones are there, and the best way to discover that is by profiling your application.
The key to understanding when and when not to use indexes is to get a grasp on what they're really doing under the covers. In a nutshell, you want them when the selectivity of the index is high (i.e. the number of different possible values is high compared to the size of the relation). So, for example, if you have a table with 10,000 rows, and you have a column called "color" on that table that's either "red" or "blue", it doesn't help much to have an index, because the DBMS will probably have to load most of the pages into memory anyway (assuming a random distribution). Conversely, an index on the primary key id of a table (which is nearly always automatically added) will make lookups in that table lightening fast - on the order of log(n) - because a very small number of nodes in the tree have to be examined to find the page on disk where the record resides.
Indexes in most modern database systems are implemented with a B+ tree, which is a very cool variant of B-Trees that's optimized for slow secondary storage (disks instead of memory). You can get a good introduction to their use and functionality from Database Systems: The Complete Book.
Answer: Don't test indexes or optimize queries without a database filled with representative data.
The database will generally ignore any index on a boolean field. It will ignore it as part of a composite index. (However, see "filtered index" in SQL Server 2008.)
For composite indexes, where all values will be provided, enumerate them in reverse order by cardinality (or arity, or how many distinct values there are in the data.)
Don't assume anything. Test everything.
You only have one clustered index. Don't waste it on a unique index unless you're sure you will really need to almost always pull rows sequenced on that column. You want to use it for cases where multiples of adjacent rows are often fetched.
A "covering" index is one that, by itself, contains all the fields required to resolve a select. Remember that an index that "almost" covers isn't good enough in most critical cases.
Most of what you read in online blogs about designing indexes is either wrong, or highly qualified and not applicable in your case, or badly calibrated as to benefit and cost.
Comment: This: "...one clustered index. Don't waste it on a unique index...." is one of my current conundrums.  If you don't choose an ever increasing CX (identity for example), but use date or a FK string, will you run into problems if rows are inserted into large tables and by virtue of the CX these rows must live in front of existing rows?  Take a datetime CX and you insert a row with a value 10 years prior to today and you have 1 million rows already in there from say 20 years ago.  Is that shuffling 500K rows around?  I'm examining my data model and trying to decide a question similar to this now.
Comment: ... I should add (to my comment above) that this table is highly active table in an OLTP application: it's getting hammered with updates along with the usual selects* and inserts going on.  We're considering switching the CX to an identity to speed up inserts and updates (and adding a non-clustered index on the current column that is the CX) but the conflicting best practices have been my conundrum here.  *It's NOT a data warehouse, although it does regularly get hit by Crystal Reports.  I am starting to think there should be a best practice for OLTP vs. DW.
Answer: The Blunderbus - An indexing anti-pattern I have been guilty of in the past.  Putting an index or variations of the same index on columns in a table without having looked at an explain plan or really understanding how the optimizer is working.
Answer: Here's a couple more indexing anti-patterns that I have seen or have been guilty of:
Blanket coverage - Placing indexes on tables with little or no growth and a (very) low rowcount.  This is counterproductive as the index lookup can take longer than a table scan.
Industrial Strength Indexing - Placing an index on a primary key column.  I've been asked to do this to "speed up" a query.
Comment: Bear in mind that the DBMS may require an index on even a minimal and static table in order to enforce a UNIQUE (or PRIMARY KEY) constraint.  You can argue that the DBMS is faulty - but it lays down the rules, sometimes.
Comment: To be painfully clear, in most database systems any index you put on the primary key is redundant by definition. Another equally dumb index is a composite index with the primary key first.
Answer: Consider reading Relational Database Index Design and the Optimizers.  It will give you a lot of ideas and the reasons why they are good.
Answer: I see a pattern of people just using the Database Engine Tuning Advisor and thinking that it is somehow smart enough to suggest the most optimal indexes and stats. That is an pattern you should avoid.
Instead look at your query plan outputs before deciding how to approach optimization. They can tell you lots of useful information about how to best approach a query. Often times people throw indexes on all kinds of fields because they think it is the right thing to do, ignoring that in some cases any gain they might achieve could be overall negated by the impact of having the index itself (lots of indexes on a table can slow down inserts and updates).
Pick up a book on T-SQL Querying by Itzik Ben-Gan (MS Press) the next time you are in a bookstore (They will have it). Read the first 3 chapters and it will cover how the query process works inside SQL Server - as far as your work with this particular technology they may prove to be the most important 3 chapters you will ever read.
Answer: One thing that I have found that people forget to do when indexing is index the foreign key. Primary key indexes are built automatically (I'm speaking SQL Server her, other databases may vary) but foreign keys are not. But many people assume they are (presumably the same people who presume triggers will act on only one record at a time). Since they are almost always involved in joins (Why else would you have one?), they need to be indexed most of the time (Exception would be a really small table).
I would define my favorite indexing anti-Pattern as:
Why Are My queries so Slow - the condition that happens when non database people design large databases and don't even know enough to put any indexes on it. Typical symptom is found on a message board with the person asking why it takes 40 minutes to do a simple query against their 50 million record table. Likely this antipattern will occur with alot of other database design antipatterns as someone not even familiar with indexing is unlikely to have designed an efficient or effective database structure.
Answer: Putting a clustered index on a GUID column is mostly not a good idea.
A clustered index defines the physical order of how the data is stored.  Therefore, it is best to put a clustered index on a column which increments or decrements, and which is unique.
(If the Clustered index is not unique, SQL Server will add the PK internally to the clustered index).
A Guid is a random value (unless you make sure that you use sequential guid's), so this means that every time you insert or update a guid in a column that is part of a clustered index, Sql Server will have to move records around in the data pages.
Also, try to put a clustered index on columns that you often use to perform 'range' searches.


Painted Texture does not appear when rendered

Question: I painted this Amazon figure after creating an image called 'metallic'. I painted this material and the figure looks the way I want. However, none of this paint shows up when I render it. I realize there's another image called _17054_Amazon which didn't get painted.

I'm new to Blender and I'm this is a noob mistake. I'm confused there are two images, but one figure. Can I replace image _17054_Amazon with the iamge 'metallic'?
Comment: how does your Shader Editor look like? You need to plug an Image Texture node (with the image loaded) into a Diffuse
Answer: are the materials set correctly?
did you save the image? last version that I used only renders the saved file.
Comment: I agree with this troubleshoot. Save the file, then go back into the shader editor and ensure the correct image file is plugged into the shader. If that doesn't work, send us a picture of what it looks like rendered.


Blockchain based Identity Management System

Question: I want to start Identity management system using hyperledger but don't know how to take a start,either from hyperledger-composer or hyplerledger-fabric.
Answer: If you are going to achieve this with Composer you should work through the tutorials to gain some background information, then look at the various sample models in Composer, and the sample applications.
For Fabric there are tutorials for background information.
There are also many links on youtube.
Answer: Check out Hyperledger Indy for identity related blockchain implementation.
Comment: definitely... it would be unwise to try to develop a new bespoke identity management system. There is already a project designed just for that.
Comment: I don't think it would be unwise, as on one technology there can be same sort of product but different flavors or approach. Anyways specially regarding your question, both composer and fabric has their own advantages. On one hand with composer you start development pretty quickly but it's not development ready as of now, while with fabric you can have more control over the data and it's production ready. So at first try both at basic level and once you get a good understanding of both, you can choose the right path for your implementation, depending upon the requirements.
Comment: Thanks for giving me a direction.


Google Sketchup & 3D printer

Question: Does anyone have experience using Google (now Trimble) Sketchup with a 3D printer.  I have seen some blog posts that suggest there are some design steps and file format conversions before the design can be used with a 3D printer.
Answer: I build myself a Mendel 3D printer a while ago (I wrote a blog about it) and could not find an easy solution to print out my stuff. I stuffed away the project for a while and just recently I pulled it out again.
I found a software called Repetier that works as a charm. Printing objects from SketchUp is now really easy, no "extra" conversion steps in between.
You need to install an STL Exporter to SketchUp. I found this one from Flight Of Ideas that says SVG exporter, but it can export STL as well. After the plugin has been installed you get a new tool "Export SVG or STL". It will export all objects that are selected or everything if nothing is selected.
If you prefer another STL export plugin, feel free to try them out until you find one that works well with you.
From Repetier, just open the STL file and hit the slice button. Repetier does the slicing for you and supports a few 3D printers, CNC milling and drill.
You may fiddle a bit with the slice configurations, but it took me only a few hours to get things darn good.

Google Sketchup & 3D printer


Export list of sites from a Google Custom Search Engine

Question: I have a public Google Custom Search Engine with over 700 sites in its index. I can't seem to find a simple way to export the sites. What are my options?
Comment: I'm voting to close this question because this question is obsolete. The product has changed its name it has several changes. The current name is Programmable Search Engine. While the URL of the link is redirected to the new URL the question doesn't include enough details about the user context to know if it will stay the same. Ref. [Custom Search Engine is now Programmable Search Engine](https://programmablesearchengine.googleblog.com/2020/04/custom-search-engine-is-now_30.html).
Comment: Related [What to do with \[*search*\]? Review of tag naming practices in Web Applications SE for tags using "search"](https://webapps.meta.stackexchange.com/q/5144/88163)
Answer: Now there is a feature to download the site list. Here are the steps I used:

Go to your custom search engine
Click on Advanced tab under Control Panel. The url looks something like http://www.google.com/cse/panel/advanced?.....
Look for Download Annotations in the main pane and download in your preferred format
Comment: This answer is obsolete.
Answer: There doesn't appear a "nice" way of doing this.  There are some instructions below, which seem like a lot of work just to get a list of sites, which are taken from this Google Support Forum Article.

Go to the control panel of one of your CSEs.  On the "Basics" page of the control panel, note your "Search engine unique ID" (a.k.a. 'CX value').  The search engine ID consists of a 21-character numeric code followed by a colon and an 11-character suffix.
Go to the "Advanced" page of the control panel.  Note the inclusion and exclusion label names mentioned in the text that says:  "... Label sites with [...] if you want to include them ...." and "... Label sites with [...] if you want to exclude them ...."  (Note: The CSE might have more than one inclusion label name.)
Open a separate browser window or tab.  Copy and paste the URL template shown below into your browser's location bar (URL box) and make these substitutions:
In place of "XXXXXXXXXXXXXXXXXXXXX", substitute the 21-character code from the first part of your CSE ID.  In place of "YYYYYYYYYYY", substitute the 11-character suffix of your CSE ID.  In place of "LABELNAME" substitute one label name.
http://www.google.com/cse/api/XXXXXXXXXXXXXXXXXXXXX/annotations/YYYYYYYYYYY?label=LABELNAME&num=5000&start=0&feed=0&output=tsv
(Use copy-and-paste to make the substitutions.  Check the result carefully to make sure that the substitutions are complete and correct, and that no extra characters or blank spaces have been added.)
Visit the resulting URL, and you should receive the TSV-formatted annotations corresponding to the specified label for the specified CSE.

Note:  If you encounter problems in Excel when opening the .tsv file:  Rename the file, changing the .tsv extension to .txt, and then open in Excel.)
Comment: Yeah, I was afraid of that.
Answer: In case you want to export 'excluded sites' from within advanced options. There doesn't look to be an official way of doing it. If you open Chrome dev tools on the network tab, and click the next page of excluded sites, you can see the XHR request that is fired.
Copy the XHR link it should look something like:
<code>https://cse.google.com/cse/api/XXXXXXXXXXXXXXXXXXXXX/annotations/XXXXXXXXX?start=10&num=10&label=_cse_exclude_XXXXXXX
</code>
Change start to 0 and num to however many you have (or want to export) and it should download an XML document containing how many records you have asked for.


How to add or use 3 pivot o center on rotation

Question: Hello as you seen in the photo below, I want to make the animation of the scale.I want to make  the cube as a active  Rigid boby  & when i press play animation the cube should move down for gravity and the plate of the scale is A passive rigid body so that the cube will be stop on it and in that moment the scale should move becoz of the weight of the cube and the motion should have point of rotation those called center ,pivot1  ,pivot2 .Is it possible to do so ,or Have to make  the animation of the wight scale moving using the location transformation ?
Answer: It's possible to do what you want.  The plate should not be a passive body though.
Start with the scale.  We will need four rigid bodies: the two plates and the arm, all of which move, and an anchor for the arm, so that it will rotate rather than fall.  We will need three rigid body constraints, one for each pivot point:

The rigid body constraints are point-type, as demonstrated in the properties viewport.  Each joins a pair of rigid bodies and is located at the pivot point.  The origins of rigid bodies are used as their center of gravity, and so here, the origins need to be placed carefully, particularly the origin of the crossarm, which needs to be located at the same position as the "center" joint.
The anchoring rigid body should be either passive or animated.  With its placement as I have here, I need to leave the default "disable collisions" on the "center" rigid body constraint.  All other rigid bodies should be the default "dynamic".
To work like a scale, the "pivot" rigid body constraints need to be directly above their corresponding plates, and equal distances from "center".  I have changed the mass of one of the plates here to demonstrate its effect.
You may wish to replace "center" joint with a generic spring type constraint in order to create some damping and resistance to the rotation, which will otherwise rotate the crossarm to the vertical with any difference in weight.
If we want to drop a cube on top of the plate, we can:

We simply create a new rigid body, without any constraints, and drop it onto the plate.  I'm showing the original, "rest" state of the system to the left.
Comment: Thank you very much .I wish you shared the bleder file also, hope you don't mind. Thank you  once again.
Comment: Sorry, I don't think I bothered saving it.  If you're having problems with implementation, it would be best to mention exactly what you're trying and what's going wrong in the question.
Comment: From What I understood from your suggetions , I made this  in the link (https://github.com/kebab03/WeightScale)  please tell me what should me corrected?Will be waiting for your answer.
Comment: Your rigid body constraints need to link your rigid body objects together, not your other RB constraints.
Comment: Kindly make the changes on my model and then  share the modified file or the screenshot of that .Thank you for your kindness.


Get url for the page being opened next in window.onunload event

Question: Is there a way get the location for page being opened next in the window.onunload event.
Best Regards,
Keshav
Answer: No! That would be a security problem. Imagine someone navigating from a porn site to a banking site. The other way round (with the HTTP Referrer header) is already somewhat a headache. Firefox allows to suppress the referrer:
Enter about:config in the address bar
Search for referer (sic)
Set network.http.sendRefererHeader to 0
(Courtesy to http://cafe.elharo.com/privacy/privacy-tip-3-block-referer-headers-in-firefox/)
Answer: The current page cannot and should not know where the user wants to go next (via address bar or bookmarks) (as @nalply said).
If your situation is you want to know which link that the use clicked on your page, then you can do this with javascript. Have a temporary variable that is populated with the URL everytime the user clicks on a link on your page. Then in window.onunload, you can use this.
If this is not your situation, can you tell your specific requirement on why you want to this? Perhaps you might get better solutions if you tell what you are trying to acheive.


Need clearing up on vector decomposition in motion physics

Question: I've been pursuing physics on my own, and I need something cleared up. Say I have two arbitrary objects, I have their velocities, I know when the collide, I have their normal vectors, etc. I know where a force is applied, how much, which direction(lever arm, etc). I THINK that what I'm trying to do is vector decomposition. I know that torque is the force applied perpendicular to the normal(tangent?), and that linear force is the force applied directly through the center of mass. I believe I intuitively understand these interactions, but I'm having an issue... what is the mass with the splitting of the forces? How 'much' goes through the center of mass, and how much is perpendicular, or torque? I feel like trigonometry may be a simple answer, but I'm unsure of the implementation. My variables I have are the force vector(x, y coordinates scaled to magnitude), and vector(distance vector?) which represents it's offset position from the center of mass. I'm not asking how do I calculate the torque on the CM, but how do I simply determine the force that is perpendicular, not yet crossed by the distance vector(?), and how much of the force goes through the CM, and converts into linear velocity? P.S. This is in a 2D coordinate plane, in a computer simulation I'm making. Labeled as homework as I want to intuitively understand, not actually assigned by a school.
Answer: Here's a picture of a rigid object. The center of mass (CM) is labeled. The arrow represents a force being exerted on the surface of the object.

To figure out the component of the force parallel and perpendicular to the surface, first draw the vector from the center of mass to the point of application of the force.

Now draw the two vectors with their tails next to each other. Label the angle between them $\theta$.

At this point it's trigonometry. Use $\cos\theta$ and $\sin\theta$ to extract the components of $\vec{F}$ that are parallel or perpendicular to $\vec{r}$. Be careful about signs. I would just take the absolute value and add the sign in manually if you care about it.
As a side note, I want to stress that I'm not aware of any time in physics that the component of a force that's parallel to $\vec{r}$ is useful. The perpendicular component can certainly be handy when dealing with torque, but I'm not sure what the parallel component is used for. In particular, it is not what you need to calculate the acceleration of the center of mass of the object. For that, you need the entire force $\vec{F}$. See my other answer for more info.
Comment: Wait, hold on a second, are you saying that linear force is the same as force applied? If so, that kind of makes sense of what your last answer said, but doesn't that violate some laws of conservation of momentum and such?
Comment: I've not heard the term "linear force" before. But the force applied $\vec{F}$ is what you need to figure out the acceleration of the center of mass of an object. You need tho whole thing, not any particular component of the force. The perpendicular component of the force, though, is useful for *angular* acceleration.
Comment: .. no, the above wouldn't violate any conservation laws. This could be another question if you phrase it well.
Comment: (hopefully)last question, so I have the angle of the two vectors, how do you exactly... multiply the force, or a vector in general, by an angle? I tried googling, didn't find anything but dot products, which doesn't seem to fit the bill of cross products, unless you do the cross first and...? Can you explain the process of the vector math(again, more calculus, sorry), behind this?
Comment: You're trying to find the component of a vector. Look up "component decomposition of vectors" or something similar.
Answer: There are a lot of ideas in your question above. But I think I see what your major concern is. Here is my rephrasing of what I believe you are asking:

When a rigid object (like a bar or disk, not a point-particle) is subjected to a force $\vec{F}$ how much of this force goes into the linear acceleration of the center of mass, and how much goes into torque (causing angular acceleration)?

The short answer is that a force $\vec{F}$ can fully affect both the center-of-mass acceleration and the angular acceleration of an object without diminishing its effect on either.
The longer answer is that Newton's second law (N2L for short),
$$\vec{F}_\text{net}=m\vec{a},\tag{common form of N2L}$$
is more amazing than it seems. It doesn't matter where or how a given force or forces are exerted on the object; you sum them up, and you can calculate the center-of-mass (CM) acceleration of the object. I personally like the more explicit form
$$\vec{F}_\text{net}=m\vec{a}_\text{CM},\tag{more explicit form of N2L}$$
which reminds me which acceleration N2L refers to. There are indeed consequences of this that may seem counterintuitive. For example, applying a force to the edge of a rigid object will affect the CM acceleration just as much as if the force were applied directly inline with the CM.
Any force $\vec{F}$ on a rigid object will also cause a torque $\vec{\tau}=\vec{r}\times\vec{F}.$ (The cross product in this equation has, built into it, your idea of how far off the CM the torque is applied.) The usual view is that torques cause angular acceleration (or put in a more precise term, it changes the angular momentum $\vec{L}$:
$$\vec{\tau}_\text{net}=\vec{r}_1\times\vec{F}_1+\vec{r}_2\times\vec{F}_2+\cdots=I\vec{\alpha}.\tag{for rigid objects}.$$
(There are more precise forms of the above equation, but this will suffice.) To properly use this rotational analog of Newton's second law, you have to use the full force(s) $\vec{F}$.
The big idea here is that that the full force $\vec{F}$ goes into calculating both the linear acceleration $\vec{a}_\text{CM}$ and the angular acceleration $\vec{\alpha}$.
I do want to comment that one can often interpret $\left|\vec{r}\times\vec{F}\right|=rF\sin\theta=rF_\perp$ as involving only the component of the force that is perpendicular ($\perp$ means perpendicular) to the "lever arm", but this is only an interpretation. (One could also interpret it as $r_\perp F$.) This does not diminish the force's affect on the CM acceleration.
Comment: I'm having trouble following you, although what I think your trying to say is that the force in the torque and angular acceleration is.. the same variable? I don't see how that works with the law of conservation of momentum. What is the upside-down T figure mean? What is 'N2L'? My question is how do you get the component of the force that is perpendicular to the lever arm, and the component that passes through the center of mass?
Comment: I edited to explain N2L and $\perp$. As for calculating the component of the force perpendicular to lever arm, it involves trigonometry.  For the component "through" the CM, I would ask *why*, since this isn't needed for the linear CM acceleration (as your question seems to imply). Is my boxed "question" at the top not related at all to what you want? Does [this link](http://physics.bu.edu/~duffy/py105/Torque.html) help?
Comment: Well, it kind of is, but not entirely. I figured that it was some kind of trig, and I found at some discrete place on google that it was a sin of of an angle and a cosine of an angle, which kind of doesn't tell me much. Trig of what? Magnitudes? How do you get direction from that? I see in your answer that you show the equation, where rF sin 0, but that doesn't make any sense. I'm not exactly a mathematician, so I'm guessing that it means lever cross force ... ? I know trig, not really with vectors and trig. And, would the CM be F cos 0? My issue is I'm having a hard time visualizing it.
Comment: That link(which as I tend to do, overlooked), seems to help. Not entirely sure if I understand it correctly. The order of operations here seem flexed. Where do cross-products fit into this? I imagine that it is r x (F sin 0), but that is multiplying by a scalar which you can't cross, I typed out another 300 or so characters of how I think it could go, and it's more of a mathematical question, but it doesn't really make any sense.


Is there any way to jump to the ground floor?

Question: When you tap at the top of the screen, you jump to the very top floor.
Is there an equivalent to jump to the ground floor (i.e. not the quick button for the elevator, but something which is there all the time)?
Answer: Sadly, no there is not.  The only method anyone has come up with is to leave Mos Espa Cafe or something close to the bottom level empty of bitizens and use the ! notifier as a quick way down.  This is not desirable on several levels, though.  You lose revenue, and it makes the function of the ! notifier not reliable for other levels.
Comment: Thanks, that is pretty clever but the disadvantages outweigh the benefit. Is there anywhere which we can submit to the developers to request this feature?
Comment: Yes. email@example.com
Comment: Why not move Panna City Medicines for this?  This one would typically be empty more often, as Bitizens don't have this for their dream job.
Comment: @Tim Perfectly viable option.  PCM doesn't carry much stock to begin with.  Yet, the function of the ! marker is still significantly diminished.


How to continue playing Godus on different Computer?

Question: I started playing Godus on my PC. Now I want to continue playing the same game on my Laptop. Is there a way to achieve this? Is the current state saved to Steam Cloud? Is there a file on the disk I can copy?
Answer: After some investigation I have found that the Godus is not supported on the Steam Cloud.
But, you can still manually find the save file from your steam folder.
In the game library on Steam, right click on Godus in the list of games in the sidebar. Select "Properties" and then click the "Local Files" tab in the "Godus - Properties" window. Click "Browse local files..."
You should see a "windows" folder or an equivalent folder on the Mac version. Open that folder. The save files are the following files in that folder: (Note: on OSX 10.7.5 the files are inside the user's godus application support folder and not inside any of the steam folders: "~/Library/Application Support/godus/")

state.back
state.bin
And possibly a number of files like statebackup0001.bin
You will also need to look in the folder named something like prf110000100a1858b which is where the saves are kept.

By transfering these files to your second PC, you should be able to pick up where you left off.
Of course if you do not like the manual proccess you can always use Dropbox to store the saved directory, replacing the original directories on both PCs with Symbolic Links.
Comment: Cool.I will try and accept oft course as soon as verified. THX.
Comment: All files were only in the prf1100... folder. But worked without any issues.
Comment: Here are some info: http://godus.gamepedia.com/How_to_start_over
Comment: In other hand, I can not migrate my saves from Steam to Android. (I tried to copy the `prf1*` directory from Local files of Steam to `/data/data/com.mobage.ww.a1912.Godus_Android/files/prf1`, but it droped my saves)


How to make initial trajectory for incident A2 molecule on any surface?

Question: I want to write code to simulate the impingement of any molecule on a surface at different (r, theta, and phi) angles in XYZ format.
Comment: Could you be more specific in you question? That might make it more clear for others to provide you an answer
Comment: to explore surface dynamics by simulating the dissociation of H2 molecules on a Pt surface. To initiate the study, I need to generate initial molecular geometries (trajectories) with varying angles (theta, phi) and distances between H2 atoms so, how to make initial trajectories (via python code or via ASE) for VASP?
Answer: I don't totally understand what OP is trying to do, but to my understanding, he/she is trying to make .xyz files for of a molecule moving on the surface of some structure, where its constituent atoms are moving away from each other along with rotation in their bond.
The logic behind that would be to either read or build the required surface model, define a range of values for (theta, phi), and a range for the distances between the atoms of the molecule. We then create the molecule with some initial configuration and iterate over the range of corresponding values we have already defined so that we can vary the distances and rotations, we shall save those configurations accordingly along with the surface we have already built or read in the first steps. Last step, write those configurations as xyz files.
The following is an example of my idea, which might be a good starting point for what OP is willing to achieve. The values in the script are random so you need to tweak according to your situation.
<code>import numpy as np
from ase import Atoms, Atom
from ase.build import fcc111, molecule
from ase.io import write
# Supposed we have Pt surface
a = 3.92  # Check the correct value of Pt lattice constant in Å
surface = fcc111('Pt', a=a, size=(2, 2, 4), vacuum=10.0, periodic=True)# randomly chosen Pt surface, check for your case or read the surface file if you aiready have one
theta_range = np.linspace(0, np.pi, num=20)  # Range of theta angles (0 to pi), num can change the sampling inside the chosen range
phi_range = np.linspace(0, 2*np.pi, num=40)  # Range of phi angles (0 to 2*pi), same thing about num
distance_range = np.linspace(0.5, 1, num=10)  # Range of distances (value1 to value2 Å) between the H atoms
# This list is used to store the final xyz files
configurations = []
# Initial trajectories
for theta in theta_range:
    for phi in phi_range:
        for distance in distance_range:
            # Generate H2 molecule with specific distance and orientation
            h2 = molecule('H2')
            h2.set_distance(0, 1, distance)
            h2.rotate(theta, 'y')
            h2.rotate(phi, 'z')
            # Get the positions of H2 atoms relative to Pt surface
            h2_positions = h2.positions + [0.5, 0.5, 2.0 + distance]
            combined_system = surface.copy()
            combined_system.extend(h2)
            combined_system.positions[-2:] = h2_positions
            configurations.append(combined_system)
# write the final structures XYZ files
for i, configuration in enumerate(configurations):
    filename = f'configuration_{i}.xyz'
    write(filename, configuration, format='xyz')
</code>
Comment: Thank you @Jaafar Mehrez


fast distance metric between a new data entry and available clusters of data

Question: Assume we divide a large data set D into m different partitions of data in a distributed learning case, using K-means clustering. We do the training in the clusters and they are local experts. Now, we have some new test points that we want to assign to the partitions and obtain the predictions. An initial guess is we can find the distance between new points the centroids of the clusters which may take time in large data sets. I want to know if there is any faster method that works faster when the number of the new points increases? Also, except distance metrics, it there any similarity-based measures that can be used to make a connection between new entries and available partitions' centroids?
Comment: It is a bit strange to start asking what measure is faster to compute, without first deciding on what can conceptually serve a proximity between a cluster and a point. Will that be a distance to centroid? medoid? nearest neighbour? etc.
Comment: @ttnphns You are right. I updated the question. Assume K-means clustering has been used to divide a data set into some partitions. Then, the initial solution for the question is we can find the distance between new points and the centroids of the clusters. But in this question, I want to know is there any effienct substitute for that?
Comment: Computing a distance between a point and a centroid is fast. Centroid is a fixed location in space, a "point" on its own, so as soon as you've got a cluster, you can compute the coordinates of the centroid. Then, when needed, you compute the distance from every newcomer data points to this "point".
Comment: Fun question (+1). I think we can turn this task to its head and get a very elegant solution via classification. Please see my answer below.
Answer: Don't cluster. Classify.
I have expanded on this topic here How to assign new data to an existing clustering but to give some more details why this allows us to have a "fast approximate distance metric".
Especially if we use a classifier $C$ based on trees (e.g. random forests, gradient boosting, etc.) what we would have learned through the training of it will be a recursive partitioning of our sample space (through piece-wise flat functions) such that it aligns as closely as possible with the class/cluster labels. This recursive partitioning is exactly what will allow us now to compute a fast approximate distance from the cluster centres/exemplars in the form of our class/cluster membership probabilities. (where for example, a high probability of being in class $A$ suggest someone "very close" to a typical class/cluster $A$ instance.
To that extent, this "trick" of recursive partitioning our sample space via a tree-based classifier is exactly the "trick" we use when calculating approximate distances between points from a large high-dimensional sample via ball trees.
(Do note though that, unlike ball trees we don't have to use a tree-based classifier, I used it as an example, any classifier with probabilistic outputs will do.)
Comment: I didn't understand your first sentence. The speach, as I understand, is about assignment, not clustering. Given some "small" number of new data cases, we simply assign them to the nearest clusters, we don't recalculate clusters (e.g., their centroids) after every assignment or even all the "small" number of assignments is done.
Comment: (cont.) You are suggesting to perform an additional analytic procedure after the initial clustering, classification, to derive another rule of assignment of cases than the "distance to centroid" rule having come from the clustering procedure. The another rule can be potentially better and more sophisticated than it, but how can it speed up the whole job? Can you explain how adding a classification analysis will make the whole project of new assignments faster in the end. This might be so, only that you haven't explained it in more detail.
Comment: No worries, the first sentence is a bit tongue-in-cheek that if you can't classify based on your clustering then probably it is not really useful. :) (And I never suggested we recalculated clusters...) For the main part: If we resort to "simply assign them to the nearest clusters" we don't have an idea about how the metric is interpreted between clusters/classes, probability is much more interpretable. Also, assuming we do brute force calculations of (Euclidean) distances that can be slower than using recursive partitioning (that's why the link to the ball trees in my answer).


How to wait for all button click functions to complete

Question: My program runs a function upon a button press. Inside, I perform an action and then show a progress dialog spinner. Now I would like to wait until I get a "response", so I acquire a semaphore for T amount of time.
I thought that the function will execute and a progress bar will show up before I try to acquire the semaphore, but instead the program ends up in the semaphore acquire and sleeps, blocking the other functions(probably). The progress dialog shows up AFTER the semaphore times out. How do I ensure that all previous functions completed successfully before proceeding? Here is my onClick function:
public void onButtonClick(View view) throws InterruptedException {
   do_action();
   progress_dialog.show();

   boolean acquired = my_semaphore(15, TimeUnit.SECONDS);
   if (!acquired) {
       // action timed out
       // do something
   } else {
       // set elsewhere in the program
       // a - ok
   }
}

How can I implement it in a better way?
Answer: I'm not sure I understand your question fully but if I understand correctly but here is what I would do. Move your do_action(); call to after progress_dialog.show(); then call progress_dialog.dismiss(); from within the do_action(); method (at the end once your desired code has executed). Also note that the progress dialog is deprecated and you should use something like the progress bar instead. If I misunderstood your question let me know and ill try to give you a answer.
Comment: To clarify...do_action and progress dialog do no fully complete execution when I insert the semaphore get call. Without the get call, both functions execute and I see the progress dialog. When I add the semaphore get, the previous two functions ie do_action and progress bar show do not complete, I also dont see the progress bar until the semaphore times out.
Answer: Well, I know a way to full fill your requirement which name is the async task.
Async task?

AsyncTask was intended to enable proper and easy use of the UI thread.
  However, the most common use case was for integrating into UI, and
  that would cause Context leaks, missed callbacks, or crashes on
  configuration changes. It also has inconsistent behavior on different
  versions of the platform, swallows exceptions from doInBackground, and
  does not provide much utility over using Executors directly.

In your case, I think the do_action() is doing a background task. If so you could use the async task like this.
public void onButtonClick(View view) throws InterruptedException {
     // Execute your task
     new ButtonClickTask().execute();
}

 private class ButtonClickTask extends AsyncTask<Void, Void, Void> {

     // This task run on UI thread
     // Before starting the background task show the progress dialog.
     protected void onPreExecute () {
         progress_dialog.show();
     }

     // This task run on background thread, if you do any UI action from this function it will terminate your application and give an error.
     protected Long doInBackground(Void... params) {
         do_action();
         return null;
     }

     // Once your background task is completed. This method will be called.
     protected void onPostExecute(Void param) {
         // Your do_action() task is completed
         // Now you could dismiss your progress_dialog here and do other tasks
         progress_dialog.dismiss();
     }
 }

Comment: I tried this method earlier but I got a runtime exception, dont recall the error, something to do with Looper. Anyways, this method doesn't have the semaphore get and that is the crucial part. When I perform do_action(), I am expecting a response in a different part of the program which will set the semaphore. If the response doesn't arrive within the timeout, I will perform a cleanup.


LED lamps and fluoro replacements

Question: I  have  recently  purchased   LED  lamps   and magnet attached circular units  to  replace  old  fluoresent  tube units. The individual  lamps in the  format  of a  standard  240v  lightbulb  are  no problem. But  the  circular  units  and two flush mounted  down lights remain  permanently  slightly  lit  when  turned  off. One  of  the  circular  magnet  attached units in particular is  visibly  lit   in  daylight. The  remainder   can only  be  noticed  at  night. I  have  tried  reversing  the  wiring but  that  has  no effect. There  is  no  earth/ground  wire. To check  for  earth leakage via  the   lamp  body (which  is  fixed  to the  ceiling to an  all  steel  framed  building) I  put  insulation  tape  under  the  magnetic   mounts even though  the  lamp unit  is  powder  coated. This  made  no difference. There  are  no   dimmers, only  simple  mechanical  switches. The  only  way  to  fully  kill them is  to  switch  off  the  main supply. Am I missing   something   obvious ?
Comment: Just to make sure, the switches don't light up when off, correct?
Comment: The  switches  are simple  mechanical  with  no indicator lights.
Comment: how do you switch them on and off *other* than by turning off the mains supply to them???
Comment: looks like you may have a serious problem in the breaker panel or in the building wiring
Comment: Wherever you are- is one side of the mains at essentially ground potential or are both 'hot' at 120VAC  wrt earth?
Comment: Are you sure the switches are purely mechanical?  Wall switches with neon indicators can allow sufficient current to dimly illuminate LED lamps.
Comment: If  the mains  supply is  incorrect/reversed  could  the  rcbo be back feeding? I  have  been  assuming load  and  neutral were  correct according  to  colour code. The  supply is  temporary to a new construction via  a builders pole fed  from a  neighbours  house so it maybe  reversed  at source !
Comment: @DavidNichols reversed hot - neutral will not cause your problem. Cheap or mismatched LED's on the same circuit will. I have experienced this myself. LED's have a power driver that is Pulse Width Modulated current control - mismatching can cause problems, your units are always on via potential on the neutrals typical ~2VAC, no grounding means problems like this will occur. It bleeds to the LED and it appears dim. You either need a ground or better LED lamps.
Answer: You will need to change out the LED's for a better model light or add in a real ground. Changing the LED's is cheaper and easier.
Did you leave the Florescent Assemblies in place with their transformer ? Or did you remove that ?
I have experienced this in a ceiling fan unit that had a remote control even some to be as bright as 50%.
I have also experienced this by mismatching LED's on the same lamp assembly:

LED's and Compact fluorescent bulbs.
LED's from one manufacturer with LED's from another manufacturer.

In all of the above cases changing the LED out for a different manufacturer fixed the issues. I now use all CREE or all Philips in my lamp assemblies and I have no issues.

LED lamps and fluoro replacements


Does a Tesla coil work in space?

Question: If I took a Tesla coil into space, and then turned it on near, but not touching metal objects- would charge jump to the metal objects? It's my understanding I wouldn't see a flash, since the lightning comes from ionizing the air, but would the charges still move?
Comment: Yes, no sparks. No much wow and wiiii in space. But yeah! Charges will still move, that don't depends on the external medium.
Answer: The conventional definition of lightning is a current though a plasma (not necessarily through air as lightning happens on other planets) so in a vacuum there cannot be any lightning. However charge does still flow between electrodes in a vacuum, and from personal experience I know that we can get something very like lightning in the right circumstances.
In a vacuum charge can leave a surface due to field emission. Basically the field gets so strong that the electrons at the surface can get enough energy to overcome the metal work function by moving only a small distance and they tunnel out of the metal. However this is a rather diffuse flow and wouldn't generate any light so it wouldn't resemble lightning.
I did claim you can get an effect like lightning, and this can happen if there is a rough spot on the electrode surface that concentrates the electron flow. If the electron flow gets concentrated enough it can vaporise the electrode at the high point then you get an arc through the vapour. In the old days when we used giant Van de Graaff generators as particle accelerators this used to happen on a regular basis leaving a scar on the dome that then needed to be polished away.
Comment: I would like to add that there is vacuum switching gear, which is declared up to 160kV (the number a few years ago, so it could be more today). These are used in the electric power system to separate parts of the network. They do arc while separating the contacts, the arcs are created from the contact material. The crux is, with enough voltage the contact material will vaporize and start *flowing* from one electrode to the other, creating a conducting channel which becomes visible as an arc (when current starts flowing).
Comment: Hey! Some of us still use Van de Graaff generators! Our High Voltage Engineering (Robert Van de Graaff's company) EN Tandem is 53 years old and runs every day for experiments.  We are very surprised if we get a tank spark - those should not happen on a regular basis. (Note ours has been upgraded to a Pelletron chain, which eliminates the main sparking cause of dust from the belt).
Comment: @JonCuster: I'm remembering this stuff from about 1983 (good grief, 32 years ago!) and I've probably remembered the arcing as being more of a problem than it was.
Comment: @JohnRennie - no problem - the technology continues to improve. Earlier this year we opened the Tandem tank for the first time in 5 years to do maintenance. That would have been unheard of 30 years ago...

Does a Tesla coil work in space?


What are the major differences between Drush versions 3 & 4?

Question: What are some of the biggest differences between Drush versions 3.x & 4.x?
Answer: There's a lot of new user management stuff

user-add-role    Add a role to the specified user accounts.
user-block   Block the specified
user(s). user-cancel Cancel a user account with the specified name.
user-create  Create a user account with the specified name.
user-information Print information about the specified user(s).
user-login   Display a one time login link for the given user account (defaults to uid 1).
user-password    (Re)Set the password for the user account with the specified name.
user-remove-role Remove a role from the specified user accounts.
user-unblock Unblock the specified
user(s).

The cache clear functionality has become more fine grained
The backup folder for module updates now appears outside of webroot and you have greater control during updates over which modules to update (security updates only)
Check out http://docs.drush.org/ for more information.
Answer: Drush 4 features a great feature where it can act upon all the sites defined in your sites/ folder in one command. So if you run multisite you can run Drush commands against them all.
Comment: Uh, I miss that feature in Drush 9 :'(


I still kinda have a cramp from when I ran

Question: So in gym class we had to run for 12min and I did 2.3km during that time. At the end I had a really bad cramp, but when she said 1min left, I still sprinted during the hole time. At the end I had a HUGE cramp.. But now around 3 days later, it still hurts at the same spot :/ but less intense. Like it hurts a bit, but it's still bothersome. Please help!
Comment: Where exactly is the cramp? Cramp occurs due to many reasons and is still a mystery.
Comment: Bottom right of my stomach
Answer: I had the same symptoms when I started running. Take a look at this article.
It could have a lot of different causes. But mine went away after these precautions:
I do not run with a full stomach or with a lot of fluids. Also I drink no more than a few sips during running. You can't breath well with a full stomach.
Also, I do start with a low pace and try to keep my breathing pattern when speeding up. If you pay attention to your breathing, you will breath much better.
Stretching obviously helps too. If you try these and it does not go away, I would suggest talking to a physician.


People who give their children the same first name as themselves

Question: I've come across people who give their children the same first names as themselves, and just call the child "junior" while the parent is referred to as "senior". For example, the Nobel laureate John Forbes Nash Jr's father was John Forbes Nash Sr. Nash Jr has 2 sons: John David Stier and John Charles Martin Nash. I'm curious as to why a family would want to call 4 of their men "John". Wouldn't it be better to have different first names for different people in a family?
Comment: I suspect that this can only be answered by personal opinion. Naming patterns can easily result in duplication or triplication of given names but we have no idea whether a pattern is driving the examples.
Comment: Hi, Thomas, I've  closed your question because it goes against several of our site guidelines. Please read the section about what's on or off-topic in the [help].  https://genealogy.stackexchange.com/help/dont-ask and https://genealogy.stackexchange.com/help/on-topic
Answer: This often happened if the first child or children died young.
I have several ancestors of the 17th or 18th centuries where a child John was born and died in infancy.  Another son was born and also called John.
Indeed in one case I do have four Johns in the one family.
This isn't necessarily the family giving the son(s) the same name as the father, in some cases it they are named after another relative, like a grandfather.


Did the Dallas Cowboys's Jeff Heath practice kicking at all since high school?

Question: On 22nd October 2017, the Dallas Cowboys's kicker, Dan Bailey, was injured during their game against the San Francisco 49ers. For the rest of the game, strong safety Jeff Heath handled the kicking duties. While Heath kicked for his high school team, had he done any kicking practice since then?
Comment: It's very unlikely that any reliable answer is possible, though speculation is likely. If it was *unclear* before, it's *primarily opinion-based* now.
Answer: Quoting from the official Cowboys site:

[Heath] got a little [kicking] practice in training camp and last October

and from NBC Sports, referring to the "last October" incident above:

Heath did kick during practice the following week, the first time he had kicked with a snapper and a holder since high school.

so he has definitely practiced since high school.


ATTINY 84 Aref pin?

Question: I want to program an ATTINY84 microcontroller using Arduino UNO as an ISP. In my program I need to use the AREF pin that is located at pin P0 on ATTINY84. I know that I can call analogReference() on Arduino UNO ATMEGA328, but what about the ATTINY84? Do I have to program the IC with some fuses?
Comment: Are you intending to use the ADC? (Why else would you be worried about the AREF pin...) The only reasons should you need to mess with the fuses for programming with ISP is to change the clock speed if you are using an external crystal or clock source.
Answer: For reference, here's a link to the ATTiny84 datasheet.
Section 16.13 specifies the ADC-related registers for controlling the ADC peripheral.
16.13.1 specifies the ADMUX register:
Bit 7 6 5 4 3 2 1 0
0x07 (0x27) REFS1 REFS0 MUX5 MUX4 MUX3 MUX2 MUX1 MUX0

If REFS1=0 and REFS0=1, the ADC will use the external reference on pin PA0.
These registers can be modified in code, here's an example using AVR-C:
ADMUX = 0x40;

Note that this will mess up the MUX settings, there are other ways to do this if you don't want to mess up the mux settings using bitwise operands:
ADMUX = (ADMUX & 0x7F) | 0x40;

ATTINY 84 Aref pin?


How can I instantiate objects at the ends of a curve so that they point outward?

Question: I am trying to create some guitar cables from a curve using Geometry Nodes. I got the setup to work for most parts, but I'm having trouble with the jacks at the ends of the cables. They are supposed to be facing outwards, but currently these keep their original rotation. How can I get these to point in the right direction? Thanks in advance!
Comment: your node setup is not clear image quality wise.
Answer: By converting the curve directly into two points with Curve to Points, you get the two end points with the original rotation and can instantiate the objects at them.
However, one of the two objects will always point in the opposite direction, which you can reverse with Rotate Euler. To do this, just capture the Endpoint Selection in the point domain before converting the curve to points and switch the rotation to be added. In this example I use $180°$ on the Y-axis (since the value here is in radians, this corresponds to $\pi$).

You could of course also use the tangents of the curve in combination with Align Euler to Vector:
Comment: May I ask what the difference between your two solutions are? I mean obviously the method is different but is there a reason to do one over the other?
Comment: @MinerDy Essentially, both solutions do the same thing. The first one, however, transfers the actual rotation of the end points, whereby also a possible curve tilt is correctly considered. The second solution only transfers the direction of the tangent and adjusts the Z-axis of the object to it. In case of doubt, I would use the first variant in your place.


What is the proper way to preserve solder iron tips?

Question: My question is should you turn off a solder iron to preserve tip when not in use. I am currently working on a project which requires sometimes a lot of soldering and sometimes occasional soldering to reroute wires or just tin wires to use as jumper cables. I work 8 to 12 hours a day and most of the time I am programming but sometimes I need to change things on hardware when I solder. So when I am programming should I turn off the soldering station or should I just leave it on or should I minimize the tempreture to preserve the solder tip?
Answer: While the tip is hot, it is oxidizing faster. You should turn it off when not in use, but before it cools, apply some solder to the tip so it forms a cover around it when it cools. That prevents oxidation of the tip while it is cooling down and also when it is off.
Answer: You should turn it off. I see several related questions. If you want to know more, you can look here:
How to clean my soldering iron tip or how to determine that it's beyond repair?
A link from that thread I thought was good:
http://www.hakkousa.com/kb/attachments/How%20to%20maximize%20soldering%20iron%20tip%20life-GUIDe088627954984a4986039711460ec36a.pdf


I am struggling to believe there is anything good in humanity: can you help?

Question: I feel neither like a sinner nor sinned against, but I am struggling to see any good in anyone or myself. I am reminded for the 100,000th time of "mankind is a bridge", and that's what we can love about him. I am not asking a bridge to what, but what exactly is it about us that allows for progress, if we're not talking about human progress but the meaning of humanity?
Comment: I would suggest considering the possibility that you *aren't* good, but that you can and ought to *do* good, be the acts of kindness however small, until goodness becomes a habit. Whereupon you will find you have *become* good.
Comment: I would encourage you to be kind to people who *aren't* especially worthy or needy, and look for the very little things that you can do every single day beyond what is expected of a decent person, not acts of conspicuous gallantry/largesse.
Comment: *"...I am struggling to see any good in anyone or myself."* What would you consider good? For example, there are millions of people out there dedicating (large parts of) their lives to improving the world and the lives of others, on big and small scales. As a consequence we are living in the most peaceful and prosperous time in human history, with people living longer and healthier and more stable lives than ever before, and things are only trending for the better every single day. This is by the hard work and dedication of people. Do you not consider this good?
Comment: It all comes down to what you mean by "good". From a scholastic perspective, [every being is good](https://www.newadvent.org/summa/1005.htm#article3).
Comment: I think your vague queries are better suited for a therapist than for this forum.
Comment: ok i will endeavour to find some people who i think are worthy of my kindness @gs thanks that is helpful
Comment: What kind of an answer would convince you? What kind of an observation would be sufficient?
Comment: I think you're overthinking it.  The point of understanding thinking is to get it under control and deploy it or not deploy it - so this is akin to zen (and just Being) i.e. (and this is rarely said, because it's a promise of sorts) : "If conduct such as that of Zäng and Shih were discarded, the mouths of Yang and Mo gagged, and benevolence and righteousness seized and thrown aside, the virtue of all men would begin to display its mysterious excellence." [Chuang Tzu, Book X: Khü Khieh, or 'Cutting open Satchels.'](https://www.sacred-texts.com/tao/sbe39/index.htm)
Comment: "Mankind has no essential nature." - Sartre. "When you feel like everyone hates you, sleep. When you feel like you hate everyone, eat. When you feel like you hate yourself, shower." - mental health advice-proverb. I was listening to this great podcast I highly revommend: 'Is Depression Evolutionary? with Dr Charles Raison' https://www.drugscience.org.uk/podcast/77-is-depression-evolutionary-with-dr-charles-raison
Comment: Pirsig gives an answer: "Good is 'what you like.'" This is from [Zen and the Art of Motorcycle Maintenance](https://en.wikipedia.org/wiki/Zen_and_the_Art_of_Motorcycle_Maintenance). Pirsig explains how this definition fits into various societal expectations of goodness.
Comment: i admire few people. who do you admire @Servaes ? my friends are good people. hmm
Comment: @doot_s Then why do you say you struggle to see any good in anyone? This seems blatantly contradictory.
Comment: You might like this answer, about the human need to ally ourselves with purposes & groups that will outlast us as individuals, & how to do that: 'What are some philosophical works that explore constructing meaning in life from an agnostic or atheist view?' https://philosophy.stackexchange.com/questions/91010/what-are-some-philosophical-works-that-explore-constructing-meaning-in-life-from/91017#91017
Answer: It doesn't take much to see that humans are pretty cool members of the earth's animal kingdom. We have complex speech, we can use tools, we can grow and dye our hair and clothing fabulous colours, and there is a great capacity for compassion and warmth in humanity in relation to what can be a very harsh world.
But a reasonable question to be asking at this stage is whether we overvalue humanity relative to the wider potential of nature as a whole, and whether our push for exclusively human interests is of net detriment to the world.
This is the charge of Speciesism (cf. the moral status of animals) and I think it's quite a sensible combination of views that humans are valuable, but that our value judgements should not be as wholly focussed on humans as they are.
Comment: Well, the suggestion Singer et al. make is that the goodness of humans is in some critical ways deficient at present, but we might be capable of improving by recognising the moral value of non-human beings and developing accordingly.  You can both think that humans aren't perfect and that there is great potential to forge a better world, and that's pretty cool.
Comment: @Corbin, I've definitely needed to make an interpretation of the question, which is asking about what's good about humans in the context of a "bridge to" something and the "meaning of humanity" in contrast to human progress.  I've proposed that this might be part of the answer here: an ethnocentric view does skew this understanding in ways that an alternative perspective might help.
Answer: Existentialists like Sartre argue that meaning is not inherent - it is constructed by the choices we make and the actions we take. We must take responsibility for finding our own purpose.
He says that we have the freedom and responsibility to create meaning by how we live authentically and treat others. The goodness in humanity is not pre-defined, but rather something we construct by the values we uphold and compassion we show.
So according to his concept Life will always contain suffering and injustice. But we can find purpose in standing up through our actions for the ideals we believe make life meaningful - justice, creativity, love, beauty.
Whether it is the concept you like - is another question. ;)
Comment: Yes. Ideas will only take one so far. I often use the phrase: **the tyranny of concepts**. Deeper is "*The force that through the green fuse drives the flower*".
Answer: I would say this depends on what you mean by "good". Do you mean good for the Earth, for the ecosystem? Do you mean good in an universal sense? Do you mean "good" in a moral/ethical/religious/spiritual sense?
In all of these cases, the answer would either make no sense, or depend solely on the opinions of the one asking - i.e., calling humanity itself "good" or "not good" only says something about the one saying so, not about humanity.
"Humanity" (i.e. the whole of us, the species) can certainly be seen as something which simply is. You wouldn't ask whether any other non-intelligent species, or whether any other fact about the universe at large is "good".
All about humanity can simply be seen as a completely natural extension of the process of evolution that has brought up everything else - including our intelligence, our technology, our big cities, the fact that we make large swaths of the earth non-inhabitable for other species, and so on and forth. There does not need to be a moral difference between termites changing their environment (nothing grows in/on a termite hill except termites), and us building megacities - in both cases a species simply uses the tools available to them to reproduce as much as possible. That is the core of what evolution is, no matter if you talk about plants, animals, or simply the chemical elements.
As you say you are struggling, it sounds like you are asking a bit for help there, and you (OP, as a person) seem to have a problem with not finding anything good about us. I encourage you to explore the idea that things just are what they are. It is not required to find an external, objective meaning-of-life to live and be just fine. It is perfectly fine to assume that humanity as a whole is just as random of a process as a termite hill.  Progress is assured by evolution (in its most general form); where it leads to can neither be predicted nor does it really matter. There is no score card handed out at the end, as far as we know.
Answer: I felt I would answer... not so much the question but your comment which I feel is the real heart of your question.
As a preliminary let me say that I believe that all (authentic) religions are equally worthy of our consideration. [Or simply, I am a perennialist]
However sometimes you feel confined and claustrophobic in the culture you find yourself in and you need a different perspective.  Here is (a snippet of) the Hindu one; hope it helps
Happy → Good vs Good → Happy
Hindus have two aspects of the Divine — Rama and Shiva.
[Well there are zillions but I'll stick to two for here,
Also these formats of the divine are often mistranslated as 'gods', I'll stay with the standard anglophone mistranslation for here
]
shiva means good, rama means happy.
Shiva does and makes happy, Rama does and makes good.
So you will find that Rama is generally depicted as worshiping Shiva, and Shiva as worshiping Rama. While we need not get into the endless mythology of this bonhomie, lets just say that the Platonic forms of the Good and of happiness are closely intertwined.
This translates into two fundamental possible vectors that a human can chart through their life:

I find the good in my innermost core; then in increasing widening concentric circles spread that good in the form of happiness — the Shiva mode
I find happiness in my innermost core; then in increasing widening concentric circles spread that happiness by doing good — the Rama mode

My suggestion then in short: Let go the Shiva mode — be good, make happy — and try the complementary Rama mode — be happy, spread good.
Once that makes sense the next step is natural at least to easterners
Practical non duality
The practice of non-duality is quite simple — at least to enunciate!!

You establish the firm conviction that the sole being that exists is you
all else is input/output data, input data comes in from the sense organs, output data flows out from the volitional organs
Now assuming you are like the 99.99% of us who imagine we have/are in a body [We'll ignore the 0.01% who know themselves as one with the cosmos] you sit to meditate alone
Alone of course literally means when/where no one will disturb you; but more importantly it means with a deep conviction that there is only you...
... and data!

Thoughts come and go... um interesting (or maybe not)
Feelings come and go... usually more engaging
Most important of all the breath comes and goes.  Mostly we ignore it as a given, but try stopping it for 20 seconds and see how SUPER INTERESTING it is!
You may try if you like the mediation called the anapanasati sutra of Buddha...
Or a zillion others...

The point is not the mediation technology you use but to come to an interest in yourself and thence a love of yourself. Finally abidance in yourself (or in the Self).
Terminology: 'atma', usually mistranslated as 'Self' better translated as ground of awareness: you seek to progress from atma anusandhana to atma vichara to atma nishtha.

With even a little practice you will find you become a better person.
But the important thing to get is that the effort is not to be good but to be happy and to love yourself; the good follows as a natural corollary.

PS
Still eastern but a different culture and still a choice:
Which of these three guys appeals to you? Its a really fundamental choice...
Comment: @ScottRowe  Ben Zander?
Comment: Like the "one buttock" piano player from "The Art of Possibility"
Comment: "The lights must never go out,
The music must always play,
All the conventions conspire
To make this fort assume
The furniture of home;
Lest we should see where we are,
Lost in a haunted wood,
Children afraid of the night
Who have never been happy or good." - Auden
Answer: The Christian worldview (and particularly that of my theology in the Church of Jesus Christ of Latter-day Saints) is that mankind is both good and bad.  We are all children of God who is perfectly good, and we chose to follow him in a pre-mortal life, which means all mankind were good then.  But by the fall of man, man became evil, and devilish by nature. Good men who have lived throughout the ages are those who have put off their sinful nature, and become saints through the atonement of Christ the Lord. https://www.churchofjesuschrist.org/study/scriptures/bofm/mosiah/3?lang=eng&id=p19#p19 .
Answer: Mankind is a trap; drop the pretensions to 'feeding the world', and rather than thinking of good and evil in others consider instead things that "truth" and "meaning". Sure it's difficult when you're alone, but there's no need to make something of that


Would TFA be a strong enough acid to perform an SN1 reaction on alcohols?

Question: The pKa of sulfuric acid, which is usually used to do this reaction is -3, but would TFA be sufficient even though it has a pKa of 0.5?
Answer: Yes. TFA is widely used for alcohol dehydration, for example as described in this review.
TFA is a standard reagent for the ionic hydrogenation of alcohols with hydrosilanes which proceeds via the protonation of the alcohol and the formation of the cation wikipedia article


How to schedule a java program to run Every day?

Question: How can I schedule my java program(core java file) to run every day at a particular time?
I want to schedule it in a Linux server and what is the same for Windows?
Comment: Voting to close as OT and moving to *Super User* - running a Java program is a matter of executing `java -jar ...`, the rest is OS-related configuration.
Answer: For Linux, have a look at cron jobs.
First, install your cronjob by running the following command:
# crontab -e

To run a job everyday 5 minutes after midnight, append the following:
5 0 * * * /path/to/command

Save and close the file.
For Windows, have a look at scheduled tasks.
Answer: For linux you can use cron and to do the same thing on windows use quartz-scheduler.
Take a look here for crontab-examples.
Answer: you can use Quartz API to Schedule your daily/On-Time Jobs. Following is the link for Quartz API:
http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/
Answer: You can use linux Cron , yoy can also read good toturial in here: http://www.ibm.com/developerworks/linux/library/l-job-scheduling/index.html
also for scheduling in java program you can use java Api such as Timer class in java util but better approach using scheduling frameworks such as Quartz.
Answer: You can schedule your java program(task) using either Operating system services or using java.
1) Using Operating System Scheduler
for Linux, you can use Cron Jobs to schedule your program
for Windows, check the windows scheduler
2) using java.
you can use java.util.Timer class to schedule a TimerTask object.
make a separte thread for timertask and schedule it with
 Timer.schedule(TimerTask timertask, Datetime)

Answer: please use the following steps:
 1. download and configure your application to use any of the Java services products , I use frequently this one : http://wrapper.tanukisoftware.com/doc/english/download.jsp

schedule your software using any of the scheduling APIs available:
cron4j (very small & reliable but does not cover all possible use cases)
quartz scheduler , the rolls royce for scheduling but now heavyweight
learn the Java 1.5 java.util.concurrent.ScheduledExecutorService
and register a job (Runnable or Future) into this service depending from the API (all may use Runnable ,some support Future and add their own Job classes)
learn the cron syntax to use any of the listed APIs and schedule your job

Quartz may add a lot of features with vetoable jobs , clustering and other advanced topics
HTH
jerome
Answer: Since everyone already mentioned the obvious CLI options.

Linux: gnome-schedule:   apt-get install gnome-schedule
Windows: zcron:  Download from:   http://z-cron.com (been using for years, very effective product).
Mac: CronniX:  Download from:   http://code.google.com/p/cronnix/
Answer: In Unix:
You need to write a script with an .sh extension: something as simple as
echo "start"
java usr/bin/MyClass

would work
then add a entry to start it up under the crontab of the user you want to start the script with
In Windows:
You need to create a bat file(same as scripts with .bat extension)
Schedule in Windows Scheduler


Hearing the difference between a I6 vs iii?

Question: In the opening of this song, I hear an Ab to to Eb/G but then in the verses I hear a Gm after the Ab for the most part. I know the difference between the chords in theory and that they both can function as a passing chord or some sort of a false resolution to the Cm, but I want to learn how to hear the difference between the two and if I'm even correct in the first place that the opening is an Ab to Eb/G. This might not be the right place to ask this, but I was hoping to get some advice on how to practice hearing the difference between these chords and if I heard it correctly in this example.
Comment: We don't transcribe music normally here. Note that intro and verse may use different chords, and there's nothing wrong with it. Also, the song uses upper structures a lot, which results in some ambiguity about interpretation of harmony, and that's perhaps intended.
Answer: In both cases the telltale sign is to listen for the tonic note, the Eb in the second chord in either the harmony or the melody. If there is an Eb (or the tonic note in another key) it is a I6. The tonic, Eb, is also the only common tone between IV and I6 (IV and iii have none). In the intro it is super clear because the basic melody is G Bb F Eb. If you hear a D but no Eb in the chord (in this key) it is a iii, not the case here.
However in both the intro and the verse there is also a D in the chords which makes a case for the iii chord but this is overridden by the presence of the Eb above the D, which gives you an Ebmaj7/G.
It takes practice, time and patience to be able to hear and recognize chords and harmonic progressions but it is an invaluable skill. No matter what instrument you play always spend time on an instrument that can play chords. Try and recognize and identify the way the inner voices move through the chords. It is well worth the effort!
Comment: It is possible to have a D on a strong beat over an Eb/G. You must examine the individual context and make a decision based on your knowledge and experience. If the melody doesn't have a clear interpretation it is best to listen to the notes in the harmony regardless of the melody. That is always a better choice as it is more stable than a melodic line.
Comment: Thank you for the tips but I have yet another question I suppose. How am I to decipher which melody note could be considered a part of the chord and which would just act as some sort of embellishment? If the melody included a D on an accented beat but still had an Eb, would the Eb be considered a passing tone for chordal purposes?


The prime numbers do not satisfies Benford's law

Question: A set of numbers is said to satisfy Benford's law if the leading digit d (d ∈ {1, ..., 9}) occurs with probability,
$$ P(d)=\log_{10}(d+1)-\log_{10}d,$$
how do you prove that the prime numbers do not satisfies Benford's law?
Comment: What probability distribution are you using on the prime numbers?
Comment: you have every reason. Now I think that the question is clear.
Comment: P(d) is just the frequence of the digit d in the prime numbers, is the limit of the number of primes with leading digit d( looking the first n primes) / n
Comment: Technically, not a probability - there is no uniform probability on any countable set. This term here is "density."
Answer: Essentially you face the same problem as the question of whether the natural numbers satisfy Benford's law: if you look at the pattern up to some maximum value $m$ then the distribution depends on what $m$ is, and there is no convergence as $m$ increases because the first digit of $m$ is not stable, though there is a degree of uniformity in the distribution.
From the prime number theorem, the number of primes between $d \times 10^k$ and $(d+1) \times 10^k$ is about $\dfrac{10^k}{\ln((d+\frac12) \times 10^k)}$ while the number between $(d+1) \times 10^k$ and $(d+2) \times 10^k$ is about $\dfrac{10^k}{\ln((d+\frac32) \times 10^k)}$.
The ratio of these tends towards $1$ as $k$ increases, so if you look at the distribution of first digits of primes below $10^k$ then this tends towards uniform as $k$ increases. Nothing like Benford's law.
But if you look at at the distribution of first digits of primes below $3 \times 10^k$, then for large $k$ there will be almost ten times as high a proportion starting with $1$ (or $2$) than with $3$ (or each of the higher digits).
Answer: "[H]ow do you prove that the prime numbers do not satisfies (sic) Benford's law?"
The question of Benford's Law for prime numbers has some wrinkles to it.  Back in 1972, R. E. Whitney proved that prime numbers exhibited the Benford's Law distribution in the logarithmic density, which generalizes the "natural density" (they agree on all sets for which the natural density exists).  That was published in the American Mathematical Monthly, vol 79, pages 150-152 ("Initial digits for the sequence of primes").  Shortly after that, Bombieri showed that the prime numbers had the Benford's Law distribution in the Riemann Zeta density, which also generalizes the natural density; I don't think that proof was ever published, but J.-P. Serre mentions the result on page 76 of "A Course in Arithmetic" (https://www.math.purdue.edu/~lipman/MA598/Serre-Course%20in%20Arithmetic.pdf).  In 1984, Cohen et al showed in "Prime Numbers and the First Digit Phenomenon," Journal of Number Theory, vol 18, pages 261 - 268, that any density that generalizes the natural density with certain intuitive properties (e.g., when you multiply by two you halve the density) and which could measure the density of first digits of primes would follow Benford's Law (http://ac.els-cdn.com/0022314X84900611/1-s2.0-0022314X84900611-main.pdf?_tid=509b9d70-826f-11e5-8d70-00000aacb361&acdnat=1446585211_c0f3dcdb9846df09399024856bdf16f3).
So it's not clear to me how you would prove that prime numbers DON'T satisfy Benford's Law.  It is true that prime numbers are not strongly Benford, but then, neither are the positive integers.
Answer: FWIW Prime Numbers do follow a generalized Benford Law (cf. Bartolo Luque, Lucas Lacasa, http://arxiv.org/PS_cache/arxiv/pdf/0811/0811.3302v1.pdf)
What it boils down to is that the distribution of primes is estimated as x/ln(x), and Benford's law describes a logarithmic distribution.
Comment: The title of that paper states (correctly) that the first digit frequencies of primes tend to uniformity. So *generalized* is being used in a very particular sense.


Is the AES-GCM in Python Crypto.Cipher library can take care the AAD portion

Question: Looking at the description below, it doesn't looks like the AES-GCM mode in Crypto. Cipher library  can take in AAD data. Do we need to handle it separately for using this? Can advise if my understanding is correct. How to achieve the AES-GCM encryption with using this library if I have the AAD portion in my content need to be take care?
Comment: The AAD are generally passed in PyCryptodome with [`update()`](https://pycryptodome.readthedocs.io/en/latest/src/cipher/modern.html#update), s. also this [example](https://pycryptodome.readthedocs.io/en/latest/src/cipher/modern.html#gcm-mode).
Comment: PyCrypto is abandoned, use alternatives like pyca/cryptography https://cryptography.io/en/latest/hazmat/primitives/aead/#cryptography.hazmat.primitives.ciphers.aead.AESGCM
Comment: @frost-nzcr4 - OP uses _PyCryptodome_ and not legacy _PyCrypto_, at least according to the posted documentation excerpt. So there's actually no reason to recommend a change (especially since library recommendations are off-topic on SO).
Comment: Ok, my fault, but at least question should provide proper library name. And second, recommendations in answer with the actual libraries that can help with encryption isn't the same as question asking recommendations to ignite the flamewar.
Answer: As Topaco said in comment, use update(). For example:
<code>from Crypto.Cipher import AES
nonce = bytes(12)
data = bytes(0)
ad = bytes(16)
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
cipher.update(ad)
ciphertext, tag = cipher.encrypt_and_digest(data)
</code>


Is it acceptable to use decoupling capacitor ground pad as ground for oscilloscope probe?

Question: If one were to probe with an oscilloscope using the short ground spring clip attachment, and use the ground pad of a decoupling capacitor as the ground, would the measurement be thrown off at all by currents moving to ground through the capacitor? Or is something like a test point pad on the top layer ground pour required for peak accuracy? Say I'm probing a pin on an IC and using a local decoupling cap ground pad as the ground as shown in the pic, would this measurement be free of any noise from the cap? If not then what would be the best practice method to do this? Thanks.

Comment: You should show the relevant schematic as well as the *complete* PCB layout. Noone can guess the frequency that decoupling cap is subjected to. Moreover, the little part of the PCB layout suggests the cap is grounded to the ground plane, but if the ground plane is cut and causing ground loops...
Comment: It looks like the pin above the to-be-probed pin also seems connected to ground. You could use [such](https://electronics.stackexchange.com/questions/221292/tip-barrel-test-of-oscilloscope) setup
Answer: In general you want to minimize the loop area when probing fast signals. So, as a rule of thumb, you should select the ground connection that minimizes the loop area.
Now this is only in general. There may be good reasons to use the capacitor ground. This is due to the resonances in the ground plane. Your ground plane will not be zero volts everywhere for all frequencies. It will look something like this:

source
This shows the voltage of the ground plane at a specific frequency. What's worse is that this can change dynamically depending on the power consumption of the ICs. If you select a ground reference near a resonant mode, high frequency noise can enter your probe, due to the fact that the ground plane reference will be oscillating at the resonant frequency.
The thing about decoupling capacitors is that they suppress the resonances in the power planes. In fact this is how you prevent unwanted resonant modes near your frequency of operation. However this all depends on the geometry of the planes, the value of the capacitor (the smaller the better), power consumption of the ICs, frequency of the ICs etc.
So it all depends on your specific situation. As I said, try to minimize the loop area as a general first approach.
Answer: Your assumption is correct to use this pad.
But consider what rise time you expect and ringing error to occur from the probe if looking at <5ns rise time.
The criteria for analyzing a bad choice of gnd. Is V=LdI/dt. Where f-3dB=0.35/dt (10~90%) and L=~0.5nH/mm the distance of the shared ground current of the observed square wave rise time.  The probe capacitance also results in a resonant frequency from this L including the probe spring length and if kept short should permit a flat response to a 200MHz BW , the limit of many good high Z 10M probes.  By contrast , a typical 200MHz probe with a long ground clip wire will resonate near 30MHz due to L of the ground clip and probe capacitance.
Beyond this requires a better understanding of geometry where 50 Ohm AC probes  work best and 50 Ohm geometry has a ratio of signal width to gnd gap near 0.5 and length becomes irrelevant. This reduces the Q of the parallel Resonance and extends the BW into the GHz range.
Generally a good design with DFT will have paired test points for short spring probe contacts on critical test signals including Vdd with an AC coupled 50 Ohm load for direct coax connection or high Z spring Probe.  This is a desirable way to measure supply ripple accurately at source and loads for comparison using the 50 Ohm AC coupled load. Ideally the 50Ohm is selected on the DSO or SA input with AC mode to prevent power loading using high freq high quality coax , if you want >1GHz BW.
Comment: does Tektronix still sell 500 ohm probes? 450 ohm in probe, plus 50 ohm in scope.
Comment: @analogsystemsrf Don't know but that is also a good method for DC capture


Applying for a UK visa with a Schengen visa that is about to expire. Would this cause issues?

Question: I am planning to travel England in next December(20-27th). But my current Schengen visa is valid till December 31st. I am not sure, if my visa application will be refused because of that?I have not found any clear information in gov.uk site. They only mentioned, I need to have valid visa when I travel.
Comment: Your UK visa application will not be refused because of your Schengen visa.  It will also not be accepted because of your Schengen visa.  Rather, it will be refused or accepted because of the weakness or strength of the application.
Comment: The UK is not part of the Schengen Area. You cannot enter the UK with just a Schengen visa, you need a UK visa.
Comment: No, this is completely unrelated. You can get a UK visa without having ever had a Schengen visa.
Comment: Yes I know, so my question is, is there any possibility to get refused to get British VISA considring my current situation?
Comment: What will you do on after the trip? Leave the EU immediately? Return to the Schengen area for a couple of days and then leave? Apply for another status or find a way to extend your stay? If you plan on leaving, having evidence of that might help a bit. On the other hand, if you are in a position to obtain another status and remain in the Schengen area after December, then evidence that you have applied for it could be useful.
Comment: Actually, My problem is: My Schengen VISA will end on 31st December, I will start my VISA extension procedure on first week of December, But I will have to start my British VISA application before that, so British Embassy will not able to know, I am extending it. Obviously I will comeback to Germany as I have work here. But How can I solve this situation?
Answer: You want to apply for Standard Visitor Visa and you have a Schengen that will expire about two weeks after you arrive in the UK.

so my question is, is there any possibility to get refused to get
  British VISA considring my current situation?

Yes, those are delicate situations and they are not going to be happy about it. It looks like you want to remain in Europe after your Schengen expires and are using a UK visa as a pretext to advance a secondary agenda.  Maybe you are, maybe you're not, but that's what they will think.  They are paid to think like that.
They will also be wondering why you did not extend your Schengen and more importantly what is making you apply for a UK visa at this particular time (that can be a show-stopper).  You need to get proactive and address both of those in your application BEFORE they have a chance to start worrying about it.
In a more general sense, they usually like it when the applicant has a Schengen currently or in their history.  It means the applicant has already performed in a regulated environment (that's a good thing).  But the timing of the application in your case is suspect and hence elevates the risk of refusal. So be diligent and proactive.
Comment: Actually, My problem is: My Schengen VISA will end on 31st December, I will start my VISA extension procedure on first week of December, But I will have to start my British VISA application before that, so British Embassy will not able to know, I am extending it. Obviously I will comeback to Germany as I have work here. But How can I solve this situation?
Comment: The answer is above, perhaps reading it again will help?
Comment: @VessilliZayetsev you can apply for a new Schengen visa up to three months before your intended travel.  If you apply for a visa for a trip on January 1st, you can lodge that application at the beginning of October.  But really, a lot depends on your trip.  If you are traveling to the UK from a non-EU country, then you should not have too hard a time dissociating your trip from your Schengen visa.  If you are traveling to the UK from a Schengen country, it will be harder.


How to remove content editor after first load of any page

Question: Any one knows how to remove content editor after first load. I want to load the page with content editor for the first time but after page refresh the content editor should be removed from the page. Please suggest the help. Thanks in advance
Comment: What kind of requirement is this?
Comment: I have script inside the content editor and i want to run this script only for first time.
Answer: You can use locastorage or cookies for your requirement, localstorage can be used to store custom string values on custom key values.You can have the below code in the page load to determine whether the page has been loaded already or not.
if(localStorage.getItem('first') === null){
  toBeExecutedOnFirstLoad();
  localStorage.setItem('first','nope!');
}

OR
if (localStorage['...my key here...'] === '...my expected value here...') {
    // The page has been visited before
} else {
    // The page has not been visited before
    // OR
    // The user or script has cleared the localStorage value
}
localStorage['...my key here...'] = '...my expected value here...';

NOTE:

If the user deletes his cookies and or other site plugin data then it will refresh.
If you want to show the page again for next session, replace localStorage with sessionStorage
For more information on localstorage, click here
Comment: And for a more permanent solution, one could mix the localStorage with a user profile property.


Third Person Flying Camera

Question: I am having issues creating a third-person camera for my Rogue Squadron (N64) like game. First I have posted my issue on the official Unity Answers site here. So far my ship is behaving as I want and the camera follows position correctly (XYZ), however, it doesn't rotate how I would like. My first attempt was to set the rotation of the camera to the rotation of the ship and realized that is not what I am looking for either. I have found some information on rotating around a (pivot) point but I am having trouble understanding them. For example, I have found this and this but Im not sure how they work. The end result would be something like the camera found here. Thank you for any help, I would greatly appreciate a description of what you are doing/how it works. Lastly this is done in C# in Unity. I can provide my code if needed.
Answer: Hello and welcome to the community!
Solution 1 - manually setting rotation and position
You almost got it, you just need to do camera offset a bit different. Transform has handy-dandy properties, called .foward, .right, which are normalized vectors for the direction the Transform is looking at.
Now imagine your player ir facing north (transform.forward is (x=0, y=0, z=1)). To move camera 5 units behind, you would do cameraPosition = playerPosition + playerTransform.forward * -5f. The multiplication would result in (x=0, y=0, z=-5) and camera would be placed 5 units behind. Easy, right?
Now what if you want to place 5 units behids plus two units to the left? You add those Vectors together, which results in cameraPosition = playerPosition + ((playerTransform.forward * -5f) + (playerTransform.right * -4f)). Now your camera is placed 5 units behind and 4 unit left of the player.
To place the camera 2 units above the player, you would just use transform.up property and the whole routine is the same.
After setting the offset, use camera.rotation = player.rotation to rotate camera to right angle.
Here's a quick snippet for camera, that follows set object:
public class TransformFollower : MonoBehaviour
{
    public Vector3 offset;
    public Transform target;

    private void Update()
    {
        transform.position = target.position +
            (target.right * offset.x) +
            (target.up * offset.y) +
            (target.forward * offset.z);

        transform.rotation = target.rotation;
    }
}

Solution 2 - let Unity hierarchy do it for you
If you're never going to Destroy player character object, you could make the camera as a child of the Player object. Then setting offset in the inspector. All rotation and following would be done automatically by the Unity engine, as the Camera would be anchored to the Player.
Comment: Hey, Tomas thank you so much your answer is working. After learning from my mistakes it seems I nearly had it though I was setting the position of the camera to the position of the ship not the "forward" of the ship. Again, I appreciate all of your help, thank you.
Comment: Hello and thank you Tomas for your input / help. So I have read your post and I like it a lot though there are still some issues The issue is the camera will not rotate with the ship's local z. The result is I can fly upside down and the camera will still be right side up. I have a video [here](https://streamable.com/wohtk2). Thank you again for your help.
Comment: Ok, found the solution - instead of using `transform.LookAt()` just make `camera.rotation = player.rotation`. I'm editing the answer to make it clear.

Third Person Flying Camera


List Video Filename and Duration for multiple files in folder and subfolders with path too if possible

Question: I need to get a list of filenames and path along with the duration of the file. All are video files. Some files are in subfolders as well. I need the list sorted according to duration.
My goal is to delete the files which have a duration lower than 2 minutes.
Is there someway I can do it through terminal or GUI?
Comment: Possible duplicate: http://askubuntu.com/q/681388/295286
Answer: this should give you a list of mp4s less than 120 seconds in the folder specified including sub folders
find ~/pathtofolder -iname '*.mp4' -type f > vidfiles && while read f; do echo -n "$f: "; ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$f"; done < vidfiles | awk '$NF<120' > shortvids

Just change the ~/pathtofolder to your target location.
The list will be in a file called shortvids
I apologize for not sorting but I don't see the need if the only files in the list are the short videos.
If you would like to change the duration, near the end change '$NF<120' to the number of seconds.  For example '$NF<300' would mean "duration less than 5 minutes(or 300 seconds)"
of course you can also find durations greater than or equal to by changing the sign ie. < to > or =
Answer: You are out of luck without using external programmes, file videoname.xyz does not return the duration of the videos. On the other hand, avprobe (ffprobe) from the package libav-tools does!
You would need to perform a recursive directory walk (e.g. in Python), call avprobe (via a subprocess), parse the duration from the output and store play length and filename in a suitable structure.