Plesk httpdocs permission in skeleton

Question: I would like my plesk skeleton httpdocs to have a drwxr-xr-x permission. Plesk creates users for each domain we create, but the only users that need access to the domain, are the developers who update the application code, and they belong to the group that owns all t / I tried setting it up in /var/www/vhosts/.skel/0 but the permissions from there are always overwritten.
Comment: This question appears to be off-topic because it is about [`working with a service provider's management interface, such as cPanel`](http://serverfault.com/help/on-topic).
Answer: Yes, permissions and ownership are overwritten. You can only put custom files in skeleton. If you want some users accessing all domains on a server, you could include them in "psaserv" group, which is granted access to httpdocs.
Comment: hey Sergey. that's what I did already. my skeleton has drwxrwxr-x 5 root root 4096 Jul 10 09:58 httpdocs but once a new domain is created it reverts to drwxr-xr-x. All the web developers are part of psaserv already.
Answer: Thanks to Sergeys suggestion in another post I created an event that chmods all the directories on "Physical hosting created"
FYI Domain Created doesn't work, as it is being called before the actual files are created on the server.
#!/bin/bash
chmod g+rwx "/var/www/vhosts/${NEW_DOMAIN_NAME}/httpdocs"
chmod g+rwx "/var/www/vhosts/${NEW_DOMAIN_NAME}/httpsdocs"

Plesk httpdocs permission in skeleton


Can large, sticky, sodium polyacrylate crystals be coated in a powder to facilitate handling?

Question: I am separating a larger container of sodium polyacrylate crystals into smaller containers for student experiments. Commonly known as "Deco Cubes" and used by florists in decorations and centerpieces, they are about 1/8" cubed. They are sticky which makes them hard to handle. Is there a water resistant powder that I can coat these with, to facilitate handling, that can be washed off just before hydrating?
Comment: They are not crystals.
Answer: It's hard to know what would be best without knowing what state they are in initially and how you are going to use them.
Assuming they are dried to begin with then they are likely sticky due to absorption of humidity from the air. Try drying them in an oven or vacuum desiccator (if you have one) and then storing with silica gel in a sealed container (the little packets you find in electronics boxes) to keep them dry.
If that doesn't work, try coating with a very fine water-soluble powder that  won't ruin your future experiment. Icing sugar might be a good idea but be warned that the resulting gels may end up being the perfect place for bacteria to grow due to the wet, sugary environment so this might be a bad idea depending on how long you plan to use them for.
Comment: I called the manufacturer and like you said, the product is absorbing moisture from the environment and becoming sticky. However, they had nothing to add for handling. They just deal with it. I tried adding corn starch, but after 3 days, the results were iffy. Looked like the moisture seeped into the corn starch and bacterial growth could become an issue. I have access to a vacuum chamber so I will try that next.


How to train model when Data is consist of matrices

Question: I am new to ML and python. I am facing an issue related to the training SVM model. I have a training data file size (200,50,120). Where 200 are my examples (or experiments). While Actual data is a matrix X= 50x120. Here 120 are features and 50 is the sample size. On the other side, there is a Y=labels file with size (200,1). I am confused, how to train the model with a matrix? I read some comments about flattering the features into an array. whats is its purpose?
Comment: so what are the 50 "samples"? Time series?
Comment: What does "flattering the features" mean? Flattening perhaps? But then...flatten to put the features into an array? What for? What about using matrix algebra for matrices?
Answer: The purpose of flattening (or reshaping in general) is to match dimensions of data and model layer to enable training.
Answer: Considering your case, the input to an SVM model (assuming you are using scikit-learn) is a 2D array with a shape of (n_samples, n_features). Now given the dimensions of your data, think about how it can be brought to this form so that the fit method from sklearn.svm.SVC can be used directly. The quickest idea that comes to the mind is to somehow change the dimension of the matrix (50x120) because we already have 200 as the number of samples. The way it is done in machine learning is the data is "flattened" such that it can be represented by a vector. Another interesting way to think about this is when you vectorize your data, you are essentially representing it by a point in that dimensional space (that is, in 50x120-dimensional space, each example becomes a point). So, with the help of "flattening", the input to the model is nothing but 200 data points, each in 50x120-dimensional space.
Here are some quick references for training an SVM model:
1) Scikit-SVM
2) SVM code examples


What is the difference between Social Engineering Attack and APT Attack?

Question: Doesn't social engineering attack mean APT attack? They seem similar in my mind, because both of them focuses human, not technology. Shortly, what is the difference between social engineering attack and APT attack?
Comment: Some attackers are more *apt* than others...
Comment: I once read a tweet (author forgotten, the login started with a 'c' IIRC) which stated more or less that 'when a small company is hacked it is called bad security, when a large one is - it is called an APT'. Being a victim of an APT sounds much better than being hacked because security was not there. This does not answer your question as there is no relationship between "APT" and "Social Engineering" (it is one of the ways to gather information prior to or during an attack)
Answer: APT is generally thought of as "Advanced" to the tune that many resources were used in order to attack a target. These resources could be programming (zero day/unseen/sophisticated) threats that are not common among a set of baseline attacks (they used exploit X Y Z). They generally are in the attack/compromise phase for long periods of time, and have indicators of "heavy" sponsorship. (Nation states, organized crime groups... Someone/some group with financial resources/time). The wikipedia entry for APT is very detailed in explaining the differences of what an APT is, and isn't.
Social engineering is one set of attacks that APT groups may use. For example spearphishing: "Targeted phishing attacks" This is when an attack group creates a specific message that a target is likelier to open versus random phishing attack. For example, if you announced a partnership with Acme Corp, and received an email from who appears to be the attorney for Acme Corp, there is a higher likelihood you would open that email. It is targeted specifically to make you open it. It (the phish) has relevant information (targeted). Rarely has it been documented that other means of social engineering (phone calls, in person visits, perimeter style) were used in an APT attack. Long story short, APT is an attack phase/parameter, and social engineering might be one of the vectors used.
Answer: Original answer
Social engineering is a set of techniques while APT is a type of attack(er). Let me clarify:
Social engineering means, targeting the human as the weakest link of the system. This includes attack like phishing, calling support to get information or change passwords, talking to people to get entrance to a restricted area, etc.
APT (advanced persistent threat) is a name that is given to a type of attack(er). Someone, but more often a team, with great knowledge, time and money to attack. State sponsored attackers are a good example.  They will most often try to persist their attack once they have broken into your system by installing rootkits or backdoors. Their goal is to remain under the radar and gain information and escalate privilege. An APT is characterized by the time between the start of the attack and the time of detection. These guys have often infiltrated months or years before being detected. Even after closing the initial vulnerability the attack can persist through extended knowledge of the system and earlier compromise of other system.APT wiki
Social engineering can also be used by an APT to gain initial access to your network. Therefor these two are not opposites or synonyms. Social engineering is an type of attack vectors and APT is a type of attack.
Edit:
Since I had a lot of comment on APT being an attack. The Dutch Wikipedia explains it as an attack while the English Wikipedia explains it as an attacker. In my first explanation I had it both as a type of attack as well as a type of attacker. This was kinda confusing so I removed it.
APT is indeed a threat that goes out from a type of attacker but they are are characterized by the way they attack (therefor type of attack).
English wiki:

APT usually refers to a group, such as a government, with both the capability and the intent to target, persistently and effectively, a specific entity.
  Wikipedia

Dutch wiki:

Een Advanced Persistent Threat (APT) is een langdurige en doelgerichte cyberaanval... Wikipedia

Translates to: An APT is prolonged and targeted cyber attack...
Comment: "APT (advanced persistent threat) is a name that is given to a type of attack" - sorry but I'd disagree, and so would your linked wiki article :)
Comment: "APT" is not an "attack". It's much broader in scope than a type of attack. Also, "social engineering" is a type of attack, and "phishing" would be the "attack vector".
Comment: @schroeder, I disagree that social engineering is a type of attack. Social engineer like phising, baiting, pretexting is a set of concrete techniques to penetrate a system. An attack can consist of multiple of these attack vectors and also contains much more like data extraction, cleaning up your tracks and installing backdoors. Therefor APT which is a type of attacker uses a distinct attack (pattern) and makes use of attack vectors which can be grouped into attack types like social engineering.


Secure Pages Best Practice

Question: I am in process of writing a plugin that has front-end shortcodes that display a user's information/data.  If the user is not logged in, I need to redirect to a front-end login page/form.  What would be the best practice here?  My plugin creates the pages that I use as well as add the shortcodes to those pages.  So, if there is a way to "protect" those pages I would love to know.
Answer: Not sure about the best practices, but I have a few custom login-sensitive pages which simply display a message if user is not logged and is trying to view the page directly:
$logged_in = is_user_logged_in();

if($logged_in) {
?>

        <?php the_content(); ?>

<?php
} else {
    _e('You are not logged in. Please ', 'abc');
    echo ''. __('log in','abc') .' ' . __('or','abc') . ' ';
    echo ''. __('register','abc') .'.';
}

Note: both the login and register pages are custom pages as well.
Comment: Thanks for the response.  Is there a way to redirect the user to my front-end login page without getting the "Warning Headers Already Sent" message?
Comment: Hm. By the looks of it [this snippet](http://madebyraygun.com/blog/2012/wordpress-snippet-redirect-all-non-logged-in-users-to-login-page/) should work. If you want conditions then a plugin could be the way to go, such as [this one](http://wordpress.org/plugins/peters-login-redirect/).
Answer: You can't redirect users from a shortcode. Shortcodes run too late-- well after content has been sent. But given that your plugin is creating the Pages you should be able to do this:
function protect_plugin_page_wpse_101230() {
  if(is_page('page-slug') && !is_user_logged_in()) {
    wp_safe_redirect('your-login-page-url');
  }
}
add_action('template_redirect','protect_plugin_page_wpse_101230');

Secure Pages Best Practice


Explicitly set document.domain on every page

Question: Is is a good idea to set document.domain on every page of your site. For example if your site is 'www.example.com'. But you also work with 'en.example.com' and 'fr.example.com' and 'www.example.com:8444'. All these domains make it difficult to work with when you have to deal with xss issues. So is it a terrible idea to explicity set document.domain = 'example.com' on all pages?
Answer: It depends. It means any other subdomain can do the same, so if ever one with a lower trust level comes along (like ads.example.com or survey.example.com) it may come back and bite you.


Can the three quark colors be considered to correspond to different particles?

Question: Is it harmless to count three, say, up quark particles instead of one up quark with three colors, as well as 8 different gluons instead of one with different color?
Comment: Define "harmless."
Comment: That sounds like a distinction without a difference.
Comment: In many situations this is not optional. For instance, if you compute the contribution of the quarks to the entropy of the early universe, you need to take into account these color factors.
Answer:
Color is the strong interaction analog to charge in the electromagnetic force. The term "color" was introduced to label a property of the quarks which allowed apparently identical quarks to reside in the same particle, for example, two "up" quarks in the proton. To allow three particles to coexist and satisfy the Pauli exclusion principle, a property with three values was needed. The idea of three primary colors like red, green, and blue making white light was attractive, and language about "colorless" particles sprang up. It has nothing whatever to do with real color, but provides three distinct quantum states.

Italics mine.

The rationale for the concept of color can be highlighted with the case of the omega-minus, a baryon composed of three strange quarks. Since quarks are fermions with spin 1/2, they must obey the Pauli exclusion principle and cannot exist in identical states. So with three strange quarks, the property which distinguishes them must be capable of at least three distinct values

The difference  with the electromagnetic charge is that color charge can be exchanged. An electron cannot change its charge and still be an electron, it is identified by its elementary charge. A quark can be either red blue or green with color exchanges with gluons, whereas photons do not carry off charge when interacting with electrons.
Color charge acts more like classical positive and negative charges which can be exchanged  in classical interactions. The SU(3)xSU(2)xU(1) standard model successfully describes  particle interactions, and  there the only differenc in quarks comes from the fixed quantum numbers of strangeness , charm, bottomnes and toppness, which are conserved in strong interactions.
Answer: The short answer is no, it's not harmless.
The technical reason why is that experiments confirm that the gauge group of QCD is $SU(3)$, which implies three colors for quarks and eight charges for gluons.
The less technical reason why is that if you look closely at particle collisions, the frequency of certain types of collisions is only accurately predicted in the case that quarks have three colors and gluons have eight charges.  (These are known as three and four jet events in electron positron collisions, D. Decamp et al. (ALEPH), Evidence for the triple gluon vertex from measurements of the QCD color factors in Z decay into four jets, Phys. Lett. B284, 151 (1992).)


can I reset my visitor status

Question: I have applied for Canadian PR and am at the 6 month point with no final answer yet. I currently live in Canada but am not working whilst awaiting the award. My current status is on a 6 month visitor visa which shortly runs out. I have applied for an extension but am awaiting that as well. If I leave the country and fly to the UK for a week can I reset my visitor status?
Answer: In most countries, a pending application for permanent (or even temporary) residence will allow you to stay beyond the expiration of the status you were in when you filed the application.  By contrast, if you leave the country, that can be seen as abandoning your pending application, requiring you to start all over again from the beginning.  Here's what Canada has to say about that:

Can I leave Canada while IRCC processes my application for permanent residence?
Yes. However, if you leave Canada while your application is being processed, you must meet all the admissibility rules before being allowed back into Canada.
If you leave Canada and want to return, you must have all the required documents to enter. This can include:

a valid passport or other travel documents,
a valid work permit or study permit, if you need one, and
a valid visitor visa or an Electronic Travel Authorization (eTA), if you need one.

If you are unable to return to Canada, we could determine that you abandoned your application. In that case, we will not process it.

They also mention that you must maintain valid status independently of the pending application for PR.  You have taken that into account and applied for an extension.  That application allows you to remain after the expiration of your initial period of admission.  This is from the pages about extending visitor status:

After you apply
If your processing time has passed, you may contact us by using this Web form. For the "type of application/enquiry," select one of the temporary residence options (online or on paper).
If your status expires
If you apply to extend your stay in Canada before the date you're supposed to leave, you can legally remain in Canada until a decision is made on your application. In this situation, you have implied status.

So you don't need to leave Canada before your original period of admission as a visitor expires.  Taking those two things together, I would say that attempting to "reset" your visitor status by leaving the country is risky.
Answer: If you applied inland, it may be a bad idea to leave the country before your PR is approved. I was applying in 2016, so things may have changed, but IIRC you are allowed to stay in the country as long as you're not doing anything that would give them reason to remove you. If you leave, however, there is no guarantee you will be let back in. If you're not in Canada, you're no longer an "inland applicant," and may need to start over. Canadavisa.com has lots of information about this and forums with many datapoints. They helped me stay sane during the process.

can I reset my visitor status


Sub panel install issue

Question: I had a sub panel installed recently. The plan was that i will be installing my own breakers.  The sub is running off of the main about 25 feet away in my garage.  I understand that the ground and neutral cannot run on the same bars so why did they install it this way?  Below is the pic of the sub panel!  Can i just remove the bonding screw and attach the ground to a separate bus? Im getting mixed answers from people.
Comment: Electrician screwed up. You can see the ground bar screws, they are directly in the photo.  Also the N-G bond (green screw) will need to go.  To be charitable maybe the person's last 10 panels were small GEs which have a rightside, insulated ground bar.
Comment: It looks like at least one of the mounting screws is missing too.  Between red and neutral.  Not a huge deal, but I hate when people only put half the screws into anything.
Comment: I'm tagging @Harper-ReinstateMonica on this because he has already commented, and I know he knows the answer.  Don't all subpanels require a local shutoff?  This can be, and often is, a main breaker on the subpanel.  Maybe I'm wrong...I needed one for mine (maybe a local thing).
Comment: I believe in this case the fact that it's (as I read the question) in the same building means the shutoff at the supply end covers that. If it was a different building, yes, needed.
Comment: @tnknepp Yup, only ones in outbuildings, as ecnerwal says...
Answer: I'd be seriously tempted to email that picture to the licensing board...
I assume from your question that this was installed, incorrectly, by licensed electricians.
Buy a ground bar to fit your panel, note the pre-threaded holes in the back of the panel for the ground bar, move the ground wire to it, and remove the bonding screw. Or call up your "licensed electricians" and have them come correct their error without charging you extra, because it was a blatant error.
You will need a torque screwdriver (or low-value inch-pound torque wrench) for the connections to the ground bar, and your breakers, and perhaps you need to check the torque on the screws installed by your "licensed electricians" as well.
Comment: I think option #2 should be #1 - call the electricians back and make them fix it.  To be honest, I'd consider reversing any payment I'd made and using the money to hire an actually licenced inspector to check all of their work.  If they made such a basic error inside the panel you cannot trust anything else they've done.  Presumably OP hired someone because they didn't want the responsibility of making sure that the work was done safely and correctly.  It seems absurd to pay someone for that peace of mind only to be left with mystery meat at the end anyway.
Comment: The correct grounding bar is an Eaton GBKP10 or GBKP14, by the way
Answer: Yeah, this was wrong
What the installers did here was a pretty blatant violation of the NEC 250.142(B) requirement that the grounded conductor not be used as a grounding means downstream of the service entrance, and doesn't fall under any of the exceptions that section provides.  So, I'd make them fix it, as it shouldn't take them long to pick up the correct ground bar for your panel, whack it in there, move the green wire over to it, and remove the green grounding screw.
If you can't get them to come out there again, you'll need an Eaton GBKP14P, which you should be able to order in thru your local Lowes, or simply order online for that matter.  Once you have that, the process is the same; just remember to keep the feeder breaker off until the work's done, though!

Sub panel install issue


Why are some ISO numbers greyed out on my Canon 7D Mark II?

Question: I am only able to select ISO 100, 200, 400, 800, 1600, 3200, 6400, 12800, 16000. Everything else is greyed out. I can't find anything online about it. I find it hard to believe that I am the only one that has experienced this. How can I fix this?
Comment: Check advanced options to see if ISO step is in 1... if it is, change it to 1/2 or 1/3 as needed.
Comment: yes that fixed it!! post your this as an answer and let me select it as the answer
Answer: Check advanced options to see if ISO step is in 1... if it is, change it to 1/2 or 1/3 as needed.
Answer: The Canon 7D Mark II is a very configurable camera. One of the options the user has is to choose which options are selectable from various menus. ISO speed setting increments is one such choice.
On page 434 of the EOS 7D Mark II Instruction Manual there are instructions on how to set Custom Function 1 (C.Fn1: Exposure) --> ISO Speed Setting Increments to either 1-stop or 1/3-stop increments.
Comment: It would be helpful to know what part of the answer is incorrect or how it might be improved if one is compelled to downvote, especially on such a straightforward answer.


Substitute for chickpeas in Thailand

Question: I can't find chickpeas. What would you recommend instead when making falafel?
Comment: I don't know if it will help, but other names for chickpeas include garbanzos, ceci, or chana dal. Depending what kind of international markets are available to you, they might use one of these names instead of chickpeas.
Comment: Besan flour or Gram flour (both chickpeas) are probably too fine for falafel. Fresh cooked broad beans or Fava beans might work. https://www.google.com/search?q=broad+beans&ie=utf-8&oe=utf-8
Comment: @WayfaringStranger : cooked?  I thought that felafel was made from ground uncooked beans (either fresh or dried & soaked).  See http://www.telegraph.co.uk/foodanddrink/recipes/10146437/Broad-bean-falafel-sandwich-with-tahinisauce.html
Comment: @Joe Tinned (or canned) chickpeas are cooked. As the first comment in your link implies, it is possible to overcook the things. Soaking for a few days *should* work too, but I've always been too impatient for that.
Answer: I have personally made felafel with split peas (both green and yellow) as well as chickpeas and several other types of bean. I have not tried red beans as I don't like them. While not exactly the same as chickpea, the split pea felafel were felafel, not something unrecognizable as felafel, though the green ones were quite green ;-)
I don't use canned beans for felafel, I use soaked dried beans.
Answer: Look for goobers.   Same thing. Normally in can goods.  Bigger stores. Ram brand Garbanozos bean is what I buy. Red  can. With photo of chick peas on it. Normaly near Ram pork & beans in store.
Comment: I haven't heard the term 'goober' in many years.  (possibly 30 yrs ago, when I lived in Alabama).  But it always referred to peanuts.
Comment: In the Philippines were I live. There are hold over words from WW2 & Military slang that don't mean the same as in America. In America you are right.  In Thailand same but more British in slang. So word do change some.
Answer: Split huskless mung beans can be used.
Comment: These should be very easy to find in Thailand as well. Best suggestion in my opinion

Substitute for chickpeas in Thailand


How can I remove the labels Social, Promotions, Updates, Forums in Gmail's compose window?

Question: I would like to remove the labels "Social", "Promotions", "Updates", and "Forums", from the Gmail compose window.
Comment: They're not labels per se, but inbox categories. They're only included in the list of labels as a convenience. Short of something that will modify the HTML, there isn't a way to remove them. (Unless, of course, you stop using the inbox categories altogether.)
Comment: Thanks @AʟE.! I don't mind to completely stop using the inbox categories. How can I do that?
Comment: Eh, phooey. Even if you turn them off you can't remove them from the labels list. That's annoying. I'll create an answer to that effect.
Answer: They're not labels per se, but inbox categories. They're put into your labels list as a convenience, so that moving messages into or out of a category is easier. Moving a message into or out of a category informs Gmail how to categorize similar messages in the future.
You can turn them on or off in Settings > Inbox > Categories.
Unfortunately, you can't remove them from the labels list. Probably because even though you may not be using/showing them, Gmail still uses them. (This is true even when using an alternative Inbox option, like "Priority Inbox".

All messages are automatically labeled for the first 5 categories even if you don't show the categories in your inbox.

So, short of some possible HTML/CSS trickery in your local browser, you cannot remove these categories from the labels list. At least they're sorted to the bottom.
Comment: Thanks! Let me know if you know of any HTML/CSS trickery that removes or hides those. :-)
Answer: What I do is wait till I've got a page full of emails (100 in my setup), then select All emails, then in the Labels button, page down to the end of the labels that you've applied yourself. Untick the Social, Promotions etc boxes (fortunately always at the end of the list) and you're done. DON'T FORGET to select NONE afterwards, of course, to clear the active boxes next to your emails. Sounds ponderous but it literally takes 10 seconds and you only have to do it ~twice a month.
Answer: A HTML/CSS trickery that can hide them, written in Tampermonkey:
// ==UserScript==
// @name         Gmail remove annoying categories
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://mail.google.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant        GM_addStyle
// ==/UserScript==

waitForKeyElements (
    "div[title*='Updates'], div[title*='Forums'], div[title*='Promotions'], div[title*='Social']",
    hideNode
);

function hideNode (jNode) {
    jNode.hide ();
}


Quasi-compactification of locally spectral spaces

Question: Let $X$ be a locally spectral topological space (i.e. a space admitting an open cover by spectral spaces). Does there necessarily exist a quasi-compact locally spectral space $Y$ and an injective continuous open map $X\rightarrow Y$? What if we require $Y$ to be spectral?
Answer: I still do not know the answer to the first question, but it turns out the second question was pretty idiotic.
Take any topological space that has a cover by two spectral open subspaces whose intersection is not quasi-compact (e.g. the underlying space of the infinite-dimensional affine space with doubled origin over the integers).
Notice that an injective continuous open map is an open topological embedding, and that in an open subspace of a spectral space the intersection of any two quasi-compact opens is quasi-compact. Therefore, the required map can not exist.


Alternative to \large, \Large, \Huge, \small etc in ConTeXt

Question: Are there simple alternative of these font sizes in ConTeXt? Or one needs to use some special module? I looked at this page here. It seems to be a lot of boilerplate of such a simple task.
Comment: Yes, there exists some by default, see [the ConTeXt wiki about font switching](http://wiki.contextgarden.net/Font_Switching).
Comment: You can change font sizes with `\tfa`, `\tfb`, `\tfc`, etc. or e.g. with `\setupdodyfont[18pt]`. If that doesn't suit your needs please add more details and explain what exactly you want to do.
Comment: @Marco Thanks. This almost does what I want. You can add this as answer. Some newbie like me would be able to search it easily.
Answer: You can change the font size for the entire text using
\setupbodyfont:
<code>\setupbodyfont [18pt]
</code>
If you want to change the font size of a smaller part of the text
you can use the following constructs:
<code>{\tfa large}
{\tfb even larger}
{\tfc huge}
</code>
Or if you prefer absolute values:
<code>\switchtobodyfont [16pt]
</code>
For more details see the ConTeXt wiki - Font switching → Font sizes.


Without using sharing rules how can i share records to another user?

Question: Without using   sharing rules   how can i   share   records to  another user?
Comment: Why can't you use sharing rules? What are you trying to do, specifically?
Answer: For automated sharing, where possible it is far easier to use Sharing Rules than other forms of sharing. If you really cannot use Sharing Rules, there are options such as Apex Sharing, though these require explicit coding to support them and, if you want to make it possible to support this approach regardless of the Org Wide Defaults for sharing, you have to be careful to use entirely dynamic DML when creating or deleting the sharing records since the sharing record objects only "appear" in your org when OWDs are not Public Read/Write.
Of course, if you are not automating this, your users can now use manual sharing even in Lightning Experience.
See the documentation for more details on the various forms of sharing.
Comment: Thanku...By using Apex Sharing I have done this..


Which styling should the field have, once a value has been chosen?

Question:
I'm working on the input style for a dropdown field, and I have two options for once a value has been selected. The default field state is shown at the top, which has the same border color as the empty state. The second option has a border the same color as the value. Which version communicates better?
Comment: Not sure I understand the question. Can you reformulate?
Comment: I think this still qualifies as a UX question, because this is mostly an input state issue.
Comment: It qualifies now that it's been edited from its original state.
Answer: Consistency is at the center of good UI design
Unless there's a good reason to, the weight and color of the text and the thickness of the input border of a dropdown selector should be the same in all states.
In your case, graying out the text in the "no value" state risks the field being mistaken for one that is disabled, and increasing the thickness of the border could be distracting and increases the risk of technical issues with the layout of your form.
The age old aphorism applies here:
KISS (Keep it simple, stupid)
Answer: To me, option 1 is stronger, but your default empty state still suffers from its lack of contrast. It might be mistaken for a disabled state. I suggest making the text a bit darker.
Your second option gives the impression a bit too strongly that the input field is currently in focus. You should reserve border changes (color) to communicate errors and activity.
If you really want to make it obvious something has been selected, you can opt for a checkmark next or inside the input field. If you are worried that people will think it's pre-filled, you can make use of smart defaults.


How fast was All Might?

Question: In the battle with One for All, All Might ran 5 kms in 30 seconds, that means running at 600 km/h. But All for One told him he was slow. Are there references how fast was All Might in his prime, at least an estimate?
Answer: That's actually the only information we have on All-Might's speed.
That scene you're referring to occurred in Chapter 90, which tells us that All-Might ran 5 kilometers in just 30 seconds, giving him a speed of about 600km/hr.
If I recall correctly, this is currently the best estimate we have of All-Might's speed at his prime, because we know he's faster than that. Only thing to do is wait for new chapters that give additional information.
Answer: All for One says "it's only five km from the bar to here and yet it was at least thirty seconds after I sent the Nomu that you arrived" meaning it took him 30 seconds to defeat the Nomu and then make his way to the bar.
For the record, he fought the Nomu for about 20 seconds and talked to Endeavor for about 6 seconds. Now you should be able to get a more accurate speed
Comment: Strong language is usually not accepted on SE sites.

How fast was All Might?


Difference between conjugated and te-form listed verbs? 「置いて行かないで下さい」

Question: I came across the phrase「置いて行かないで下さい」. I am unsure as to whether this means "please do not leave it there", or "please put it down and don't leave". I'm thinking it's the first one, and that if it was the second it would be written as「置いて、行かないで下さい」, or maybe something else? Or am I way off with both?
Comment: 「置いて、行かないでください」を "Put it down, and don't leave." って解釈する場合/状況ってある・・・?
Comment: 「置いて行かないで下さい」.  could also mean "Please don't leave me here."  (Please take me with you) -- i imagine a melodramatic scene in a train station or airport (Casablanca).
Answer: 行く after the te-from of a verb will almost certainly be parsed as a subsidiary verb, so 置いていかないでください means "Please don't leave it/me/him/etc here". And even if you put a (Japanese) comma after 置いて, people would still parse it in the same way. That comma is nothing more than a small pause between words. For example it may just mean the speaker said the sentence slowly and clearly.
To absolutely break the link between 置いて and 行く in written language, you need a (Japanese) period.

置いて。行かないでください。
  Put it down. Please don't go.
Answer: <code>     「カネオクレタノム」   <---   電報で有名な笑い話
</code>
I think you're right on-point on everything you said.
This enrty (below) used to be huge, until the WP-police ("the downvoters") censored it.

ぎなた読み  ---  https://ja.wikipedia.org/w/index.php?title=%E3%81%8E%E3%81%AA%E3%81%9F%E8%AA%AD%E3%81%BF&oldid=46603070
   1. 「今日は、雨が降る天気じゃない」   と
     2. 「今日は雨が降る、天気じゃない」

( I think both utterances are possible in casual speech. )

Today is [ not the kind of weather in which it rains ]
It's (going to be) raining today ;  it's not good weather

<code> ■ ぱんつくった    ( パン作った / パンツ食った )

 ■ ねえちゃんとふろはいった?  ( ねえ、ちゃんと風呂入った?  /  姉ちゃんと風呂入った? )
</code>
Comment: Does this mean that the first sentence has a different meaning? While the second means "It's raining today, it's not clear weather"?


On Macbook Pro with 2 HDMI monitors, is it possible to associate the USB-C/HDMI with a desktop/monitor?

Question: On Macbook Pro with 2 HDMI monitors via 2 USB-C/HDMI adapters. I have multiple desktop's on each display. The macbook itself always has the same desktops on, but my two HDMI monitors periodically/randomly switch their collective desktops.

So all of the desktops on the right monitor will be displayed on the left, and vice versa.

This happens at times like, disconnecting and reconnecting to the monitors, not just randomly as you're typing. But it doesn't happen every time you disconnect.
Q: Is it possible to associate the USB-C/HDMI with a desktop, so that monitor 1 will always have the same content?
Note: Rearranging the order of displays in "Built-in Retina Display" is not a solution. As the adjoining monitor edges then change from 1L/2R to 2L/1R so mouse overs are the opposite side of monitors.
Answer: Unfortunately it is not possible. It is a bit of "hit and miss" when you have these situations. You can sometimes replug the cables and get the desired order, but it is not foolproof.


Is it an obligation to be a Brahmin to study advaita vedanta?

Question: Is it an obligation to be a Brahmin to study advaita vedanta ?
Comment: Well depends on what you mean by study exactly.
Answer:
For the Brāhmaṇas he ordained teaching, studying, sacrificing and officiating at sacrifices, as also the giving and accepting of gifts. (Manu Smriti 1.88).

Also,

Teaching and studying, offering sacrifices and officiating at sacrifices, and giving and accepting gifts are the six occupations of a highest-born person. - Manu Smriti 10.75

Now, the question is what we mean by studying. Commentator of Manusmriti - Medhatithi did not throw any light on it. However, this has been made explicit in other Smritis.

The duties of the Brāhmaṇa are six: studying the Veda, teaching, sacrificing, officiating as a priest for others, giving alms and accepting gifts. - Vaśiṣṭha 2.13-14

Every twice-born one is entitled to prosecute the study of the Vedas, to celebrate Vedic sacrifices and to practice charities. Of these, teaching, the celebration of religious sacrifices (for others), and acceptance of gifts are functions which specifically from the right of a Brahmana. - Gautama 10.1-3

Thus, you see that studying Vedas is an obligation, but studying specifically Advaita Vedanta is not an obligation. Just to clarify, Advaita Vedanta interprets Vedic texts in a specific way. But there are other interpretations as well (For example, Dvaita Vedanta etc.) Which interpretation you would read depends on your likings.


Acquiring French citizenship

Question: My father was a French citizen. I have his old passport and his livret de famille. He left France in the 50s, and I was born in 1970. He died 5 years ago. I've been told that I lost my claim for citizenship because I didn't demand for it until now and I'm already 53. Is there a way to bypass this article?
Comment: Did your father record your birth in the French civil register? https://en.wikipedia.org/wiki/French_nationality_law
Comment: Can't log in to my old account. I'm not sure whether my father got his own livret de famille and if he ever registered me as his daughter, the one I found are my grandparents' and he is written in it.
Comment: When was his last passport issued? Whether it was more than 50 years ago could be relevant.
Comment: @Traveller I don't think it matters here. The language in the Wikipedia article ("is essential") is way too strong and contradicted by the rest of the paragraph. Besides, the facts do not seem in dispute, the main issue is whether the OP may still benefit from a French citizenship after 53 years, which may be impossible *even if the father registered her birth and got a livret de famille at the time*. The way I understand the situation, the most important fact (and what's missing from the question) is whether the father did maintain *possession d'état* more recently than 1970.
Answer: The law says if either the parent(s) with French citizenship or the child did not maintain proof of French citizenship within the last 50 years (vote, apply for/renew a passport), the child is not eligible for French citizenship.

Lorsqu'un individu réside ou a résidé habituellement à l'étranger, où les ascendants dont il tient par filiation la nationalité sont demeurés fixés pendant plus d'un demi-siècle, cet individu ne sera pas admis à faire la preuve qu'il a, par filiation, la nationalité française si lui-même et celui de ses père et mère qui a été susceptible de la lui transmettre n'ont pas eu la possession d'état de Français. Le tribunal devra dans ce cas constater la perte de la nationalité française, dans les termes de l'article 23-6.

Basically you lost your right to French citizenship when you turned 50.
Source.
I saw somewhere, can't find it now, a proviso whereas a child in your situation might be able to acquire French citizenship if he/she has maintained links with France, speaks French, etc. But that's of course a tall order.
Comment: Actually, the source doesn't support your interpretation. These cases hinge on subtle details of the conditions, even under the ministry's somewhat restrictive interpretation, if the father did get a passport more recently, it is not obvious to me that the OP couldn't apply for one now.

Acquiring French citizenship


Classic Achronim and Rishonim

Question: People often say they learn Shas with Achronim and Rishonim. I'm curious, what are the mainstream Rishonim and Achronim that are generally learnt throughout Shas?
Comment: wouldn't the basics be the ones included in a printing of a gemara?
Comment: It's not opinion based. It's more or less become a fact. But I'm not sure what that fact is. So enlighten me please, thank you.
Comment: Somewhat related: https://judaism.stackexchange.com/questions/62100/what-texts-are-studied-in-a-traditional-yeshiva
Answer: It depends on the person, but the most common that are on most masechtos are:
Rishonim: Besides Rashi and Tosafos: Rif, Ramban, Rashba, Rosh, Ran, Ritva, Tosafos HaRosh, Nimukei Yosef.
Acharonim: Maharsha, Pnei Yehoshua, R' Akiva Eiger, Chasam Sofer, Rashash, Aruch LaNer, Toras Chayim, Kovetz Shiurim.
Also there are often major works that are only on a few masechtos, but are used pretty frequently there. For example, Hamakneh on Kiddushin, Hafla'ah of Kesubos, Turei Even, Yashreish Yaakov and Kovetz Hearos on Yevamos, Nachalas David.
This is not meant to be an exhaustive list. I am sure that there are many others deserving to be on this list.
Comment: Is Rabbenu Elyakim, Meiri, Rabbenu Peretz, Tosfos HaRid, mainstream?
Comment: Is Ben Yehoyada Mainstream?
Comment: If by mainstream you mean accepted, yes. However, if someone said he learns with Rishonim and Acharonim, I wouldn't assume he necessarily meant them. As far as Ben Yehoyada, it is written on Aggadic parts of Talmud, and the people in your question tend to focus on the halachic parts of Gemara.
Answer: This is a list of mainstream mefarshim. This doesn't mean people learn every single peirush they said. Maybe every Tosafos and Rashi. But not the rest.
Reishonim.
Rashi. Tosafos. Shita Mikubetzes. Rashba. Ran on some meschtas.These are most common.
Others are still mainstream though. Like Ramban. Rosh. Ritva. Tosafos Rosh. Tosafos Rabeinu Peretz.
Achronim mainstream.
Maharsha . Maharam, Pnei Yehoshua.

Classic Achronim and Rishonim


Why would a cake mix call for the same number of whole eggs or just whites?

Question: I have a Betty Crocker white box cake mix and the box says to use either three egg whites or three whole eggs. This doesn't make sense to me: if I used whole eggs wouldn't I use less, more like one and a half?
Answer: Think of the recipe as needing 3 egg whites, and optionally 3 egg yolks. Often if you have a cake mix that calls for oil, somewhere on the package will be a "light version" which is the very same additions and quantities, just not the oil. No extra water or milk or whatnot to make up for it.
The liquid volumes for most cake mixes are not as precise as they seem. Just leaving out the egg yolks, or just leaving out the oil, doesn't require adding some other liquid to make up for it. The cake may end up with a slightly different texture, but it will still be cake.
Answer: Well, as it turns out, no...
I don't know where you are from in the world or what eggs you are using, but I found a scientific paper that studied the ratios of egg components over age in Leghorn chickens (the type Foghorn Leghorn is named for) in the USA (Ahn  et al., 1997 you can read the abstract for free at the link, I can access the full paper). It seems that:

When calculated on the basis of interior contents, 65% of egg content is white and 35% is yolk.

But, what you are getting from the egg in this case, is not the water/volume that matters, but instead it is the protein content that is critical. Eggs overall are about 88% water:

The major constituent of egg white is water, approximately 88% of total
weight.

However, protein makes up:

The total solids content of white is approximately 12%, and protein is the major component of the solids at 11%... the major constituents of yolk are
protein (16%) and lipid (32%).

So, by adding the whole egg you are getting a little extra protein (16% of 35%) relative to using just the white alone. You also get a bit of extra fat (lipid), but in such small amounts it won't matter for the recipe and calorifically is pretty insignificant compared to the cake mix itself.
Edited to add:
You might also be concerned about the water content of the eggs, though you are most likely also adding either milk or water to the boxed mix. I had a look at a couple of recipes from the Betty Crocker site and it looks like somewhere between 1 and 1.5 cups (USA measurements as Betty Crocker is a USA company) of water/milk per box, depending on the recipe. This is equivalent to 8-12 fluid ounces (240 - 360 ml).  A large egg is about 46 ml (3.25 Tbsp), which is a reasonable amount of extra liquid, but the yolks being about 50% water and only 30% of the volume only adds about 15% extra  (20 ml or 1.3 Tbsp). The fat content of the eggs is also insignificant compared to the oil added in the recipes.
Ref:

Ahn DU, Kim SM, Shu H. Effect of egg size and strain and age of hens on the solids content of chicken eggs. Poult Sci. 1997 Jun;76(6):914-9. doi: 10.1093/ps/76.6.914. PMID: 9181628.


$\int_0^\pi{d\theta\over(a-b\cos\theta)^2}={a\pi\over (a^2-b^2)^{3\over 2}}$

Question: Show that $$\int_0^\pi{d\theta\over(a-b\cos\theta)^2}={a\pi\over (a^2-b^2)^{3\over 2}}$$ where $a>b>0$. I'm not sure how to simplify this integral or evaluate it. Any solutions or hints are greatly appreciated.
Comment: With all due respect I think you ask lots of questions but you don't seem to be willing to show what did you attempt. This is important because that way people can focus on your particular problems and also because many people here expect you to show some effort.
Comment: You should also start accepting (at least some of) the answers that the MSE community kindly provided you.
Comment: @JackD'Aurizio Jack, thank you for having the courage to post this comment.   If I had a dollar for every answer posted for which neither others who posted solutions nor I received any up votes, well ... you know the rest of this... ;-)) -Mark
Comment: I'm sorry everyone. I will heed your advice.
Comment: This integral is Kepler's third law! It's the situation for which the eccentric anomaly $$\sin E=\frac{\sqrt{1-e^2}\sin\theta}{1+e\cos\theta}$$ was invented. In terms of $E$ with $e=\frac ba$ the integral transforms to $$\frac1{a^2(1-e^2)^{\frac32}}\int_0^{\pi}(1-e\cos E)dE=\left.\frac{a}{(a^2-b^2)^{\frac32}}(E-e\sin E)\right|_0^{\pi}=\frac{\pi a}{(a^2-b^2)^{\frac32}}$$
Answer: HINTS:
Note that $$\int_0^\pi \frac{1}{(a-b\cos(\theta))^2}\,d\theta=-\frac{\partial}{\partial a}\int_0^\pi \frac{1}{a-b\cos(\theta)}\,d\theta$$
Then, evaluate the integral on the right-hand side using either the classical Tangent Half-Angle Substitution or use contour integration.
Comment: @derpmagoo Please let me know how I can improve my answer.  I really want to give you the best answr I can.  -Mark
Comment: My knowledge of integration is pretty elementary. I have never seen this before. I'll have to read that link. Thank you.
Comment: Derp, may I ask respectfully, "If your knowledge of integration is pretty elementary, then why are you tackling integrals such as the one here?"  While this can be handled by elementary methodologies, this might not be the best place to start.  ;-)) -Mark
Comment: Dr.MV: +1 for giving a good hint and not the answer.
Comment: @RRL Thank you!  Much appreciative.
Answer: Under the assumption $a>b>0$, let us start with:
$$ I(a,b) = \int_{0}^{\pi}\frac{dt}{a-b\cos t} = 2\int_{0}^{\pi/2}\frac{dt}{(a+b)-2b\cos^2 t} $$
that through the substitution $t=\arctan u$ becomes:
$$ I(a,b) = 2\int_{0}^{+\infty}\frac{du}{(a+b)(1+u^2)-2b}=\frac{\pi}{\sqrt{a^2-b^2}}. $$
Our integral is just $-\frac{\partial}{\partial a} I(a,b)$, hence it equals $\frac{\pi a}{(a^2-b^2)^{3/2}}$.
Comment: Now this looks a bit familiar ... ;-))


Is there a reason for even trying to make tires last

Question: I've always believed in rotating the tires, makes them last longer, sometimes by a lot. When they crisscrossed them. Why do they now only make directional tires that they say can't be crisscrossed. Is the tires going to know? Why rotate to the same side, what good is that?
Comment: "only make directional".  I don't know who "they" are, but none of my vehicles have directional tires.
Answer: The main wear for tires comes from the front end. This is due to two reasons. First, this is the turning axle. The geometry changes on these tires quite a bit. When going through corners, the weight of the vehicle pushes much harder on these tires, which creates more wear than what occurs in the back. Secondly, with front wheel drive cars, which are a lot of cars on the road today, the forces employed due to forces involved with locomotion create more wear. The rear tires, by contrast, mainly just stay in line with the vehicle and get pulled along. When you change them front to back, you are trying to even the wear out between what happens front to back. This way, when the time comes, all four tires are worn evenly instead of the front tires being worn out and the back tires having another 10k miles left on them.
As far as crisscrossing tires as they used to do, the reason this isn't done anymore is not because a tire is directional (that matters too, but it's not the main reason), it's because they're radial. Way back in the day they had biased ply tires. This meant the belts which surround the tire (under the rubber) went around the tire, then had overlapping layers that went perpendicular or side to side. These tires could be ran either way without issue. With radial tires, the belts are laid crisscross or on diagonal. Once these start rolling in a particular direction, they like to stay rolling in the same direction. If they are put on the car backwards from this direction, the belts will tend to separate and destroy the tire. (Please note: You'll get people who will say they rotate them crisscross all the time without issue ... maybe they do, maybe they don't. I'm not judging.)
Comment: But if you take a tire from the back right, and put it on the front left, it'll be rotating in the opposite direction as it was before. Or do they actually take the tire off of it's hub and put it on "backwards"?
Comment: @Shufflepants - They actually don't do (or shouldn't do) either. Most reputable places will only rotate them front to rear, unless there's a full sized spare which may get thrown in the mix. If they are putting from rear right to front left, this is considered "criss cross" and shouldn't be done with radial tires, even if they have omnidirectional tread. What Solar Mike says in his answer is correct as well.
Comment: ♦ Oh, I misread the answer. I thought it was saying that they specifically did crisscross for radial tires; that radial tires were the reason for doing it crisscross. I thought the antecedent of 'they' in "Way back in the day they had biased ply tires." was the radial tires referred to in the previous sentence; saying that radial tires back in the day were biased ply.
Answer: Because the tread pattern is designed to optimise the ejection of water for example and if you have them rotating in the wrong direction this won't work as well.
Early design of tyres was simple : a block tread pattern, but patterns now are designed to deal with specific issues : winter tyres, mud & snow etc


Do US universities with rolling admissions evaluate an application only when they receive all the recommendation letters for that application?

Question: I recently submitted an application to a PhD program at one US university. One of my former professors, however, who initially agreed to recommend me, have not yet submitted to the university her recommendation letter for me. Fortunately, two of my other recommenders already submitted theirs. My question is - if the universities with rolling admissions evaluate applications as early as they receive them, does that mean that they will not evaluate applications with one missing recommendation letter?
Comment: Have you asked this question to the university that you applied to as well? Because if anyone knows for sure it is them.
Answer: I find the practice of rolling doctoral admissions in the US to be pretty unusual. Normally decisions are made by committees who meet to make decisions. But it isn't impossible.
However, it is impossible to make precise statements about policies of "all" US universities as they normally make their own policies. Even within a given university, such policies might vary by department. There is no national higher education system, and even within an individual state there is no system containing all universities. There are regulations, of course, but no national system.
I'd suggest that some universities will act on incomplete applications without prejudice. This is independent of the rolling admissions question. Admissions is generally based on a broad measure of the student's likelihood of success. Letters of recommendation are relatively important, but it is common enough that they don't arrive in time for a decision.
The danger with rolling admissions, for the student with an incomplete application, is that other students are being considered and eventually the maximum number of admissions might be reached, even if it isn't a hard number. But, if everything else spells "success" then an early decision might be made. It is up to the committee at that university, to decide.
Comment: (+1)    At my university, applications were sent to the graduate school, with requisite fees. Only when the application was deemed complete by the grad school did the packet get forwarded to the relevant department for consideration by their grad admissions committee. We never saw incomplete packets or status reports on such packets. If an applicant contacted us, they were referred to the graduate school for information.


Move body to mouse click and stop

Question: I'm trying to have a body move to the player touch and stop once he reaches the destination. I have the player boxed in to prevent him to move out of bounds, I can somewhat do that with translate but with collision, it doesn't work properly, is there a better solution for this?
Comment: Needs more detail. Is your game side-view or top-down? Is there gravity, or friction, or other objects in the way?
Comment: I agree with Anko, there's too little detail here. Anytime you say "it doesn't work" you *absolutely must* describe **in what *specific* way** does it not work? This could be anything from "the body hitches or stutters in its movement" to "the body moves to the wrong place" to "the body does nothing" to "the body disappears" to "the game crashes and my computer catches fire" - so you see why we could use some help narrowing down the problem. Remember that none of us has ever seen your game, so something that may seem obvious to you won't be clear to us unless you include it in your question.
Comment: Have you considered using a mouse joint? I think it could do the job depending on exactly what you mean.
Answer: Once you have the destination determined, it can be done in two popular ways:

Tweening. That is the most simple way of transforming an object to a
destination in exact N seconds with the ease algorithm of your
choice. Most tween engines has path feature to allow you to put    checkpoints on their way, so you can take a longer path.
Physics. You can control your player navigation code to help it reach to the destination and continue to control or apply force
(in case there is a friction). Finally, once arrived (collided), remove all forces/controls.

If your scene is complicated and your player has to make decisions on the road, then AI is your friend.
Answer: First, you need to define a bounding box around your player. This is what actually collides with the outside. To try to calculate collisions with every pixel of your character, your CPU would put you in the realm of terrible FPS. Since you are programming in Java, I would recommend looking into the java.awt.Rectangle class. You can simply define one rectangle as your "out of bounds box" and one rectangle around your player, and use outOfBoundsRectangle.contains(playerRectangle) to check if the player is in bounds.
What if your bounds isn't a simple rectangle?
The "contains method can also apply to single points. Just if your player's bounding box contains any points in your out of bounds shape.
What if that is taking too long/too much processing power
If you have a lot of points in your out of bounds shape, the above method will be too tedious. You can try dividing up a larger shape into smaller rectangles that can be checked for collisions.
The best way for working with a complicated boundary is by making it into a java.awt.geom.Path2D - a class that defines a set of points with lines between them. Using methods in this class, you can check for intersections between the path and your player's bounding box. You could also create a bounding path for your player for more complicated collisions.
Edit:
I'm not sure whether you are writing code for 2D or 3D. What I gave you above only works in two dimensions. For three dimensions, I believe libgdx has a BoundingBox class that works in a similar way to what I described above. It can also replace the Rectangle class if you define the BoundingBox as only having two dimensions. The BoundingBox is defined by two "Vector3"s, another libgdx class that just stores a 3D vector. Again, you can make this 2D by setting one of the vector dimensions to 0.
As for clicking and having your player move to that point, that should be done by frames in your update method. I'd recommend looking at this site for some easing equations, but a linear equation will work fine for a basic game:
Some easing equations
Comment: Interesting answer but I am not sure it answered OP's question

Move body to mouse click and stop


How can I download a complete image of my DO VPS to an image for a VM over SSH?

Question: There isn't a way to download a complete image from Digital Ocean VPS hosting through their web UI. How can I download an entire image of the VPS that I can use locally on a VM or upload to another VPS later on? Can this be done via SSH or SFTP? Im running Debian 6.
Answer: You can use rsync to essentially clone the whole system via SSH while running.
You create the local VM with the specs you need, install a minimal debian (same version) with the same partitioning schema as your VPS and then boot into a live CD (ubuntu-desktop has pretty much anything you will need).
Then from the live CD you mount the partition(s) to a temporary location (eg: /mnt) and then you run something like this to clone the whole VPS to your local VM keeping all permissions intact.
rsync -aAXv --progress --stats --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} root@YOUR_VPS_IP:/* /mnt/

Make sure to exclude paths that you don't need to clone. The above paths are standard paths that need to be excluded for a successful rsync.
Depending on the virtualization platform the current VPS runs on you might need to fix some paths or files (eg: Partitions' UUIDs on /etc/fstab and/or GRUB config).
You may also need to (re)install the boot loader.
And of course you will need to update the network information so that the newly cloned VM is accessible over the network.
Comment: Sounds like it would be easier to re-configure a brand new node from scratch. How is there not an easier way when we have tools like vagrant now!
Comment: If you know what you are doing, cloning a system like this is waaaay easier and faster than re-installing everything from scratch. Not to mention the fact that by cloning it, when it actually boots OK then you won't have to worry about any issues since it's the exact same installation with the exact same config. Doing a re-install from scratch is bound to cause issues (a setting here, a forgotten config there an so on and so forth). Since you mentioned Vagrant, if all this is a dev box, then I guess re-installing everything is not a problem. For production systems though I wouldn't re-install.
Comment: Btw the only reason I mentioned to first install a vanilla Debian and then essential overwrite the installation with rsync is to avoid manually creating the partitions and the boot loader. You could of course do it all the way manually if that suits you better (and it's actually faster this way).
Comment: Could I also use rsync to sync a local image to a new VPS over ssh? Its been do long since I setup the VPS, ive had to configure so much custom stuff, I cant believe Digital Ocean don't have a download option.


Arduino emulating a keyboard that has a demultiplexer

Question: I have a old typewriter which I want to automate with an Arduino. The way I am trying to do it is to replace its keyboard with the Arduino and make the Arduino emulate the keyboard IO.
The keyboard of the typewriter is using a 74154 demultiplexer. The original keyboard setup has:

4 pins mainboard outputs > demultiplexer input
8 pins demultiplexer output > switches > mainboard inputs

My plan so far:

remove the keyboard (so also the demultiplexer) completely
the "8-pins" demultiplexer output > switches > mainboard inputs
replace them with Arduino digital INPUT pins > mainboard inputs
the "4-pins" mainboard outputs > demultiplexer input
replace them with mainboard outputs >  Arduino analog INPUT pins
constantly read data from 4-pins
depending on their value (0001, 0101, 1011, etc) I would know which row is being "scanned" currently
if I need to type a character from that row - I would set an appropriate pin from the 8-pins to OUTPUT LOW and turn it back to INPUT after some milisecons *1

Where I am stuck:

If the previous are correct, it would mean that at any time that I "ping" any pin from the 8-pins, it should type on random character
What happens is - it types 6 specific characters depending on which one from the 8-pins I "ping"
Extra note: I can set for how long to "ping" the 8-pin and I have tried different values down to 1 ms which does not trigger anything.

Notes:
The 8-pins being set to INPUT as initial state and being set to OUTPUT LOW for triggering, because of what is mentioned here in the second paragraph.
Update 1:
Instead of:

the "4-pins" mainboard outputs > demultiplexer input

replace them with mainboard outputs >  Arduino analog INPUT pins

I now did

the "4-pins" mainboard outputs > demultiplexer input
replace them with mainboard outputs >  Arduino DIGITAL INPUT pins

Because the values being read with analog input are not absolute at all, so I left the decision making regarding LOW/HIGH input on Arduino's digital input.
I created a sketch of the circuit, which can be found here.
Y0 and Y8 connect to modifier buttons (like shift, bold, letter spacing, etc) and IIUC that's why they are also connected through diodes to mainboard input pins 2, 6, 10, 12, 14, and 16. Because the typewriter has "record and re-print" functionality, when it's being done - those modifier buttons are probably disabled so you can not invervene with styling options.
And some **graphs of the input that I receive from the mainboard.
Regarding what phil-g commented, if you have a look at the graphs you will see that the enable pins are triggered rarely at (random?) moments.
Regarding what hacktastical answered, I think it is on the correct path, but I struggle to detect the strobe.
Current situation:
I changed my timing library to a more precise one, and set the "input detection" timing to 0.1 ms.
So far I have managed to print a random single character, but at totaly random moments by sending OUTPUT LOW of 1 ms duration to a mainboard input pin. Usually it still prints 6 characters.
My current questions/problems:

How to detect / understand which of my inputs from mainboard signify the strobe?
Also regarding the strobe, in the bit sequence that hacktastical included in the answer, if the outmost right column leads to 6 buttons and one of them is pressed, wouldn't it mean that mainboard would detect LOW when row 0 is scanned, and HIGH all the other times no matter if stobbing or other row being scanned?
If the previous is correct, doesn't it mean that I should not care about the strobe? As that column will output 1 0 1 1 1 1 to specific mainboard input and all the other columns will not output anything to any mainboard inputs because their buttons are not pressed.
Since columns are connected to buttons and then to mainboard input, when no buttons are pressed, it means that no current is passed to mainboard inputs. So in this situation I am setting the Arduino pins to INPUT is order to act as disconnected. Does that sound OK?
My computation of the demultiplexer output shows that also Y10 - Y15 are being triggered quite often, but they are not connected to anything. So why doesn't the mainboard try to trigger only Y0 - Y9?
Comment: Are the enable pins being momentarily pulsed low after establishing the input to the demux? You'd likely do that to avoid spurious outputs while changing the input.
Comment: The circuit sketch link is reporting as broken "Sorry, the file you have requested does not exist.".  Why not upload it here?
Answer: The demultiplexer is selecting the row. The select inputs probably run continuously, cycling through each row one-by-one. The E0/E1 inputs are probably pulsed so that the outputs show one low bit with a blank in between.
So you get a sequence like this from the mux:
1 1 1 1 1 1 1 1 - idle
1 1 1 1 1 1 1 0 - row 0
1 1 1 1 1 1 1 1 - blank
1 1 1 1 1 1 0 1 - row 1
1 1 1 1 1 1 1 1 - blank
1 1 1 1 1 0 1 1 - row 2

etc.
Seems like you have to do two things:

follow the row-scanning activity from the host. That is, watch the mux select state
output the column bit when the correct row 'comes around'

If they're strobing the row-select (as I suspect they are) you would also follow that, only outputting the column bit when the row bit is low, otherwise outputting all 1's for column.
As you have access to the mux inputs (4 bits, 16 rows) you can use them directly and reduce the number of Arduino I/O needed from 24 down to 12, or 13 if you need the strobe.


One or more network protocols is missing on this computer

Question: I just rebooted my Windows 10 PC, tried to connect to the internet and got a message saying "One or more network protocols is missing on this computer". The Windows troubleshooter is unable to fix the error. I have not changed the laptop at all and certainly haven't changed any protocols. How do I fix the error?
Comment: I'm voting to close this question as off-topic because the OP writes in a comment on the accepted answer that the system fixed itself (an apparent hiccup), so the problem is no longer reproducible.
Answer: Go to Settings -> Network & Internet -> Ethernet (I don't use Wi-Fi so if Wi-Fi is an option, try it) -> Change adapter options -> Right-click the one you are having issues with -> Properties -> Install... -> Protocol -> Install all the protocols there.
Comment: Thanks for the answer but the issue seems to have sorted itself out. A restart didn't help, but something has fixed it??? :/
Comment: I have accepted anyway as it seems like the answer will fix other user's problems when they have the same issue :~)


Classical Style vs. Modern Innovation

Question: For some time now, the matter of classical versus modern writing has weighed heavily in the discussion of my mind-congress. Here is my thought: given the sheer reverence that is given to classical pieces of writing by large associations, I, as a high school student in the United States, have been exposed largely to this style. However, over time, I have come to realize that often times, though it may be by artistic choice, many lapses in syntax and diction can be found in classical literature and prose. And do not misunderstand me; I value and appreciate classical pieces and revere them as many are masterpieces. But, given the advancement and rigor of the education of the English language to those who may pursue it here in the States, would an aspiring writer such as myself utilize that literacy to craft new styles, or attempt to replicate the styles of the 17th and 18th centuries, but still with personality?
Comment: What's a 'mind-congress'?
Comment: @Spagirl It's an attempt to use the 17th/18th century style which the OP wants to write the book in. :)
Comment: I'd still like to know what the OP thinks it means. I've tried looking it up, but am none the wiser.
Comment: It is simply an allusion to the common confliction that comes to mind when thinking of Congress but linked to my thought processes instead.
Answer: You should only attempt the style of the 17th/18th centuries if you're writing some kind of pastiche or mimicry of a book written then — for example, a Sense and Sensibility and Dragons kind of thing. CE Murphy did a reworking of Pride and Prejudice and added magic to it, using a  style similar to Austen's but without strangling herself with her own sentences.
However, modern readers can find this convoluted structure and stately diction hard to follow, so I wouldn't try to replicate it precisely. Approach it, but aim for clarity.
And honestly, if you do use this kind of style, be aware that it's a gimmick, and treat it accordingly. It will narrow your audience. You may find a deep niche audience (readers who love Regency romances, for example), and devoted niche readers are not to be taken lightly, but that kind of writing will not get you broad acclaim or sales.
Answer: Centuries don't have styles; writers have styles. True, there are certain broad features of the way things are written which change over time, but they are very much secondary to the styles of individual authors. And diction and vocabulary are only a small part of what constitutes an author's style. Austen's cool ironic detachment is a much a hallmark of her style as her diction and vocabulary, and you certainly would not mistake her for any of the Brontes.
Nor would you mistake writers of the 17th century from those of the 18th or those of the 18th from those of the 19th, etc. There is a marked development of fashion in literature from one centry to another, which continues into the 21st. These fashions have as much to do with weltanschauung as they do with the use of language. The relationship between character, narrator, and reader, for instance, is a far more distinctive part of the evolution of storytelling fashion over the course of the 20th century, reflective of a larger social trend of descent from confidence into doubt about the reliability and objectivity of human judgements.
A writer today who wanted to emulate Austen would come closer to their intended effect if they focused on emulating her confidence, irony, and wit, than if they focused on her diction and vocabulary. Indeed, the effect would be far more convincing with the former focus than the latter. Imitation of the diction and vocabulary without the fundamental authorial stance will sound like a painful pastiche, almost mockery.
The key stylistic fashion of the later 20th and early 21st century literature has nothing to do with vocabulary and diction. It is the withdrawal of the authorial voice; the refusal of the author to speak directly to the reader in any manner. Partly this is the influence of the movies at work, and partly it is our artistic lack of confidence showing through. It is the author's voice shining through, more than anything else, that strikes us as foreign about the classics of the modern era.
Comment: I appreciate this input, I had not thought of it in this way.

Classical Style vs. Modern Innovation


How to deal with soil erosion under slab floor of garage?

Question: There is a small crack extending 10 feet down the center of the slab floor of my garage.  The floor sounds hollow when I hit it with a 2x4.  Also, there is a 4" water drain and I can feel air when I put my fingers under the slab.  It seems the soil under the slab floor has eroded away.  There is a high water table in my neighborhood. Most of my neighbors get water in their basements, but I do not (yet?) The crack does not seem to  have gotten worse over the 5 years I've lived here.  There are bedrooms over the garage.  What, if anything should I do about the floor of my garage?  Thank you.
Answer: It doesn't look to me like the slab has shifted, since the crack appears level and isn't terribly wide.  I would contact a concrete contractor, one that specializes in repairs, if there is erosion under the slab they can usually pump a slurry under it to fill in the void. Is your garage floor "Floating"? Look around the edges, if the floor goes under the walls, it's part of the support of the building and you want to consult a professional immediately. If the floor butts up against the wall, it's a "floating" floor and isn't part of the structure, however you may still have erosion under the wall footing, and I would still consult a professional, however a floating floor will be easier for a contractor to break up, install proper drains and such so it won't erode underneath again, and re-pour.
You could get an endoscopic USB camera from Amazon for about $20 that you could probably snake under the slab and inspect it, but I would consult a professional. Most of these types of things are cheap to fix now, but could end up costing thousands to fix later.


Link to second local html file with PhoneGap

Question: I want to switch from the index.html file to a second html file called projects.html in a PhoneGap App on Android. If I write something like Second Page the projects.html page opens, but I get a prompt "[]" and then "usePolling" and then "getPort". In adb logcat the error "D/PhoneGapLog( 3288): file:///android_asset/www/phonegap.0.9.6.js: Line 810 : JSCallback Error: Request failed." appears. Looking around on the internet using multiple html files seems to me to be some kind of an issue with phonegap. Any ideas how I could get this to work?
Answer: As a solution for this problem, you can either edit phonegap.0.9.5.js and comment out all lines that contain the prompt() function (there are six lines).
Or you download PhoneGap 0.9.4 (PhoneGap 0.9.4 doesn't use the prompt() function), extract the phonegap.0.9.4.js file from it, delete phonegap.0.9.5.js from the assets/www/ directory and place phonegap.0.9.4.js in the assets/www/ directory instead.
Answer: I changed to phonegap version 1.0. This fixed the problem.
Answer: It also happens if you create a PhoneGap Android app following Quickstart page http://wiki.phonegap.com/w/page/30862722/phonegap-android-eclipse-quickstart
Answer: Not sure if you have a solution to the above but I was getting the same until I changed the reference to the phonegap.0.9.6.js to not include the version info in each html page . ie just use phonegap.js where you indclude it in the script tags


what is the correct expression of the two below?

Question: Is is right to say "I have a pen" or  "I am having a pen" ?  I keep hearing people using the latter.
Comment: It depends on the variety of English. In area where Indian English does not predominate, the progressive _be having_ is only used in very limited circumstances: experiencing a state,(I'm having a bad day) or planning an event (I'm having a party). But I have noticed that Indian English makes much more general use of the progressive with verbs like _have_ and _know_ than other varieties of English.
Answer: "I have a pen" is the correct way to show possession of an object.
"I am having" is used mostly for a state of being, such as
"I am having a bad day"
or
"I am having trouble with this math test"
or
"I am having a heart attack"
Comment: Note that there is no real difference between *I am having a pen*, *I am having a heart attack*, *I am having sadness*, and *I am having dinner*. But only the second and fourth of those would we deem correct. This is an annoyance. It's more about usage than it really is about logic. What you say is *generally* true, but it's also something that, unfortunately, has to be learned through experience. (And if you are eating  a pen for dinner, you actually *can* be "having a pen." ;)


Radioactivity and Paradoxes

Question: Can we refer the half life of radioactive materials as another form of Zeno's paradox. Half and half and half forever. Does that mean that if we keep a piece of uranium in a laboratory then there will always exist an atom of uranium that has not been broken down.
Comment: No because there is a discrete amount of such atoms. The last disintegration will happen at an unknown time but will happen.
Comment: In the continuous approximation, yes: in an exponential decay, zero is reached only as $t\to 0$.
Answer: No. There is a discrete number of uranium atoms, and eventually they will all decay. A kg of uranium contains 4.2 mol $= 2.5\cdot 10^{24}$ atoms. If we say the half-life $\tau$ is 4.5 billion years (oversimplifying a bit since different isotopes are different), then after that time there will be $1.25\cdot 10^{24}$ atoms, and so on - but eventually the halvings will reach halving a single atom.
On average, there will be $N(t)=N_0 2^{-t/\tau}$ atoms, and if we calculate the $t$ when $N(t)=1$ we get $t=\tau \log(1/N_0)/\log(2)$. In this case, after 364 billion years (81 half lives, since $2^{81}\approx N_0$) we reach one atom. Which will eventually, sooner or later, decay.
As long as the number of atoms is large, one can treat them as a continuous magnitude. But once they become a mere handful decays are best analysed as a discrete random process.
Answer: Let us suppose that you are left with one Uranium nucleus.
The probability that it will decay within the period of a half life is $\dfrac 12$.
The probability that it will not decay in that period of a half life is $\dfrac 12$.
That Uranium nucleus which did not decay within the period of one half life has a probability of $\dfrac 12$ of decaying in the next period of a half life and so the probability of it surviving a period of one life and then decaying during the next period of a half life is $\dfrac 12 \times \dfrac 12 = \dfrac {1}{2^2}$.
Surviving a period of two half lives and then decaying during the third half life period has a probability of $\dfrac {1}{2^2} \times \dfrac 12 = \dfrac {1}{2^8}$.
So what about the chances of surviving $N$ half lives?
Well that will be $\dfrac {1}{2^N}$
So you will see that the chances of survival get smaller and smaller but as you quite rightly pointed out still finite.
The probability of decaying within $N$ half lives is $\dfrac 12 + \dfrac {1}{2^2} +\dfrac {1}{2^3}+ \,.\,.\,.\,+ \dfrac {1}{2^N} = 1- \dfrac {1}{2^N}$ and note that this sum never becomes exactly equal to one but if you wait enough half lives that chances are that the Uranium atom will have decayed.
Of course the other way of doing the sum is to say that the probability of surviving $N$ half lives is $\dfrac {1}{2^N}$ and the probability of not surviving $N$ half lives is one (certainty) minus the probability of surviving $N$ half lives which is equal to $1- \dfrac {1}{2^N}$.
If you picked out one Uranium nucleus then in a time approximately equal to age of the Universe (13.8 gigayears) approximately three half lives (3 x 4.5 gigayears) of U-238 would have elapsed so the probability of observing the U-238 nucleus under observation decaying is only $\dfrac 78$.

Update as the result of a comment.

Wait a minute, are you saying that two equal pieces of Uranium, by
  mass, can decay after unequal intervals of time<

The short answer to your question is "Yes".
Inherent in the nucleus is a parameter which is called the decay or transformation constant or the half life.  That parameter is unaffected by temperature, chemical composition or the age of the nucleus. The key word in the definition of such a parameter is average or mean. So when you say that the half life of $\rm U-238$ is $4.5 \, \rm gigayears$ it means that on average after one half life, half of the $\rm U-238$ nuclei would have decayed.
If you start with four $\rm U-238$ nuclei then after one half life the probability of one nucleus decaying is $\frac 12$ whereas the probabilities of none or both nuclei decaying are $\frac 14$ and $\frac 14$.
Starting with $100$ $\rm U-238$ nuclei the probability of exactly 500 nuclei decaying is $0.025$ which is roughly the same as the probability of $499$ decaying or $501$ decaying but note that after one half life you cannot be certain that exactly half of the nuclei would have decayed.
At the other end of the spectrum the probability that none of the thousand $\rm U-238$ nuclei decayed is approximately $10^{-301}$ and that only one decayed is approximately $10^{-298}$.
So when you start off with your equal numbers of $\rm U-238$ nuclei it is highly unlikely that the last nucleus in each of the specimens will decay at the same time.
I hope that I have shown you that two equal pieces of Uranium, by mass, can decay after unequal intervals of time.
Comment: Wait a minute. ARE YOU SAYING THAT  TWO EQUAL PIECES OF URANIUM, by mass can decay after unequal intervals of time.
Comment: @user497826 I have added an update to my answer.

Radioactivity and Paradoxes


How to protect my ubuntu linux computer from screen capture programs or keystroke loggers?

Question: I have a Ubuntu home PC. I often use this system to enter passwords to various websites. Some sites also offer a graphical on screen keyboard to protect from keyloggers. However, I suspect that even the on screen keyboard is not safe from malicious software which records the computer screen. I want my passwords to be safe from such programs. Of course, I do ensure that I don't install insecure programs but I would like to have an additional layer of security.
Answer: If the device is compromised to the level where the attacker can record your screen, the attacker can replace whatever they want on your screen as well. You simply cannot trust that device at all at that point. Almost all scenarios assumes that the end user device is somewhat trustworthy.
However, two factor authentication may assist a bit. It may stop an attacker from authenticating using your password - but if they have screen recording access, they can probably just steal your session cookies anyway.
Answer: The main issue with malwares and keyloggers is that they are getting sophisticated every day. As a result there is no single method to detect every possible malware because the intentions and methods behind it may differ entirely for different malwares.
In Linux systems, you can use ps aux to check all the running processes. Some of the popular keyloggers are named like lkl, uberkey, THC-vlogger, PyKeylogger, logkeys. At my college, I had developed a keylogger which would capture every keystroke and installed it on a Linux system for testing. The method which I used to kill the keylogger process was get the PIDs and then use kill command.
To get the PID, simply use
ps aux | grep keylogger

This will return the process details which includes the PID.
Once you know the PID use
kill <PID>

It is important to note that this method may not always work and may not always eliminate every malware from your system. You need to yourself control your urge to download untrusted applications and codes. Keep monitoring the running processes and investigate suspicious processes. Meanwhile don't turn into a paranoid as it is quite possible to loose your mental peace in the process.
Refer this answer which talks in more a more detailed manner.
Comment: Why would a covert keylogger executable be named keylogger? It's ***trivial*** to change the name of a binary (lit. `mv keylogger systemd` will do). Also, an attacker would probably include ways to catch and ignore a kill, and handle sigkill with a restart. Your approach in this answer seems overly naive.


What is the difference between Switch-Case and If-Else in PHP?

Question: I'm deciding whether to use if/else vs switch/case in a PHP site that I am writing and I was wondering if there were any benefits to using one or the other or if there were certain instances where one was intended to be used rather than the other.
Answer: Interesting question because in a compiled languaged (or JIT'ed language even) there is a nice performance gain when using switch statements because the compiler can build jump tables and will run in constant time.  Even switching on a string can be optimized as the string can be hashed.  However, from what I've read, it appears php makes no such optimization (I'm assuming because it's interpreted and runs line by line).
Great .Net article about switch optimization: If vs. Switch Speed
Regarding php being interpreted, the PHP docs says: http://php.net/manual/en/control-structures.switch.php

It is important to understand how the switch statement is executed in
  order to avoid mistakes. The switch statement executes line by line
  (actually, statement by statement). In the beginning, no code is
  executed. Only when a case statement is found with a value that
  matches the value of the switch expression does PHP begin to execute
  the statements. PHP continues to execute the statements until the end
  of the switch block, or the first time it sees a break statement. If
  you don't write a break statement at the end of a case's statement
  list, PHP will go on executing the statements of the following case.

I also found several references all suggesting that if / else statements in php may actually be faster than switch statements (weird).  This probably is not true if you compile php (something I've never done, but apparently it's possible).
http://www.fluffycat.com/PHP-Design-Patterns/PHP-Performance-Tuning-if-VS-switch/
This article in particular, http://php100.wordpress.com/2009/06/26/php-performance-google/,  is interesting as the author compares internal php code of if vs switch and they are nearly identical.
Anyways, I would say that any performance gain will be insignificant one way or the other, so it's more of a user preference.  If statements are more flexible and you can more easily capture ranges of values (especially large ranges) as well as do more complex comparisons whereas switch statements line up to exactly one value.
Comment: Wow, awesome. Very comprehensive. Really appreciate it. I've always been using if-else but I am starting to want to mix it up a bit :)
Comment: @Sam, What about HHVM? It seems odd that the docs explicitly stated that the engine had to do it **line by line** (statement by statement). So an engine that optimizes it by not doing it line-by-line is no longer compliant?
Comment: @Pacerier I wouldn't say that compliance means that a switch must be done line by line.  I'm not clear on whether HHVM uses a jump table or not.  I think in the docs when it shows an example of "if" statements and then a "switch" equivalent that the logic is equivalent but not necessarily the implementation or performance.  HHVM very well may optimize switch statements to use a jump table since it compiles source into byte code before executing it.
Comment: @Sam, But it has to follow the standard defined on php.net/... And if they do that, they would be violating http://php.net/manual/en/control-structures.switch.php *"The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only...."*
Answer: A switch-case statement switches on the value of a given expression only. This gets very convenient if you have a lot (I'd say even any more than two) possible actions to decide between. So, if you have a number of discrete values of a variable and some code to execute for each one of those values, a switch-case statement is probably better.
On the other hand, if you have a more complex test than simple equality, or if there are only two possibilities involved, an if-else is probably better.
Note that in terms of actual behavior, they're identical; it's just a question of which is more convenient for you, the programmer, and for whoever else will have to read or modify the code.
Answer: An if-else statement can evaluate almost all the types of data such as integer, floating-point, character, pointer, or Boolean. A switch statement can evaluate either an integer or a character. In the case of 'if-else' statement, either the 'if' block or the 'else' block will be executed based on the condition.


How to improve on this implementation of the radix-sort?

Question: I'm implementing a 2-byte Radix Sort.  The concept is to use Counting Sort, to sort the lower 16 bits of the integers, then the upper 16 bits.  This allows me to run the sort in 2 iterations.  The first concept I had was trying to figure out how to handle negatives.  Since the sign bit would be flipped for negative numbers, then in hex form, that would make negatives greater than the positives.  To combat this I flipped the sign bit when it was positive, in order to make [0, 2 bil) = [128 000 000 000, 255 255...).  And when it was negative I flipped all the bits, to make it range from (000 000 .., 127 255 ..).  This site helped me with that information.  To finish it off, I would split the integer into either the top or bottom 16-bits based on the pass.  The following is the code allowing me to do that.
static uint32_t position(int number, int pass) {
    int mask;
    if (number <= 0) mask = 0x80000000;
    else mask = (number >> 31) | 0x80000000;
    uint32_t out = number ^ mask;
    return pass == 0 ? out & 0xffff : (out >> 16) & 0xffff;
}

To start the actual Radix Sort, I needed to form a histogram of size 65536 elements.  The problem I ran across was when the number of elements inputted was very large.  It would take a while to create the histogram, so I implemented it in parallel, using processes and shared memory.  I partitioned the array into subsections of size / 8.  Then over an array of shared memory sized 65536 * 8, I had each process create its own histogram.  Afterwards, I summed it all together to form a single histogram.  The following is the code for that:
for (i=0;i<8;i++) {
    pid_t pid = fork();
    if (pid < 0) _exit(0);
    if (pid == 0) {
        const int start = (i * size) >> 3;
        const int stop  = i == 7 ? size : ((i + 1) * size) >> 3;
        const int curr  = i << 16;
        for (j=start;j<stop;++j)
            hist[curr + position(array[j], pass)]++;
        _exit(0);
    }
}
for (i=0;i<8;i++) wait(NULL);

for (i=1;i<8;i++) {
    const int pos = i << 16;
    for (j=0;j<65536;j++)
        hist[j] += hist[pos + j];
}

The next part was where I spent most of my time analyzing how cache affected the performance of the prefix-sum.  With an 8-bit and 11-bit pass Radix Sort, all of the histogram would fit within L1 cache.  With 16-bits, it would only fit within L2 cache.  In the end the 16-bit histogram ran the sum the fastest, since I only had to run 2 iterations with it.  I also ran the prefix sum in parallel as per the CUDA website recommendations.  At 250 million elements, this ran about 1.5 seconds slower than the 16-bit integer.  So my prefix sum ended up looking like this:
for (i=1;i<65536;i++)
    hist[i] += hist[i-1];

The only thing left was to traverse backwards through the array and put all the elements into their respective spots in the temp array.  Since I only had to go through twice, instead of copying from the temp back to array, and running the code again.  I ran the sort first using array as the input, and temp as the output.  Then ran it the second time using temp as the input and array as the output.  This kept me from mem-copying back to array both times.  The code looks like this for the actual sort:
histogram(array, size, 0, hist);
for (i=size-1;i>=0;i--)
    temp[--hist[position(array[i], 0)]] = array[i];

memset(hist, 0, arrSize);
histogram(temp, size, 1, hist);
for (i=size-1;i>=0;i--)
    array[--hist[position(temp[i], 1)]] = temp[i];

This link contains the full code that I have so far.  I ran a test against quicksort, and it ran between 5 and 10 times faster with integers and floats, and about 5 times faster with 8-byte data types.  Is there a way to improve on this?
Comment: This question appears to be off-topic because it is about [codereview.se].
Answer: My guess would be that treating the sign of the integers during operation is not worth it. It complexyfies and slows down your code. I'd go for a first sort as unsigned and then do a second path that just reorders the two halves and inverts the one of the negatives.
Also from your code I don't get how you have different processes operate together. How do you collect the histogram in the parent? you have a process shared variable? In any case using ptrhead would be much more appropriate, here.
Comment: I thought about doing that with negatives, then go through and shift the negatives down.  But I ran into the issue of not knowing how many negatives there were.  On the part about the histogram, yeah the parent collects the data through shared memory (as seen in the link).  The issue I had with pthreads (any threading library if I did c++), was that they would have to link the library.  I wanted to make it as easy on the user as possible.


Confidence intervals of fitted Weibull survival function?

Question: I'm implementing a Weibull survival analysis fitter, and have successfully estimated the parameters and their standard errors. I can also produce the fitted survival curve. My question is how can I use the fitted parameters and the standard errors to compute confidence bounds of the survival curve?
Answer: I just worked this out as I had the same question myself. My answer is largely thanks to Mara Tableman (p65 of Survival Analysis Using S/R).
Let's say you have the survival function $S(t)$ using the Weibull distribution, the lower and upper bounds of the 95% confidence interval can be calculated for every $t$ of the follow-up:
$$CI_{lo} = exp\left\{ log\left(S(t)\right)\times e^{z^*/\sqrt{n_u}}\right\}$$
$$CI_{hi} = exp\left\{ log\left(S(t)\right)\times e^{-z^*/\sqrt{n_u}}\right\}$$
where $z^*$ is the relevant quantile of the normal distribution ($z^*\approx1.96$ for a 95% CI) and $n_u$ is the number of events observed for the follow-up time (i.e., not the number of patients/subjects).
The below is R code to calculate the confidence bounds for a vector, named S_t, of survival proportions (a vector of $S(t)$ at specified follow-up times, $t$).
nu # number of events, needs to be set
z_st<-qnorm(0.975)
ci_lo <- exp(log(S_t)*exp(z_st/sqrt(nu)))
ci_hi <- exp(log(S_t)*exp(-z_st/sqrt(nu)))

Answer: I found that @tystanza's answer (Tableman's equations) give a too conservative confidence interval -- that is, they are too wide. When I did a Monte Carlo simulation to estimate the coverage of the Tableman confidence interval, I found that nominal 95% CI's gave 100% coverage.
I found another option from the package flexsurv. I don't think they directly expose the confidence intervals, but they can be found from "summary". Here is the hack workaround I found to get CI's.  I did verify through MC sampling that the coverage of these CI's is just about right (I found the CI's contained the true value in 930/1000 cases for 95% confidence intervals -- pretty close).
require(flexsurv)
require(survival)

sWei = flexsurvreg(Surv(samples, rep(1,N)) ~ 1, dist='weibull', cl = 1-alpha)
s = unlist(summary(sWei))
lowerCI = s[(2*N+1):(3*N)]
upperCI = s[(3*N+1):(4*N)]


Sufficiently powered, small sample size

Question: I am doing an assignment for 3rd year med. The methods in the paper claims 93% power but sample size is only 20 people. If a study is sufficiently powered, is there anything i should be concerned about when interpreting the results of the study?
Answer: With that few observations every single observation that is a bit "weird" will quickly become very influential, that is, that person will have a very large influence on the size and direction of the effect. That may be fine, and that may not be fine, depending on the circumstances.
Comment: In addition another question to consider is whether the assumptions are realistic. By claiming that one assumes a sufficiently large effect size (no matter how unrealistic), a researcher can pretend to have a well-powered study. There may be an incentive to be overoptimistic, because funding and ethics committee approval usually depends on the trial having a realistic chance of achieving its goal and some researchers may be tempted to do this (and would hope that even if there is realistically no power, they will "know it when they see it").
Comment: I will add to @Björn's comment that even if the sample size was calculated to provide 80% power, there is NOT an 80% chance that the trial will be successful. The effect size can be different than planned. The variability can be different than planned. Etc. Note: when performing a sample size calculation, uncertainty in the parameters is usually/unfortunately not accounted for.

Sufficiently powered, small sample size