User identity and microservices

Question: I have created a User service that controls user login using OAuth2 protocol and stores the user in the local database. So this service is aware of the user session and user identity.
Now I have another service Foo with some endpoint /foo. And the problem is that I need to know which user made the request to /foo endpoint. But the problem is that Foo service is unaware about the user and session.
What are the solutions and best practices for handling this scenario?
Comment: Why are they unaware? Once logged in, the user should have a token that says as much, which the Foo service can respect.
Comment: @Telastyn so should the Foo service have the duplicate logic for validating the token? For now, only the User service has this logic. If so, should both services share the same client-id and client-sercret or should each service have it's own?
Answer: The usual approach is for the authentication service to issue the user a signed token. Other services can verify the signature to check that the token is genuine. The token then contains the user ID. Don't roll your own, but use an existing approach like JWT instead. Be aware of the drawbacks: tokens cannot be revoked individually. A token is valid until it expires, or until the signing key for all tokens is revoked.
In many cases such a zero-knowledge architecture is not necessary (well, the other services do at least have to know the public key for the token signature). Your services can talk to each other. There's no general reason why the foo-service shouldn't be able to ask the user service "is this token valid and which user does it represent?".
Note that your internal services don't have to correspond 1:1 with externally visible endpoints. E.g. it would not be unusual to provide the API through a server that just translates the requests to various internal services. This frontend or facade is also a great place to add shared concerns like authentication. Your internal services would then be firewalled of from the public, and could assume that any provided user ID has already been authenticated.
Comment: Thanks for your detailed answer! It really clarifies a lot! So one approach is to have authentication in the API gateway service but storing users to DB in the user service, is it correct?
Comment: Yes, exactly :)

User identity and microservices


Cisco AnyConnect Secure Mobility Agent Service Starts then Stops

Question: Cisco AnyConnect Secure Mobility Agent was working until yesterday, then it suddenly stopped. I have not installed/updated any software on my PC in the past week.
When I start the Cisco AnyConnect client, I get the messages:

VPN Service not available.
The VPN agent service is not responding. Please restart this application after a minute.

My Event Log shows this information:
<code>Faulting application name: vpnagent.exe, version: 3.1.5187.0, time stamp: 0x543f5ae9
Faulting module name: vpncommon.dll, version: 3.1.5187.0, time stamp: 0x543f58ef
Exception code: 0xc0000005
Fault offset: 0x0005eac6
Faulting process id: 0x2a5c
Faulting application start time: 0x01d04087bc1b3ff3
Faulting application path: C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnagent.exe
Faulting module path: C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncommon.dll
Report Id: fd291387-ac7a-11e4-9545-415645000030
</code>
I have checked the files:

C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility
Client\vpnagent.exe
C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility
Client\vpncommon.dll

with those on a colleague's PC (where Cisco Anyconnect works) and they are identical.
I have tried moving all of the files within:

C:\Windows\System32\drivers\etc

to another directory, whilst I re-installed the software, but this did not help (I have seen other post say that this resolved this issue).
Please can you tell me how I can resolve this issue.
Answer: I resolved the issue by uninstalling CISCO AnyConnect, then deleting the folder:
C:\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client
Note that this folder is hidden: C:\ProgramData
Then I re-installed the CISCO AnyConnect software and it started working.
Answer: You may have Internet Connection Sharing service active, like when you set your computer as a wifi hotspot. Sharing connections may prevent Cisco VPN service to run. In Windows 7 or 8, open local services configuration, look for Internet Connection Sharing service and stop it (double-click and hit "Stop"). Try starting the VPN client service again by starting the Cisco Systems Inc. VPN service. Locate the VPN executable and run it.
Hope it helps.


Does Multiversion module need content migration if enabled on running site?

Question: I have Drupal 8 setup with lot of content in it. When I enable Multiversion module all the content gets disappeared. Do I have to migrate the content after installing Multiversion? Why does it deletes the content?
Answer: As mentioned in the Multiversion description on Drupal.org that it should be enabled on the fresh instance of the drupal. If you are planning to use multiversion on already established database then on enabling this module it will erase all the entities including the custom ones. It will delete
all Taxonomy Terms, Menu Items, Content, Config Entities. So that will require content migration on after install. But there is another way,
1. Install a fresh database
2. Enable the Multiversion
3. Sync the configuration.
Configration management comes really handy in this case.


What is a Zero Day attack?

Question: Can anyone explain to me what is a zero day attack with a very simple example? Also, how can it be prevented?
Comment: Have you done any research or reading?
Answer: The term Zero Day or Zero Hour can apply to any type of attack. It's really just a classification given to the time period at which a vulnerability has just been discovered by a person or organization but has not yet been disclosed publically.
Some definitions also include the first day or "Day Zero" of a vulnerabilities announcement and the race between attackers and defenders to attack or defend their systems when this type of announcement is made.
Zero Day attacks are particularly dangerous because for the short time period they haven't been disclosed the attackers can effectively compromise some level of system access across almost all systems which are vulnerable. In some cases, this can give an attacker access to millions of devices or access to lots of sensitive data.
Once it has been disclosed publically or there is a known remediation it is no longer considered to be a Zero Day. Note: Some definitions vary here.
So there is no "solution" to preventing Zero-day attacks as new vulnerabilities and exploits will always be discovered before the remediations to prevent such problems from being exploited can be created.
Effectively the holes will always exist before their respective patches.
This said there are additional defenses which can be implemented to reduce the risk from certain types of Zero-Day attacks or limit their damage but it is not possible to anticipate all attack vectors.
This is really why you want to have multiple security tools because at any given time one layer of defense (one of your security tools can fail or be vulnerable).
In other words, if you think of security as a function of time at some point a vulnerability will exist even on the most well-secured networks.
If you only have one level of defense protecting your data your security will look like the following:
Time: ----->

Layer 1 Security: --------------------    ----------------
                 Zero Day occurs here ^   ^ vulnerability fixed here.

If you have multiple layers of defenses (or defense in depth) in theory as different vulnerabilities come out in time your defenses will look more like the following:
Layer 1 Security: --------------------    ----------------
Layer 2 Security: --------------    ----------------------
Layer 3 Security: ---   ---------------------    ---------

Even though each layer of security gets vulnerabilities from time to time they don't all align for an attacker to get through all three layers. In rare cases, this can happen but statistically multiple layers can provide much better security than one layer by itself.
One of the best defenses against Zero-Days is a very disciplined staff keeping multiple layers of security up-to-date. Discipline is key here, the layers just buy you more time.
Comment: Excellently explained. The ASCII art really helped visualize something as complex as security layering.
Answer: Zero days is the length of time that the vulnerability has been known about.  Thus meaning that the vulnerability is unknown to the people who would write or fix the software.  The reason they are so valuable on the black market is because no one is currently working to fix it!
Keeping your software updated is a good defense to known vulnerabilities but doesn't protect you from zero-day attacks.  The solution is defense in depth and reducing your attack surface (turn off any services you aren't using).
Answer: Simplest definition for zero-day attacks is attacks on vulnerabilities that have not been patched or made public. Or you also can define them as attacks that take advantage of a security vulnerability on the same day that the vulnerability becomes publicly known (zero-day).

What is a Zero Day attack?


Debug System Slow-downs and freeze

Question: I have an Arch laptop where sometimes (daily and more) I experience freezes that start with software slowing down and then slowly extends to the whole system until it's unusable and I have to alt+prt+(REISUB). Sometimes RE is enough and I can restart lightdm from another session.
I was wondering how to properly understand what is going on. If this is RAM being used up, is there an overlay I can keep as these freezes are not very predictable? I don't believe logs would be helpful for this.
And if it is RAM, is there no better way for linux to handle this...
Comment: If it is something hogging RAM (and that may be the first hypothesis) at some point the linux kernel will decide to kill one process to reclaim some RAM, and this will be recorded in logfiles. See and search about the "OOM Killer". OOM=Out Of Memory. Otherwise you are not giving a lot of details... Distribution version ? Kernel version ? Hardware used and specifically RAM availale ? What applications run on it? Etc.
Comment: It seems like it does not do this, even waiting long enough. And sysreq-F should do the same, but it doesn't seem to work at all. I didn't give information because I was not looking for a solution to the freeze, but to understand how to treat it. I am on Antergos 5.2.11 on a ux430un with an i7 8550u and 8 GB of RAM. Applications vary, mostly it's using firefox + something like matlab, inkscape or so.
Comment: "but to understand how to treat it." you first need to understand where it does come from. If you have absolutely nothing in your logfiles, you need first to put in place some monitoring. PS: please update your post with all the relevant extra information on software/hardware, do not put that in comments, people will overlook it and in your post it will make your question better as more detailed.
Answer: you can try a script like
<code>while [ true ]; do
    ps aux >~/ps-`date`.log
    sleep 1
done
</code>
to catch processes which eats your memory.

Debug System Slow-downs and freeze


How do I connect a media server to 3 LANs?

Question: I'm planning to connect a media server (Raspberry pi may be) to 3 separate home networks (with separate subnets). I've researched and found solutions for 2 networks. If it's possible, how do I go about connecting 3 networks to the server? I can keep the server in one of the networks or in totally separate network. Also, the computers/devices should not be able to access devices from other networks. Devices should have access to devices in its own subnet and the server.
Comment: Setup a VPN server for the network the media server is in, and from the other networks, connect to it via VPN. Then it doesn't matter where the other networks are.
Comment: Are they in the same home or different physical locations? What soultion did you find for 2 networks? If it handles two, it should handle more.
Comment: Will that be over the internet? Bcz that will waste a lot of internet bandwidth. I forgot to mention all 3 home networks and server network are nearby.
Comment: @HazardousGlitch they are in neighboring houses, so they can be connected with Ethernet. The solution I found was connecting both via switch, then route forwarding settings in both the routers. But this method will give all devices access to each other.
Comment: I meant devices will get access to other networks' devices, which I don't want.
Answer: Put a router between the 3 networks. Most routers that aren't bottom-tier are capable of handling multiple networks – be it OpenWRT, a Mikrotik, an ER-X/ER-L, Raspberry Pi, etc.
Each network's existing main router should have a static route for the other two networks, pointing to the 'new' router as the gateway.
Nearly all routers come with firewalls. Edit the firewall rules such that only traffic to your media server is allowed (plus "established" traffic so that replies can go back).
The mechanism doesn't really change much from 2 to higher numbers. (But in all cases, there is the requirement that all networks have unique addresses: you cannot reliably connect two 192.168.1.x/24's together.)
Comment: Thanks. All three networks have their own internet. So pointing to new router as gateway will prevent internet access, right? I guess firewall is the key here, that should work perfectly. I will have to check firewall supported routers.
Comment: @HimanshuMehani: Don't point to the new router as the _main_ gateway! Point to the new router as a gateway for _the other two networks,_ nothing more.
Comment: Would you mind explaining this?
Comment: That's probably worth its own thread, but in short: routers (and even computers) can have a 'routing table' which lists several different gateways for different destinations. (And that's why the default gateway is called "default gateway".) Most routers let you add custom routes like "192.168.3.xx can be reached via 192.168.1.23".


Why does time in Minkowski's space have the opposite sign of the space coordinates?

Question: I've looked up here and on Griffths' didatic Introduction to Electrodynamics, but, still, am struggling to understand why time has the opposite sign of the space coordinates. Any insights are welcome.
Answer: From the 2nd postulate of special relativity, and homogeneity of space-time and isotropy of space, follow that the space-time interval, i.e. $s^2 = c^2Δt^2 - Δr^2$, between two physical events is invariant. If you change the sign of $Δt^2$ (or $Δr^2$) in the interval, then it cannot be invariant anymore.
Answer: One starts special relativity with the idea that the speed of light is the same in every reference frame. From this one concludes using the Pythagorean theorem that time must pass slower for a moving observer. The distance traveled in space $x$ plus the time, that actually passed for you, $s$, is the time $t$ that would be observed from a different observer.
This proper time $s$ then becomes the new measure of things. So you start with
$x^2 + (cs)^2 = (ct)^2$ and then define a new scalar product (using the metric tensor) that gives you $(cs)^2 = (ct)^2 - x^2$.
I feel that this is not justification enough. If there were no minus sign, the addition of velocities would not work such that the maximum velocity is the speed of light $c$.
Answer: If the time coordinate had the same sign as the space coordinates, then time would be completely equivalent to space.  Clearly it isn't - for example, causal influences (i.e. pretty much everything) can only move forward in time, but it certainly isn't the case that everything can only move in one direction in space!


Should I normalise image pixel wise for pretrained VGG16 model

Question: My goal is to use pre-trained VGG16 to compute the feature vectors excluding the top layer. I want to compute embedding(no training involved) per image one by one rather than feeding batches to the network as this network is just to compute embedding and not classification. In batch training I understand the importance of batch normalization but for a single image should I normalize it pixel-wise? All I can think is maybe it's useful to reduce the importance of illumination in an image. Am I missing something?
Answer: It all depends on how the original pretrained model was trained. If it was trained with normalized data, you should also normalize your data before giving it to the model. Otherwise, the input data distribution will not match what the network was trained with, and then you probably won't obtain good results.
VGG16 pretrained weights expect normalized data as input, so the answer is yes, you should normalize the data (subtracting the mean and dividing by the standard deviation).
If your image domain is similar to ImageNet, you may use the same mean and standard deviation statistics. If your images are from a very different domain, you should compute your own statistics (source).
Comment: Thanks for the response!
Comment: I'm sorry the undo of your answer selection but I found that indeed images were subtracted by mean but they weren't divided by std deviation .It might mislead future readers. Thankyou for your response.


Canadian's car in USA

Question: I live in Boston MA with a TD visa. I don't want to buy a car in USA. Can I drive my Canadian car (car registered in Canada) here? How long can I drive it? How about car insurance? Any detailed information about this?
Comment: You might want to ask this on [Expatriates.SE] instead.  That site is more closely oriented towards practical questions such as this one.
Answer: When you started living in Massachussetts, you are required to register your car in Massachussetts. Residency means "living there", and isn't about citizenship / permanent residence. There is no provision at all for delaying the change of registration: here is how to transfer the registration. You can't use Canadian insurance, so you will also have to get Massachussetts liability insurance (and collision, if you want it). Pretending that you are "just a tourist passing through" will not work and is easily disprovable. Your Canadian insurance agent will confirm that you have to switch to a Massachussetts policy when you move to Massachussetts, because you are not covered by Canadian insurance when you reside in Massachussetts.
Comment: Not only that but if the OP's insurance company finds out they are living in a different country with the car, they may deny any claim, so the OP may effectively be uninsured.
Comment: I know there are strict and often burdensome requirements to import a car manufactured for the US market in Canada, and to import a car made for the Mexican market in the US.  I'm not sure about Canadian cars in the US, but it seems likely.  There's also the question of import duty.  None of this implies that anything in this answer is incorrect, if course, but there may be quite a lot of paperwork and money involved in registering the car in Massachusetts.
Comment: Typically you must register a car by law if you live there at least 30 days, although enforcement is slight is your Canadian registration is current. One reason to comply is the insurance requirement as this answer notes.
Answer: The Massachusetts Department of Revenue has a web page about your domicile. Among other things, they say it's impossible to have one domicile for general living purposes, but a different domicile for tax purposes. Which I take to mean that their advice about what your domicile is for taxes also applies to general living purposes.
The answer seems to be "it depends". Apparently your spouse or parent moved to Massachusetts as a nonimmigrant visa for skilled Canadian or Mexican workers. Since it is a nonimmigrant visa, it would appear you don't intend to stay in the US permanently (although plans sometimes change). So maybe Massachusetts isn't your domicile.
A person who keeps a home in Canada, goes there a few times a month, and has a definite plan to return to that home after working in Mass. a while is apt to have Canada as the domicile.
A person who disposed of the former home in Canada, only visits Canada a few times a year, goes to different places on each visit, and has no idea where he/she will live when the period of work in Mass. is over, is apt to have Mass. as the domicile.

Canadian's car in USA


How do you make a sunburst brushed metal effect?

Question: How do you make a sun brushed metal effect like in the image below? I've tried motion blurring a noise layer but this gives to much blur.
Answer: Draw a circle and apply a Radial Gradient to it. I simply used a Layer Style, but you can use a Gradient Layer if you want.

Use a custom gradient with several color stops. Use the same color for the stop furthest to the left and furthest to the right. Otherwise the gradient will show a "seam".
Then create  anew layer, fill it with black and add a Mask the size of the circle.

Unlink the mask with the layer, by clicking the chain icon between them:

Click the layer thumbnail so it's highlighted and choose Filter > Stylize > Add Noise, play with settings until you get a middle-ground and then click OK.

Then choose Filter > Blur > Radial Blur

lastly set the Blend Mode of the blurred layer to Screen:

You can then further refine the gradient:

And adjust opacities to blend things a bit better:
Comment: I know you are trying to replicate the user's example, but using a "zoom" pattern has little sense because this kind of brushed metal is done by spinning it, so a spin blur would be more realistic. :o)
Comment: @Rafael Your'e correct, and actually.. I'd use both.
Comment: Excellent example. Thanks, I used this today in my work.
Answer: Acceptably finely brushed metal, even if blackened, has so fine scratches that computer screen probably cannot show them except with high zoom. But together the scratches and the light result a visible gradient effect. Thus I would start with a simplest possible conical gradient without adding any grain. Complex gradients can easily look out a folded rosette.

The gradient is 5 stop black-white-black-white-black. You can see some banding (=ray lines) due the limited accuracy.
8 bit deep colors create more rays when the brightness range is adjusted. Darkening is needed for an impression of black metal. A levels or curves adjustment layer is the simple solution:

For some internal math operation reasons the right adjustment was difficult, I didn't found a good setting.
But there's another option. Add a grey top layer and a black background. Adjust the opacities of the grey and gradient layers.

With different adjustments you get also brushed plain steel:

The gradient is opaque, so the black background is unnecessary.
With an adjustment layer you can make it glossy:


Restart systemd service if no log produced in timeout

Question: Is it possible to monitor systemd service (unit), if it produces logs, and if no log is produced in (lets say 5 minutes), restart the service?
Answer: So you can put logic based on below scenarios:
[1] Check pid if exists, if not restart application.
[2] Check log if not produced for some time(check what threshold you want to put), restart service.
<code>journalctl <your application binary>
</code>
[3] If your application support endpoints for health check, you can write on top of it.
Actually we need to identify difference between idle and not working while checking logs, So I think checking single thing is not enough.
Comment: Thank you, [1] is not feasible, as the app seems to be running, however it is hanged, if it doesn't produce any logs, [2] is what I'm talking about, but I'm looking for automated solution, not manually checking, manually restarting scenario, [3] it does not support, it's 3rd party closed-source, which lacks this. [2] is great indication of "not working", because it actively sends out heartbeat and logs that action in syslog, so there is no idle-state confusion.


Classical language

Question: What are classical languages? How they are different from other languages? Is English is an example of classical language?
Comment: I really don't see this as being off-topic. It is asking about the meaning of an English phrase, and the answer hinges on a particular meaning of the word ***classical***. If I had the required reputation, I would cast a reopen vote.
Comment: I read that as part of the meaning of the word *classical*. One cannot answer the question in any form without exploring the use of the word *classical* as it pertains to tradition and education (that is to say, why Latin and ancient Greek, among others, are *classical* while others are merely *foreign*). It would devolve into an off-topic question if it were a matter of structural linguistic differences between languages, but it has nothing to do with any intrinsic attribute of a language. It's not like the question is "why is English not considered a polysynthetic language?"
Comment: Sorry, this is off-topic.  It is not really a question about English, except to the extent that English happens to be a language.
Comment: @Stan Rogers: The question doesn't just ask "what is the meaning of *classical* in *classical language*"?  It asks how classical languages are different from other languages — that is off-topic.  It could be made on-topic by removing that portion.
Answer: The Wikipedia article is a good reference.

A Classical language should be
  ancient, it should be an independent
  tradition that arose mostly on its
  own, not as an offshoot of another
  tradition, and it must have a large
  and extremely rich body of ancient
  literature

Is English is an example of classical language.
No.

In the context of traditional European
  Classical studies, the "Classical
  Languages" refer to Ancient Greek and
  Latin. In terms of worldwide cultural
  importance, Edward Sapir in Language
  (1921) would extend the list by
  Chinese, Arabic, and Sanskrit.

However, it also states
Early Modern English (language of KJV Bible and Shakespeare, 16th to 17th c.) is the classical stage of English -

Such a stage is limited in time, and
  is considered "classical" if it comes
  to be regarded as a literary "golden
  age" retrospectively

This means today you would consider the Shakespearean period to be the golden age of the English language.
Comment: @khan: you're welcome - not 'great' really, I only quoted wikipedia ;)

Classical language


What are other channels Botnets can use for command and control except IRC

Question: What command and control channels might a botnet use? Which would be most effective?
I found good info on IRC, what are other possibilities?
(Exam preparation - no harm intended :-) )
Comment: There are different classes of botnet like IRC based, HTTP based, P2P based etc. But your term effective is very ambiguous like it can mean stealth, or it can mean efficient communication bots between bot and server.
Comment: Talking about botnets with malicious intent where C and C is present.The ones you give an example are decentralized asfaik like P2P, web server maybe centralized.
Comment: NTP is also a fun control channel!
Answer: There are many alternatives being used by the malware creators. Some of them are:

Flashback Mac Malware used Twitter 1.
Google AppEngine 2.
Facebook 3.

For sure, there must be other channels as well, these are the one that I remember from recent news.
The botnet owners are diversifying from IRC as, Twitter, Facebook, Google AppEngine are services used a lot and the traffic is considered to be legitimate and less suspicious by the network administrators. Though I am not an expert, I hope this gives you some idea.
Edit:
I remember of another one, presented in DefCon 2010 by Dennis Brown. Using Tor network.  Using Tor2web botnet can access a .onion website and take commands from the server. Have a look at the presentation, it is informative. 4
Answer: HTTP is quite popular.
From a bot herder's perspective there is, of course, the issue with HTTP of how to keep the bots going when Law Enforcement takes down the web server you were using, or people start blocking access to it. To get around that some use domain names that are generated according to an algorithm that only the bot programmer knows and therefore (s)he can pre-register a series of next domains that the bots will try to contact.
There is social media like Twitter. You could have the bots follow a particular user on twitter, but that account could get closed so following a particular hash tag might be more useful, or like the DNS domains, you could have the bots follow user names generated according to a predetermined pattern.
The advantage of using IRC was the simplicity of setup and robustness of the system. Choose a popular IRC network and pick a channel to host communications. Creating an IRC channel hos no costs associated, and the IRC networks are already there with redundant servers etc.
Answer: Use the principle of "hidden in plain sight". Post messages in public, hidden by encryption
Usenet, with a pre-shared token and encrypted messages. Your bots would need to search Usenet message headers for the token. Limit the search by posting to a preselected list of newsgroups. Censorship is difficult because Usenet is a peer network. Every server duplicates the same data. Choose popular newsgroups to avoid censorship by deleting the newsgroup, but not so popular that message header searches take forever
Cryptocurrency blockchains, uncensorable, with fees. You can probably send 100 40-byte messages in a Litecoin transaction for about 1 cent. Not immediate, usually delayed up to 2.5 minutes, could be longer. Once the transaction is confirmed, it's permanent. No takedowns possible. Transaction outputs are implemented using a primitive scripting language. Most outputs are coins, with a signature checking script. One of the script operators is OP_RETURN, a null operator which allows a parameter containing up to 40 bytes of arbitrary data. Construct a transaction with one or more OP_RETURN outputs, and one payment output, paying to an address recognized by your bot's own wallet. No search required
Namecoin is probably better than Litecoin, because its purpose is to store key-value pairs. On the payment blockchains - Bitcoin and Litecoin - the use of OP_RETURN for storing arbitrary data is considered by some to be abusing the common resource


Regenerate Slugs From Title of Posts

Question: is it possible to regenerate the slugs programmatically after changing the titles of the post? Numerous post titles were updated and the slug was not updated with the title so I need to regenerate all these slugs.
Comment: I have had to do this several times and found that between different server environments where it can't handle large arrays ( with numberposts being set to unlimited ) nor calling wp_update_post repeatedly with large memory consumption that breaking it into a WP_Query call with pagination and using $wpdb that it is more manageable and performant. I provided the [code sample on a similar post](http://wordpress.stackexchange.com/questions/135931/reslug-a-custom-post-type/136099#136099).
Answer: Yes, it is possible.
Sample code, has to be tested and refined:
// get all posts
$posts = get_posts( array (  'numberposts' => -1 ) );

foreach ( $posts as $post )
{
    // check the slug and run an update if necessary
    $new_slug = sanitize_title( $post->post_title );
    if ( $post->post_name != $new_slug )
    {
        wp_update_post(
            array (
                'ID'        => $post->ID,
                'post_name' => $new_slug
            )
        );
    }
}

I just made this up, there are probably some errors and egde cases, but it should give you an idea. Also, this may take a while, so it could be useful to split the update into smaller chunks.
Comment: Hmmm... from my experience, this doesn't work.
The `post_name` argument is ignored by the `wp_update_post`, at least in the 3.9 version of the core
Comment: Currently, `post_name` is ignored within `wp_update_post()` function, but it is taken into consideration when the update post calls for the `wp_insert_post()` function: this means that passing the new slug to the update, will result in effectively changing it for the post being updated.
Comment: @fuxia, I've tried something [similar](https://wordpress.stackexchange.com/questions/410130/is-there-a-better-way-to-check-if-a-slug-already-exists) but it times out. Are you able to suggest an approach?
Answer: This plugin also does the job: http://www.jerrytravis.com/598/wordpress-plugin-to-generate-post-slugs
However, as it only does it for posts which don't have a slug yet, if you need to regenerate slugs edit the following line in the plugin:
if ($post->post_name == "") {
for example, you could change it to:
if (true) {
Answer: I was trying the method suggested by Toscho, which is the "instinctive one", but in many cases it doesn't work (cf the core code to get what I mean by "many cases").
Looking in the code, I found the wp_insert_post_data filter hook, called by the wp_update_post function right before inserting the post iunto the database.
By calling this filter, and changing the value of $data['post_name'], I was able to get this to work properly. Wordpress is cool but so badly documented...
I edited the documentation, so that more people can find this workaround if needed.
Comment: Can you point out why wp_update_post overwrites the post_name? the only reason I see for this to happen is if the user trying to modify the post_name is only a contributor (or same level) in which case it shouldn't allow that user to change slug, did you find any other cases in which the post_name is overwritten?
Comment: Yes this is the proper way to do it. Thank you @Alexandre
Answer: you can do this directly in mysql if you need.  (our woocommerce site has 100's of thousands of products):
update wp_posts set post_name = concat(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(lower(post_title), '"', ''), "'", ''), ",", '-'), " ", '-'), "&", ''), ";", ''), "@", ''), ".", ''), ":", ''), "/", ''), "+", ''), "(", ''), ")", ''), "--", '-'), "---", '-'), "--", '-'), "--", '-'), '-', id) where post_type = 'product';

where post_type = 'product' - that will keep your update to just woocommerce products; you should figure out what limits you want to keep on this query.
Answer: We had an issue where we migrating and combined a bunch of post types.  We had a bunch of blank titles as well.  I wrote a WP CLI command to fix them all, but here is the gist of what I did:
    global $wpdb;
    $types = [
      'page',
      // Your CPT machine names
    ];

    // Formats our IN query properly.
    $final = array_map(function($type) {
      return "'" . esc_sql($type) . "'";
    }, $types);

    // Grabs all our empty title fields.
    $query = sprintf("SELECT post_title, ID FROM `%s` WHERE post_type IN (%s) AND post_name = ''",
      $wpdb->posts,
      implode(",", $final)
    );

    foreach ($wpdb->get_results($query) as $post) {
      $title = sanitize_title_with_dashes( $post->post_title );
      $wpdb->update('wp_posts', ['post_name' => $title], ['ID' => $post->ID]);
    }

Needed to do a direct MySQL update since wp_update_post doesn't update the post_name.

Regenerate Slugs From Title of Posts


What is the simplest way to render an image of an obj exported from Tinkercad?

Question: I like Tinkercad so far for it's very simple UI. (I'm new to 3D modeling and very confused by Blender and the like.) However, I'm not using it to do 3D printing just yet. For I'd like to be able to be to slap textures on the models I make and get images of that. What is the easiest beginner way to do that (for Linux OS)?
Alternately, displaying the .obj directly in the browser with a texture would be great, too.
Comment: I think the part "I'm not using it to do 3D printing" takes care of the textures needed aspect.
Comment: textures? Why you need textures, when the print will be monocolored (unless you have one of those new printers that add ink)?
Comment: @fred_dot_u That part makes it Off Topic, but yes.
Answer: For your purposes, consider that Meshmixer (free) can open .OBJ files and display them in any position you desire.
I use Meshmixer quite a bit for model editing, but have not used it for .OBJ files with textures. I searched my drive and found quite a few .OBJ files, but was not able to present or add textures, due to my own ignorance, I'm sure.
I found a useful link to a support page on the 'net which indicates that there has to be a texture file as well as a definition file (.MTL) in order to display the textures in Meshmixer. Using that reference, I was able to add a randomly selected .PNG file and apply the texture to a test model.
If your creations do not include those support files, this may not be a good answer. There's little to lose, however, as the program is free and you may find use for it in the future, or you may find that it works as you require.
Comment: Thanks! Unfortunately, Meshmixer does not appear to be supported on Linux, which I am on.
Comment: that does throw a wrench in the works!
Answer: If you need just a graphical 3D look at them, opening them in any slicing program should create a graphic visualization in relation to the print grid - in glorious 3D. Slicers don't allow to place textures on them though.
One of the most common slicers among hobbyists, Ultimaker Cura, comes also as a linux distribution, just like a couple more reviewed on all3dp.com
If slapping textures on your model is a strict demand, then you have to get a proper graphic-design program. Blender, which is a mess, as you mentioned, is one of the most powerful ones out there. But even with blender you don't need to go all deep into learning: if you just want to check out a rough fit of the looks, it can be used for a 3D visualization. It can be helpful to use the vertex-paint mode to mark some areas as you spin the model around. And if you dig deeper into the matter, you can make an UV-map easily.
Answer: Consider using Clara.io (100% free):

Export your Tinkercad project as OBJ.
Import in Clara.io
Texture and render.

Clara.io is 100% web based. It is simple to learn if you have prior experience with other 3D renderers. If you don't, the learning curve might be steep though...
But : you have access to VRAY which in a free-to-use package, is simply awesome...


1998 CR-V clicks behind glove box but won't crank

Question: Standard shift.  Car began to be harder to start as the weather got colder until all it does is click behind the glove box and refuses to crank at all.  Replaced main relay without change.  Checked fuses.  Looks like all good.  I don't hear fuel pump but it won't crank so pump issue is moot.  Analyzer says no codes in ECU.  Battery shows full on 2 different chargers.  Connections tight and clean.  Can't get under vehicle to jump across starter due to ice on ground.  Haven't tried push start.  This Honda does not use electronic key.  The key is of a type that has no transponder, one of the reasons I bought the vehicle.  As far as I can tell, there is no immobilizer.  There is no other security on the car.  I have only one key and it only unlocks the driver side door, which also sux.  There is no indication that anyone has modified this car in any way.  It has 270,000 miles.
Comment: Welcome to Motor Vehicle Maintenance & Repair! You state the "battery shows full on 2 different chargers", but what is the actual voltage? Did you get the battery tested under load? Don't trust the battery charger. They can only do so much.
Comment: 12.6 on both.  Yes it was tested  under load and multiple load tested batteries were used that were from separate shops who do this kind of work.  I took BOTH my chargers to shops for testing and they were good.
Answer: Since the battery reads good and yet you're still hearing clicking noises when you turn the key, the next logical thing which could be bad is the starter. If the solenoid has gone out, you might hear a relay click, but there'd be no starter action. To test this theory, you'd need to take the starter out and have it tested.


Why is a smudge stick called a smudge stick?

Question: What is the origin of the name "smudge stick"? And why is it considered offensive by some (according to Wikipedia)?
Comment: Lots of smudging happens around where I live, practised by some Ojibway folks. I've never heard of "smudging" being considered offensive by these friends and colleagues. On the other hand, I haven't heard the term "smudge stick" at all.
Answer: The Wikipedia article implies that the herbs bound together are burnt to give a scented smoke.
OED gives

smudge, n.2
2.
   a. A heap of combustibles ignited and emitting dense smoke, usually made with the object of repelling mosquitoes, etc. Chiefly N. Amer.
Etymology: related to smudge, v.2
smudge, v.2
1. b. N. Amer. To make a smoky fire in (a tent, etc.); to fill with smoke from a smudge. Also, to cause (a fire) to smoke; to drive (mosquitoes, etc.) away by smoke. Now rare.
Etymology: obscure

So: no-one knows where the word comes from. As to why it should be offensive, offence is subjective: only those who are offended could explain why.
Comment: Thank you for the answer. As for offence, it can also be explained by those to whom it has been explained previously.
Comment: I guess rarity is subjective, too! Smudge as a verb is *not* rare in Northern Ontario where I live.
Comment: I should have looked further down the list of OED entries for "smudge"! You're quite right, obviously.
Answer: John Trotter Brockett's A Glossary of North Country Words, in Use; with their Etymology and Affinity to other Languages; and Occasional Notices of Local Customs and Popular Superstitions offers an etymology from German:

Smudge, v. to burn without a flame, or any appearance of fire except smoke.—Smudge, or Smush, s. a sulphureous smell occasioned by smoke and dust—close, suffocating air. Germ. schmutz, smut, dirt.

As to offence. While the burning of herbs for their smoke is hardly unique to the American tribes, and is not a matter of cultural appropriation in itself (certainly, it's been common in Europe and Asia since before any contact with the Americas), smudge sticks are portrayed as being somehow a "Native American" tradition. As such, it stands neither as a general example of the worldwide practice of burning herbs for their smoke, nor as an example of respectfully following a genuine tradition of a tribe, but as a mish-mash of the two that often goes against the rules of the traditions they claim to represent. So it could be seen as a bastardisation of genuine indigenous tradition.
It can also be, if not offensive, at least downright irritating to have something that is not directly related to your culture frequently talked about as if it is.
It would also link into wider issues about cultural appropriation. See e.g. Michael Brown's Who Owns Native Culture (Harvard University Press, 2003) or the associated website, for more opinions and information on that.
Of course, many tribes do have a practice of burning herbs for smoke, and I can see little logical reason why it should be argued offensive to use the term smudge as the English word for it (any more than medicine and wheel or vision and quest, though medicine wheels and vision-quests are also recycled into something very different to their original format and purpose, I haven't heard of objections to the words themselves). The difference is likely between those who hear the word most often used of what they really do (or even use the term in English themselves), and those who most often hear the word used of neatly packaged "smudge sticks" that often combine herbs that traditionally should not be used together (it seems some sticks combine sweetgrass and white sage, though one is meant to attract spirits, and the other to be apotropaic, so while there could be a logical reason to use one and then the other, burning both together would be pointless), or that traditionally should not be traded or sold.
There's an irony here. Burning or otherwise using common sage, and other plants called sage (but not white sage, as it is a New World plant) for purification or warding of evil or sickness is a very old European tradition. Smudge sticks which contain common sage (as some do) are therefore a repackaging of an old European tradition with nothing to do with any American tribes. Yet generally smudge isn't used of European burning of incense and herbs, only of American use. So this modern repackaging of a European tradition is being claimed as a modern repackaging of an American tradition, which could seem a bit disrespectful to both.


If one coin toss yields Head, what is the PDF for the probability of a head?

Question: This is not a homework question.  I discovered that I am not the only tenant in a highrise that is getting headaches from paint fumes.  I talked to one couple in the elevator about the paint fumes.  I turns out that they have the same problem.  Based on just one observation, I would be dismissed as a quack if I try to convince the property manager that tenants in general are likely to find the paint fumes problematic.  However, I was wondering if that one observation allowed one to contruct a PDF of $p$ with a broad spread ($p$ being the proportion of tenants who are troubled by the paint fumes).
Comment: If you get an inspector in to measure the level of toxic fumes, you do not need statistics.
Comment: I wasn't going to present the statistics, it was an intellectual question.  The city is in-bed with the large owners of many highrises in the city, and one must be prepared to quit one's job and push full time if due diligence is desired.  I'm currently appealing to the property owners desire for attractive premises, and the hurdle right now is to convince them that the observed periods of no ventilation are reliable.  Hopefully, a few witnesses will do that.
Answer: Independent of paint fumes, the question can be thought of figuring out if a coin is biased or not, based on one (or more if you prefer) toss. One logical way to make inference is using Bayesian framework, but we need priors. Just as in example in here, assuming a non-informative prior, i.e. uniform distribution, which is the same with beta distribution with $\alpha=1,\beta=1$, the outcome of the experiment can be incorporated into the PDF estimation, yo come up with a posterior. The posterior is again Beta distributed, with $\alpha=\alpha_0+s$, $\beta=\beta_0+f$, where $\alpha_0,\beta_0$ represent your initial belief, i.e. prior, and $s$ number of positive outcomes, and $f$ number of negative outcomes after $n$ trials. In your case, $n=1,f=0,s=1$. And, when you select the non-informative prior, i.e. $\alpha_0=1,\beta_0=1$, you end up with a Beta distribution for $p$ with $\alpha=2,\beta=1$:
Comment: Thanks gunes.  I was hoping that it would be a canned equation instead of Bayesian analysis, but you made it both. I tried to crack the Bayesian nut multiple times in the past half decade, but never got my head around it. Reading things like [Bayesian inference](http://en.wikipedia.org/wiki/Bayesian_inference), [Think Bayes](http://thinkbayes.com), and [How to measure anything](http://www.howtomeasureanything.com/3rd-edition) (Chapt.10).  Your answer inspired me to try the last one again. Together with your example, I am getting a foothold.


Can Googlebot read any hosting stats?

Question: When Google Analytics isn't active for a website, can Googlebot (or any other Google entity) get any traffic stats about that website in any other way?
Answer: No. Not really.
Google can use Adsense data for some things and of course if you use Google Analytics you have given them some valuable information.
But if you think this bleeds over to search performance, it doesn't.
If you do not use Adsense of Analytics then the only data Google has is search performance and click through rate (CTR) which does effect search performance.
For Google, this is the end of the story. For the sake of education, I will go a bit further.
As for anyone else, there are some tools that exist including crawling any performance stats you post. Search engines do not do this except for search if you allow it. However, there have been cases where people have tried to use this data intelligently. There are cases where this data is useful, but not generally for building performance analysis sites. The data does not exist for enough sites and is far too limited in scope to measure.
Amazon and other tool bar issuers, and this can include Google, can potentially track user behavior. But it is user data and not site data. However, much of this extrapolated data and if you know about Amazon, their numbers and data is pure junk. I do not believe that Google tracks or takes any of this data seriously. From a statistical analysis perspective, it is impossible to gauge a sites performance upon a self-selective group and it is further impossible to extrapolate performance data when you do not know what you do not know. The Amazon model, for example, is horribly flawed and impossible to fix. Google is smart enough not to step in this trap.
Otherwise, if you are asking if a site you build can measure the performance of another site simply through observational methods. Then the answer is a resounding "No."
For many performance analysis sites, there exists a dependency upon some sort of mechanism; JavaScript/Java (known as a bug) or an image. You would have to install this bug or image for each site that wants to be measured.
Comment: You wrote "Search engines do not do this except for search if you allow it". Is there a specific way of posting stats so that search engines can pick them up and understand them for what they are?
Comment: @chris No. Search engines other than using a bug, are not interested in parsing random and uncontrolled data simply because it can be false.
Comment: Sorry if I don't get it... you say that using a bug they *do* parse stats, right? Can you pls give an example of such script that would be parsed by Googlebot? Thanks
Comment: @chris The Google Analytics code that you put in your sites page headers is a bug. It is simply a small bit of JavaScript code that executes when the page is loaded. No search engine reads stats. They collect stats using a bug. BTW- It's okay to be new at this stuff... we were all new once too!
Comment: Thanks. So the final answer is "No, it's impossible for Google to get any stats whatsoever from a site not running any Google services". Right?
Comment: @chris Right. You got it.
Answer: There are several possible ways that Google could get information about your website:

Google Analytics:  I know you already mentioned this, but I wanted to point out that Google has said they won't use Google Analytics data for ranking purposes.
Google AdSense, Google TagManager, or DFP: These are all 3rd party JavaScript on many web pages that could send data to Google the same way that Analytics does.
Google toolbar: The Google toolbar sends data to Google about every page that the user with it installed visits.
Firefox and Chrome Safe Browsing: Google runs a service that checks the reputation of websites that you visit.  It is enabled in both Firefox and Chrome by default and it sends information about each site visited to Google.
Other PageRank indicators: Other browser plugins that show the pagerank of a page also send the URL to Google for every page visited.
From ISPs:  ISPs often sell data about which pages their users visit.    I don't know that Google buys this data, but it could.   In the case of Google Fiber, Google is the ISP.
From DNS servers - Google runs its own popular DNS servers.   Users send queries to these Google servers to get the IP addresses of the sites they are going to use.
Comment: +1 for ISPs and DNS servers. It wouldn't surprise me if Google has a deal with one of the aggregators of ISP data like Hitwise.

Can Googlebot read any hosting stats?


Two weaker peltiers vs one stronger peltier for cooling?

Question: I'm planning on making a small water cooler for a project. I need to cool approximately 1.5L of water and have two TEC1-12706 (12v 6amp) peltier modules, and hoping to cool to as low as 6 degrees Celsius.
Would it be more efficient/effective to instead use a single Pelt such as the 12715 (12v 15 amp) or run the two separate lower rated ones? Or even two 12715s at half power for example?
Also any advice on calculating the ideal heat sink size/fan speed would also be very useful
Comment: This depends on your definition of better. If a quicker change is needed, then a larger surface area is better. If you can provide a larger interface between the water to be cooled and the peltier, then use whichever leads to that. My guess is many, lower powered ones can give a larger surface area.
Comment: Thanks. I will experiment. Do you think it would be worth attaching a heat sink on the cold side to increase surface area touching the water? I noticed a comment on stack saying that would just waste energy as it would impede transfer between the cold plate, but would appreciate your opinion?
Answer: If the water is stagnant, it's better to use two modules, one on each side of the container.  If you wish to use a heat sink for faster cooling, place it on the hot side as this will remove heat from the module and thus allow it to operate more efficiently.  From experience, I find that working the module at about 80% of full rated value is best for longevity. If speed of cooling is not a major concern,  connect the two modules in series across 12 Volts and each would receive the same current (but lower) at 6 Volts each and thus you would use only 1/2 the power as in the original design.
Answer: Using two peltiers is going to be better than one:
1) You will get twice the heat flow (equivalent to current) and twice the cooling rate.
2) There will be less self heating assuming that you run them at a lower voltage (ie series).
It is impossible to say anything else about your system (like how low the temperature will go, or fan speed) because you need to know what your heat in and out of the system is. The insulation around the tank needs to be known as well as the temperature on the outside of the insulation (or ambient temperature).
The insulation (or material if it is just some plastic) will leak heat in from the environment, the pelters need to be able to remove this heat. They can provide 80C of cooling with no heat load at 15 Amp (black line). If you wanted to cool to 5C and ambient is 30C (for a high mark), then you would need 25C across the peltiers, and one would give you 130W of cooling.
Answer: 6 degrees C might be ambitious for a single-stage Peltier cell.  You may want to consider cascading cells: have a large cell between ambient and a smaller cell that actually cools the target.
For example, I would seriously consider using the large 15A cell as the outside cooler with both of your smaller cells mounted to that large cell.  The smaller cells would be wired in series (as per one of the comments) to better equalize the cooling ratio.  Obviously, the cool side of the smaller cells contacts the target.
Answer: The aforementioned "heat sink in the water" idea would be good. I have worked for a place that builds giant radiators for mining trucks and have a few engineers in the family.
1.) The more surface area and fins the better you will do. for air or water
2.) Water has a very high thermal mass (apparently one of the highest for everyday things). This means it takes a lot of energy to heat or cool compared to most things but will retain a lot of that warmth/cold.
Rocks also have fairly high thermal mass. other things like air can be cooled/heated quicker but will also loose their cool/heat quicker.
Comment: Please make sure you answer the question in the original post.
Answer: If you expand to a two stage cooling vessel how regularly would you need to extract/replenish the volume?  Would you cool the heat produced by the peltiers with a recirculation cooling system.
Generally you can put pelts with a heatsink wedged between them instead of directly stacking them.  They might only activate to a change in state such as the fluid needs sudden rapid heating and your modest lowpowered series of pelts get kicked into their higher mode of operation.
Adjusting the pulsewidth for them will ensure their greater longevity.  Some control them quite diversify with digital algorithm software
If you need to transport of cut the power first you can give it a power blast to bring temp of the fluid down perforehand.  Again your insertion losses
Both stages could be the same but with different volumes.
By pump or gravity dispersion of the chilled fluid the output/secondary vessel could have a long shallow shape.
A switch for the second stage could be time activated so that the loss of temperature on pour would be compensated then switches off or delayed from the time when deactivated.
With the series pelts on the main vessel you can still achieve the correct temperature and perhaps the volume that runs into the second stage is fairly negligible for any power losses while the fluid remains still, circulated or diffused with oxygenated or carbonated gasses.
What ever you transfer the the energy with like a heatsink or submersed radiatior might be as reasonable in design to hygine/cleaning as it would be for design performance.
All in all do seal the peltier from direct contact.  A plate of raw copper with heat transfer compound means you'd never need to open the vessel just to do some service or repairs.  The copper will give the greater surface area for distribution more effectively especially if factored to variable changes in load vs ambient to desired temperatures and it will also make multiple peltsxattached to it more synchronised to function.
10deg C ambient temperature swing or more in the 24hr day means the system needs variable and automatic control usually taken care of by a programmable thermostat with a variety of adjustable parameters.
One of these could be set for the secondary stage whereby the liquid will not outward flow until the nominated reset values have been made.
When the max is reached to system will switch the chilling until a parameter is reached to the higher range set temperature.
A simple programmable thermo controller will keep you as close to 6deg without going ballistic on customized softwarebased control systems.
You can also incorporate a boost function to get everything quicker working when from anambient off state.


Safest road route from Tangier to Togo

Question: A local NGO that is working with Togo is going to organize a convoy (2 trucks) to bring some educational and medical aid. They will enter to Africa through Tangier, Morocco and are going to drive to Togo. What's the safest route possible? Also if you know some tips to make it safer, it will be very helpful.
Comment: fantastic question, about time we got some good African ones.
Comment: as an aside, are you involved in the trip? How'd you get into this?  Working with an NGO in such efforts appeals greatly.
Comment: Haven't you considered to send the material per ship? It will be safer and probably cheaper.
Comment: @MarkMayo: I've been involved in the past, not in this project, but I'd like to help with the "planning" part :)
Comment: @lejohn: Yes, but the trucks are part of the cooperation material (don't return).
Comment: OK, but trucks can be shipped too, together with their freight. You might even find a carrier who is willing to sponsor it.
Comment: @lejohn: Yes, of course, but the price is higher than driving. But thanks! :)
Answer: Fortunately, there are experienced travellers who have done these sorts of trips in the past.
The various roads in Africa sometimes form together to make the Trans-African Highway Network.  When possible, using these would be optimal as they'd be more serviced, more frequented, better condition roads, and arguably safer.

You'd be joining Route 1 initially, down to Dakar.  A mainly coastal route continuing down the Atlantic coast of North-West Africa; substantially completeTAH 1 joins with TAH 7 to form an additional north-south route around the western extremity of the continent.
You'd be continuing on this TAH 7 route, also known as the Trans–West African Coastal Road, which is about 80% complete. Roads still exist in the incomplete stages, just not necessarily of highway standard.
This should take you all around to Togo.

The other option is Route 2 down through the desert.  This is probably faster and would have less border problems - except for one big one - the Algeria / Morocco border is currently closed.  This leaves you with the only realistic option being to head down the afore-mentioned coastal route.
Comment: It is easy to join Algeria from Europe. The argument against route 2 are serious safety concerns regrading southern Algeria. Caution is also advised in Niger. When using route 7, you have to monitor the situation in Casamance.
Comment: Route to is a no-go at the moment. I talked to people I know who travelled the route a couple of times, a closed border is not necessarily a problem in the middle of the Sahara... rebels who kidnap tourist are a show stopper however.
Comment: @lejohn - except that they've already organised (and specified) in the question that they're entering Africa in Tangier, so with the closed border, route 2 just isn't possible.  But probably a good thing, considering the safety concerns, as you mention :)
Comment: Perfect, I also believe that TAH 1 is safer due the problems in Algeria and Niger. I'll recommend that route.

Safest road route from Tangier to Togo


Is it possible to create shapefiles in ArcGIS and convert into SpatialNET?

Question: I'm looking at the prospect of working for a client who has implemented a SpatialNET solution. I have never used SpatialNET and primarily have experience with ESRI and Autodesk products. The client and Synchronoss (who owns SpatialNET) have both told me that the only solution is to purchase a SpatialNET license and VPN into their database. When I asked them about creating files in AutoCAD or ArcMap, they said it would not work. I find it hard to believe that the SpatialNET system is completely incompatible with them, especially considering that SpatialNET appears to be based off of AutoCAD. Anyone here have experience with this product?
Comment: do they read kml ?
Answer: Technically yes, it is possible. However there are no packaged tools with SpatialNET to do so, so if you were to do it (which I would advise against in the strongest terms) the method would be to build the data in ArcGIS and then bulk-load it to the Oracle Spatial back-end of the SpatialNET instance. (There is also a Python API that you could use to build a script to load data, but that's harder again.)
But I can see why both Synchronoss and the client have said no as it makes it very easy to break things. My advise would be to do as the client requested - purchase the license and VPN to their database (if nothing else with the AutoCAD experience it shouldn't be too hard to pick up SpatialNET).


Automatically update dynamic text in ArcGIS based on visible layer

Question: I am building a layout template in ArcGIS and am using dynamic text on the side. On the map I have multiple point feature layers. Each feature layer represents a different visit to a particular site. All layers have the same field headings in their respective attribute tables. I wish display the minimum value from the field 'URN', to 0 decimal places. I am currently able to do this but on a layer by layer basis using the 'minimum' option from the dynamic text menu. What I'm wondering is if it is possible to have a dynamic text box that displays the minimum value from the field 'URN' to 0 decimal places for any layer visible on the map. For example if I turn off 'Layer1' and turn on 'Layer2', the text updates to the minimum value in the 'URN' field of 'Layer2' instead, and so on.
Answer: Possible to have a dynamic text box that updates automatically based on the visible layer in ArcGIS. One way to do this is to create a Python script that updates the dynamic text based on the visible layer.
You can use the arcpy module to access the attribute tables of the visible layers and find the minimum value of the 'URN' field.
You can then use the UpdateTextElement function in the arcpy.mapping module to update the dynamic text element in the layout.
You can schedule the script to run at a certain interval so it updates automatically, or you can use an event trigger such as the OnFocus event of the TOC, so the script runs when the user changes the visibility of the layers.
<code>import arcpy
import arcpy.mapping as mapping

# Set the current map document and layout
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

# Initialize a variable to store the minimum value
min_value = None

# Loop through all the point feature layers in the map
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
    if lyr.isFeatureLayer and lyr.visible:
        with arcpy.da.SearchCursor(lyr, "URN") as cursor:
            for row in cursor:
                if min_value is None or row[0] < min_value:
                    min_value = row[0]

# Update the dynamic text element with the minimum value
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    if elm.name == "min_value":
        elm.text = "Minimum URN: {}".format(round(min_value,0))

# Refresh the layout
arcpy.RefreshActiveView()
</code>
You can use this script as a starting point, and then you can customize it to match your project's requirements.
You can schedule the script to run at a certain interval so it updates automatically, or you can use an event trigger such as the OnFocus event of the TOC, so the script runs when the user changes the visibility of the layers.
You can also use the script tool to run the script in the ArcGIS Pro or ArcMap to update the Dynamic Text.


Smart contract to strore and retrieve address and ID in blockchian using mapping

Question: I want to store  some address and their ids in blockchain using mapping and i want to know how to get the  stored addresses when searching with their respective IDs.
Answer: When using mapping one of the problems is that there is no way to enumerate over the values. Whatever you store in the mapping with a key can only be accessed with that key and no other way.
So, in order to store both the mapping data and data about which entries have mapping data you have to use two different structures. One mapping for the actual mapping and one array to store information about which keys have a mapping.
If I understood your question correctly you want some way to search through the added ids.
So here's a very simple example contract. If I misunderstood and you don't need any searching possibilities you can just remove the ids part. With the below example you can add some functionality to search through the ids array:
pragma solidity ^0.5.5;

contract Mapping {

    mapping(uint => address) map;
    uint[] ids;

    function mapAddr(address addr, uint id) public {
        map[id] = addr;
        ids.push(id);
    }

    function getAddr(uint id) public returns (address) {
        return map[id];
    }
}


Can I uninstall my Steam games but still have the save?

Question: I realize that there was a similar problem to this that was answered, but i want to be safe by asking this. I'm running extremely low on disk space and I'm thinking of buying games because of the upcoming Summer Sale, so I was wondering if I could just uninstall them, then reinstall them onto an external Storage. Thus I could save a lot of Gb and have an exclusive Storage for my games.
Comment: You can navigate to the save folder, copy out the save files, uninstall the game, reinstall it on the external storage, then move the save files back again.
Answer: Some games will keep your save data in a separate folder such as your documents folder on your computer, which means you shouldn't lose the data in those cases when you uninstall.
I also believe the Steam Cloud feature sure work on most titles in terms of keeping your save data.
But as Ben said it's always recommended to manually find the save yourself and copy it just to be safe.
Comment: I am not sure about Documents being safe. Frankly, they should not be, since after uninstalling a game you'd have no choice but to manually delete them.
Comment: Each game will potentially put the save in a different location.  Some are in the userdata folder within your steam installation, some will be in %appdata% folder, some will be in the corresponding "Local" folder (go to %appdata%, up one folder then into local such as `%appdata%\..\local`) and some will be in the same folder as the installed game.  You can google "where is my `insert game name` save steam" and that usually gives you enough information for the location of the save.  In most cases uninstalling a game keeps the save in its place, but don't rely on that..copy/move the save first.


How to create a new branch in a local repository taking code from a remote branch without doing any merging

Question: I've a branch on a remote repository and i want to bring that branch locally so i can do a rebase.
I've added the repo of the remote branch which is called github. If i do
git checkout -b feature/AIOEC-168
git pull github feature/AIOEC-168

a merge occur. I would like to copy feature/AIOEC-168 locally and then on that branch do git rebase develop, how can i do that?
Answer: Instead of git pull try git fetch:
git fetch github
git rebase github/feature/AIOEC-168

Answer: If you want a local version of the remote branch that also sets the remote's branch as upstream, use git checkout's --track flag:
git checkout --track github/feature/AIOEC-168

That will create feature/AIOEC-168 locally, it'll be identical to the github remote's version (and will also set up that version as the upstream tracking branch), and you can rebase from there with any rebase command you'd like.
Answer: On any halfway-recent version of git, you can just git checkout feature/AIOEC-168, which will detect the similarly-named branch in origin and create a local branch of the same name, tracking the origin branch.


Are the petroleum deposits correlated to the dinosaurs extintion?

Question: I am designing an alternate world where the meteorite that caused the massive dinosaurs extinction never hit Earth.
I am stuck in one point: If the massive deaths of the dinosaurs worldwide never happened, the petroleum deposits will not be the same as today?
I know the petroleum is formed with organic remains. So, if those massive amounts of corpses never decomposed into fossil fuel, will the actual deposits be more scarce? or is there no correlation at all?
Comment: Real-world questions are on-topic so long as worldbuilding context is provided, and that has been done.  I'm voting to leave the question open.  However, the issue might be moot.  Carlos, there is a hot debate in the world as to what actually causes petroleum deposits.  Contrary to @John's bold statement, nobody actually has definitive proof - either way.  And that's the problem.  Nobody can prove if the age-old belief that ancient organics (not just dinosaurs) cause petroleum deposits or if one of serveral other theories are correct.  I recommend you choose a solution and roll with it.
Comment: fossil fuels are not dead dinosaurs.
Comment: @John a small part of those are. https://what-if.xkcd.com/101/
Comment: @JBH there is actually not much debate about petroleum formation, there are creationism pseudoscience about it (because if coal is dead organisms it means the earth has to be old) There used to be more debate a few decades ago but even then no one thought they came from dead dinosaurs.
Answer: The short answer is, it wouldn't make a difference. The biggest reason is the sheer amount of biomass involved. With think of dinosaurs as pretty big, but in terms of total mass, they're peanuts compared to plant life, algae, and the like.
According to this What If, which goes into some detail on where fossil fuels actually come from,

There are a few things required for oil to form, including quick burial of large amounts of hydrogen-rich organic matter in a low-oxygen environment.
These conditions are most often met in shallow seas near continental shelves, where periodic nutrient-rich upwellings from the deep sea cause blooms of plankton and algae.

Compare that to the conditions after the Chicxulub impact. Obviously anything caught in the ensuing firestorms is going to be oxidized and not form hydrocarbons. There would be massive tidal waves, which could bury land-going life including dinosaurs in an anaerobic environment. On the other hand, most of the plants are thought to have died off from dust in the atmosphere, which would leave them free to decay in the typical, non-hydrocarbon-forming way.
On the whole, although the impact might've contributed to fossil fuel formation, it would be barely a blip compared to the effects of hundreds of millions of years of accretion of biomass.
Comment: Precisely; the OP is forgetting that photosynthesis began 2.5 **billion** years ago [The Great Oxidation Event], and the Chicxulub meteor did not interrupt that hardly at all; the nuclear winter interrupted photosynthesis about 3 years, and most plants we have today evolved 100s of millions of years **before** that, and survived the event. Trees first appeared 390M years ago and were dominant by 300M years ago.
Answer: No real correlation at all.
Coal and other fossil fuels is from dead plants, not so much animals.
Just because dinosaurs got wiped out, it really wouldn't make any difference to oil and coal deposits
Comment: https://what-if.xkcd.com/101/
Answer: There are two theories held concerning the creation of petroleum deposits.
The first is the biogenetic theory, which can be summed up as, algae dies falls to the bottom of the ocean, is exposed to the right conditions and becomes hydrocarbons. This is an ongoing process.
The second theory is that atmospheric carbon dioxide is absorbed by the ocean, sinks to the bottom and then gets trapped in the mantle,  exposed to the right comditions and forms hydrocarbons. This is also an ongoing proccess.
Ok, I lied there is a third theory which is that in a recent 2014 study
both ideas work and are not mutually exclusive,  so the theory is that abiogenesis and biogenesis of hydrocarbons are both ongoing processes creating petroleum.
Dinosaurs played no part in the formation of fossil fuels.


I can't shut of the hot water completely

Question: I have a leaky shower. I bought new inserts to replace the valves in the faucet handles. I shut off the water at the main coming into the house and then removed the hot water side first. When I removed the valve a quarter inch stream of hot water continued to flow out of the pipe. As the hot water heater in in the basement and this bathroom on the floor above I don't think it a gravity issue of any kind. I replaced the valve and that stream of water continued to leak, but now out of the faucet. I can't seem to get it stopped. Any help would be appreciated!
Comment: Can you add some pictures? Maybe a brand or model number?
Answer: Go back and once again turn off the water main valve where cold water enters your house. Then go to various sinks and bath areas and turn on the faucets there. These will allow the water from higher level piping to drain out and break any potential siphon action that may have been occurring in your shower where you were trying to do the repair.
There are a number of reasons why a replacement of part of that hot water valve insert may not be working:

The wrong style of insert is being used.
The insert may be too thin.
There is debris in the faucet body that prevents the faucet stem from being turned completely in to bottom out the insert.
There a crack or corrosion damage of the seat part of the valve that prevents the new insert from even working.
Comment: Thanks for the answer! I'm not at home at the moment but I know the fixture is American Standard from the late 60's/early 70's. I could not find the correct American Standard replacement so used a generic analog found at a local hardware store, (so I assume #1 above may be the culprit). Just seemed weird that so much hot water came out after shutting off the main, and with such force! I waited for over an hour for the flow to diminish and it did not... Still, I will continue my search for the proper American Standard fitting.
Comment: @MarkSprowles - Is there any chance that where you tried to turn off the water supply that you were just closing a valve that fed just the cold water lines in the house? It is possible that the water heater may have been still connected to the main input...especially if you left it running for an hour.  :^)


Alternative Power Source T-800 Terminator 2 Judgement Day

Question: From the movie, can it be deciphered, where the alternative power source from the T-800 was located? It does show a schematic on the camera. Any further insight on this?
Answer: Nothing useful, I'm afraid. The schematic shows an "Aux Batt" (presumably an Auxiliary Battery) providing "reserve power" but no indication of where it's actually located. Given the fact that it's positioned on the blueprint next to a CPU cluster, I'd guess it somewhere inside the head but who the heck knows?

Oh, and the novelisation is no help either.
Comment: @ArvinGBorkar - It's an invention of later films that the power cell is explosive.
Comment: I was curious because, at the last part, when the T-800 is lowered into the molten steel, nothing explodes. Could be the reason that the alternative power source was in a location, with just enough power to kill the T-1000.
Comment: But if that were the case, when punctured by the T-1000, why was there so much energy radiating from it? If you take any battery and put fire near it, it will most probably explode. Even in the first film, when the Terminator's upper torso is crushed, there were HUGE electric currents radiating from whatever the power source, within it, was.
Comment: @ArvinGBorkar - The first terminator's primary power cell was supposedly nuclear. There's no special evidence to suggest it's *explosive* in the presence of fire, though.
Answer: "Uncle Bob" used the thermal energy generated by the smelter and accumulated in its internal heat sinks to reboot. A temporary measure to stay "alive", at best, and have a last shot at the T-1000. It worked...
Not actually explained in the movie, but the T2 Extreme DVD text commentary says:
Terminator drew upon the potential energy in his heat sinks to jump start his internal systems since his main power cell was ruptured and discharged by T-1000's attack"
Source: http://www.jamescamerononline.com/T2FAQ.htm
Comment: Although not untrue, this doesn't answer the question asked (e.g where are they located)
Comment: Funny how I looked at this question and found that it was a really good answer, if I had asked "how". Then I looked back and forgot that I had asked "where". But yes, my question was still "where".


Correlation and implied volatility

Question: Say I want to write call options on a stock, with no options written already on it. I know some asset which is highly correlated to it.
How can I proceed to make use of the correlation between this asset and the first one, to recreate some implied volatility surface on this unknown option ?
Answer: This is a problem commonly faced by investment banks and buy-side firms (such as hedge funds) that deal in lots of derivatives.
There isn't much more one can do than employ a few rules of thumb, and those rules have not changed much over the decades.  In this case, those tricks look something like the following:
First, let's assume you have your stock $S$ with no observable option prices in the market.  Furthermore, you have found the asset $A$ which is "most similar" to $S$.  (The rules of thumb blow can of course be generalized to set of similar assets $\{A_1,\dots\}$).

Decide on a linear relationship you want to assume between the two, for example
$$
\sigma_S = s(\sigma_A) = c + b \sigma_A
$$
where usually you force either $b==0$ or $c==0$.

If you at least have a price history for $S$, then get a historical volatility $h_S$, as well as its analog $h_A$ for $A$.  Normally you do this a 1x to 5x the tenor of the options you ultimately want to price.  Find $b$ or $c$.

If you have no price history for $S$, then just assume something reasonable for $b$ or $c$.

Map at-the-money volatility $\sigma^{(\mathrm{ATM})}$, obtaining $\sigma^{(\mathrm{ATM})}_S$ from $\sigma^{(\mathrm{ATM})}_A$ as
$$
\sigma^{(\mathrm{ATM})}_S = c + b \sigma^{(\mathrm{ATM})}_A
$$

Standardize the implied volatility skew for $A$.  First, instead of marking volatilities in $(K, T)$, space, mark them in moneyness terms $(M, T)$ where $F$ is the forward price and moneyness is
$$
M=\frac{\log(K/F)}{\sigma^{(\mathrm{ATM})}\sqrt{T}}
$$

Now, for any strike $K_S$ on an $S$-option, we have the $S$ ATM volatility $\sigma^{(\mathrm{ATM})}_S$, so we can obtain its moneyness $m=m(K)$.

Take that moneyness, and find the $A$-option volatility for the same moneyness (usually by interpolation) $\sigma_A(m)$.

Set the $S$-option volatility to be
$$
\sigma_S(K) = s(\sigma_A(m))
$$

You can repeat this for all strikes and tenors, obtaining a decent guess at a full volatility surface for $S$.
If you are quoting options, put a nice big spread on your derived volatilities $\sigma_S$ before giving any quotes to the counterparty.
If you later want to get some correlation coefficient $\rho$ between $S$ and $A$, and then price $S$ options by decomposing $S$ into $A+G$, where $G$ is idiosyncratic, you can do that, but you will need to have the volatility surface for $S$ first anyway.
Comment: Wow thanks a lot, the goal in the end is indeed to quote those 'newborns' options. I will try the method you just exposed and will come back to you If I have questions again.
Comment: Does this method enable to have a reliable skew ? I obtain some realistic values for ATM prices using It but it drifts for ITM options.
Do you know a method similar to obtain a better guess of the skew ?
Answer: EDIT:
Apologies, one more edit, but an important one:
Note, as kindly pointed out to me by an interested reader a short time ago: there is a potential issue with the simple model I proposed. Namely, as it stands the model implies that the illiquid asset$Y_t$ is not a martingale. But all is not lost; the model could potentially still be used if the illiquid asset is not tradable (in which case it doesn't have to be a martingale), for example the VIX Index.

Original answer:
I've been thinking about this question for some time. In addition to @Brian B's answer, giving here another route to constructing the skew for asset $Y$ given the skew for another asset $X$, where $X_t$ is a positive price process.
I'll state the assumptions first:

$d\ln (Y_t/Y_0) = \beta d\ln (X_t/X_0) + d\ln (Z_t/Z_0)$, and $d \ln X_t\, d\ln Z_t = 0$
$\beta$ is constant (maybe can be extended to it being deterministic) and can be regarded as the regression coefficient of logreturns
$Z_t$ is also a positive process that drives the error term $d\ln Z_t$ of the regression and has a known distribution $q(z)$

From assumptions (1) and (2) it follows that
$$
\frac{Y_T}{Y_t} = \left(\frac{X_T}{X_t}\right)^\beta \frac{Z_T}{Z_t}
$$
The price of a vanilla option on $Y$ is then
$$
E_t \left[ \left(Y_T - K\right)_+ \right] =
E_t \left[ \left(\frac{Y_t}{X_t^\beta Z_t}X_T^\beta Z_T - K\right)_+ \right]
$$
Since by assumption (1) $Z$ is independent of $X$, and by assumption (3) the distribution of $Z$ is known, we can write
$$
E_t \left[ \left(\frac{Y_t}{X_t^\beta Z_t}X_T^\beta Z_T - K\right)_+ \right] = \int_0^\infty E_t \left[ \left(\frac{Y_t}{X_t^\beta Z_t}z X_T^\beta - K\right)_+ \right] q(z) dz
$$
The expectation in the integrand is a claim on $X^\beta_T$ and can be synthesised using plain vanilla options on $X_T$ by making use of the Carr and Madan formula. Hence, since $q(z)$ is assumed to be known (for example the ubiquitous lognormal distribution), you can calculate options on $Y_T$ and infer the corresponding implied volatilities.
Remarks:

Typically $\beta$ and $q(z)$ are inferred from historical data since the regression and error is based on historical data. For pricing purposesyou'd therefore have to make an educated guess about the risk-neutral values.

Although $\beta$ was assumed to be constant, you could still use this in an 'uncertain beta' framework. For instance, suppose you are comfortable with $\beta \in [\beta_1,\beta_2]$. Then calculate the skew of $Y$ for both $\beta_1$ and $\beta_2$ and based on that decide what works best for your risk appetite.

Other than the assumptions, no approximations are used, i.e. the computation of the skew of $Y$ is `exact' (whatever that means in practice).

To the best of my knowledge the approach outlined above has not been treated in derivatives pricing papers about this topic (but happy to be corrected here if someone has come across it), even though it is actually similar to how one would go about pricing a geometric basket. So I'm curious, if you decide to use this, what results you obtain.
Hope this helps.
Comment: I've worked on related application, basket correlation skew.  In your assumption 1, Y would be one of the stocks in the basket and X the market asset. So we express each stock as beta x mkt + idiosyncratic term Z. If the distributions of X and Z have closed form characteristic functions (eg merton jump or heston), then you can calculate options on the geometric basket of Y_i using Fourier pricing methods. This can develop realistic basket correl skew in an intuitive manner. Think you have a nice idea here too Frido.
Comment: If one takes, say, $\beta=2$ and $Z$ to be a constant, then this turns into the formula for a "power quanto option" with power 2, since the payoff is now basically $(c \cdot X^2 - K)^+$.  I would be a bit nervous about imputing skews from that.
Comment: @JamesSpencer-Lavan thanks for the encouragement. Happy to work on this / exchange thoughts with you, I suppose relative value is the applicaton you have in mind. Knowing the distribution of $X$ helps but not strictly necessary given Carr-Madan can be applied. Yes, I am starting to think this `simple' framework might work.
Comment: @BrianB Fair point - I have no answer to that at this point. The level of the Y volatility will certainly be higher then (which makes sense if the beta is 2) and I think that's OK, but I need to think about the impact of this on the skew.
Comment: @BrianB See my recent edit. Not sure if this was implicitly what you were referring to as well.

Correlation and implied volatility


Auto add dimension annotation to vector file

Question: Are there any software to auto add dimension annotation for vector file  ?
for example
Comment: There might be a plugin for Illustrator, but it is a normal feature in CAD programs. Take a look at LibreCAD for example. It's free and seems alright.
Comment: Your drawing is under constrained so a automatic dimensioning tool would make more dimensions
Answer: Most mechanical CAD applications can do this. Inducing:

Creo
Solidworks
NX
Fusion 360
SolveSpace (free)
...

However note the computer does not know which dimension scheme to use so you would still need to tweak the results in most cases. Anyway please note that not all cads work this way for example Catia V5 does not and same applies to FreeCAD which attempts to be everything that is bad about Catia.
Anyway cad applications are bidirectional. So if you change the value of a dimension then the drawing will change to match suit.

Image 1: CAD applications retain dimensions and react to dimension changes
Comment: Corel Draw also has an auto dimension tool
Comment: @AasimAzam write that as an answer.
Answer: 2024 Update
The latest release of Adobe Illustrator, now has a dimensioning feature which may work for you.

Original 2017 answer below
HotDoor.com offers the CadTools plug in for Illustrator. It's designed to bring some CAD features into Illustrator, including dimensioning. HotDoor has been around since the 80s or 90s, so they aren't a "fly-by-night" developer in any sense.

I've never really used it in any sort of "robust" manner. So, I can't directly state whether it's suitable for you or not. But it's worth a shot. There is a free demo.
Comment: Yes but that's not auto dimesnioning. Its more like manual dimensioning. Auto dimesnioning actually knows howe a object should be dimensioned to me a complete description of the thing
Comment: I know Joojaa :) But if one knows Illustrator this *might* be enough.
Comment: Well sure, but if this is the case then the list of potential applications that fulfills the need is staggering


If Pentaho is Open Source, can I just use it?

Question: I see that Pentaho wants to charge me for their software. How can I get to the underlying Open Source software for dashboards to see what it can do without having to deal with Pentaho marketing folks?
Answer: Most commercial open source editions have a community edition that the community hacks on if the license permits it*. Pentaho is no different from them and has a community edition.
In these cases, the "community edition" is not the same thing as the commercial product you would buy. You may find a lot of the gloss and even some, if not a lot of the features are missing. There's no support. Yadda yadda yadda. You get the picture.
*As others have noted, not all "open source" apps need to distribute the source code in the same way as, a GPL application would. Open source, in rawest forms, just means as a licensed user, you get to see the source code.
Answer: Just to provide detail on what pentaho do and dont provide - they do provide a very complete BI platform as part of the community edition.
The only things that the enterprise edition include are a web based dashboard designer and a few other bits and bobs - i.e. not very much at all.
As mentioned above the benefit to becoming a subscription customer with pentaho is that they provide support, which for us was very useful in our final implementation.
Check out their forums too though - they are very active, and as long as your questions arnt complete newbie ones they are very helpful too.  I sometimes use the forums despite having a support agreement as i know it can be quicker.
Answer: "Open source" is not the same thing as "free" (either "as in beer" or "as in speech").
As much as I'm not a fan of Stallman in general, this article will probably help clear up the distictions a bit: Why "Open Source" misses the point of Free Software
Comment: You can't say that here! This isn't a designated Free Speech Zone!
Comment: free speech isn't even as free as people tend to think it is. woo! off-topic political discussion!
Answer: Open Source != Free
IANAL, but I'd say you're bound to the license that the software is under.
Answer: Suds get your free download of the code from http://sourceforge.net/projects/pentaho/
They have an IRC chat channel as well that ive found to be extremely helpful.


International Currency Formatting Guidelines — Currency Codes

Question: While developing a web application that presents monetary data for a variety of locales, I am inquiring about the differences of currency formats. In particular, I'd like to know when it is appropriate to use currency codes, either in addition to or instead of currency symbols.
It's my understanding that all mainstream currencies require that a currency symbol be included, but some show them in different order (as seen on this website). The four currencies that I facilitate in my application are USD, CAD, GBP, and EUR — all of which have the same general currency format.
It makes sense to include the currency codes for USD and CAD, since they have the same currency code, but what about the others? What's the norm in these other countries?
I have below what I think to be the correct formats. Please let me know if I have made any mistakes:

• United States  — $1,234,567.89 USD
• Canada           — $1,234,567.89 CAD
• Great Britain   — £1,234,567.89 GBP not £1.234,89 (ever)
• European            — €1.234.567,89 EUR

Also, should there ever be spaces between the currency symbols and the numbers? That is yet another thing I do know happens sometimes, but am not sure what the rules are.
......
Comment: Don't forget **₹1,23,45,678.90 INR** `:)`
Comment: Ireland would write `EUR 1.234.567,89` as `EUR 1,234,567.89`: so a) use US/British commas and periods, and b) only use `€` or `EUR` not both.
Comment: While I agree that using `€` and `EUR` both is strange, I think I have to for consistency in this case. It's good to know that in other applications that's not what one should do.
Comment: How can I get all countries, currency formats?
Comment: Not all of the countries use those types of format, [Display Formats](http://www.thefinancials.com/Default.aspx?SubSectionID=curformat) Some like Chile for example, don't use decimals, thus don't need decimal separators.
Answer: I'll just answer for the Euro:

European      — €1.234.567,89 EUR

Normally you'd use either the euro symbol or the 3-letter abbrevation, not both at the same time. The combination looks a bit odd, but is perfectly understandable.
The style guide used by the institutions of the European Union includes rules for expressing monetary units. The most important ones:

Use the written name ('an amount in euros') when a monetary unit is referred to generally but an amount is not included
ISO code 'EUR' followed by a fixed space and the amount in figures in written text (compulsory in legal texts). (In English, Irish, Latvian and Maltese. In all other official EU languages the order is reversed: 250 EUR).
The euro sign € is primarily used in graphics. However, its use is also permitted in popular works and promotional publications (e.g. sales catalogues). No space after the euro sign: €35.

My personal preference would be €1.234.567,89 for most texts (that feels most natural and familiar) and 1.234.567,89 EUR for legal/formal documents (or EUR 1.234.567,89 when written in English).
UPDATE: Complete list of currency formats.
Comment: What about ranges? I wonder if this use of the sign would be correct to say 0,10 to 1 euros:  €0,10 - €1
Comment: What about displaying a negative amount in a region where negative monetary amounts are typically displayed with parenthesis around them? Would it be something like `Balance: (EUR 1234.42)` or `Balance: EUR (1234.43)` or something else?
Answer: First of all, you need to be consistent. You can't show the currency code for some currencies but not for others, just because they don't have a unique symbol. You also can't rely on all your users knowing the symbols.
Regarding the format - maybe I'm misinterpreting your question, but it seems like you want to present each currency in the format customary in that country. This is not a good idea - the format isn't part of the currency, it's a regional preference. The same differences exist for math notation (commas vs. full stops as group and decimal separators), but we don't go citing the number of people in Russia as XXX.XXX,00 and in the US as XXX,XXX.00 :). Just as we don't change the time or date formats to reflect the preferences of the country we're referring to. The format should reflect the regional preferences of the user's location, not the subject.
Comment: You make a good point of the format reflecting the location of the user. The application assumes that the currency a user selects reflects their location, though, so I think I'm good.
Answer: Depending on the country, in Europe we use the symbol € on the right, like this: 3.000,00 €
For example in Spain, Germany and France it goes usually on the right but in Italy goes on the left.
Comment: I'm from Italy and I can say that it is also acceptable on the right. Personally I prefer it on the right, since it is normal for other units to be on the right. I have also noticed that amazon.it writes prices like this `10,00 €`.
Answer: I can't speak for other countries, but your presentation format for GBP is wrong - the group separator is the comma and the fractional separator is a full stop i.e.

£1.234.567,89 - wrong
£1,234,567.89 - correct

Actually, the page you linked to does show the UK presentation format correctly.
Comment: I'll second this.  The one to watch is German as it uses commas and dots the opposite way around.  I once worked on a software system with a web interface which had been developed in Germany: its back end processing didn't like Brits using it one bit as it tried to interpret big numbers as very small ones...
Answer: At least in Germany, the normal separator is a space:
€ 1 234 567,89.

(Make sure to use a non-breaking space, though: nbsp;).
However, 1.234,00 is perfectly understable, while 1.234 would be confusing.
Sources:

Wikipedia uses ' or (space) for Switzerland/Liechtenstein (not Germany)
ISO 1000 (SI system used in physics) recommends to use either , or . as decimal seperator, and a narrow space as thousand seperator. (Deprecated since 2009 in favor of ISO/IEC 80000-1)
There is no DIN norm about this? Can't believe that ...
Comment: Well, I'm a native german and live there for 42 years now and have rarely seen the space being used as a separator. Everyone I know uses the dot (.) as a separator. The space looks irritating if it's not a narrow one as proposed by ISO 1000... Using the . is definitely common practice in germany.
Comment: Cannot upvote (less reputations), but this is incorrect. Closest call is french formation with `1 234 567.89 €`.  Other EUR countries format `1,234,567.89 €`
Comment: This is totally **incorrect**. I live (and code) in Germany and here we use `.` (dot) for thousand and `,` (comma) for decimal separators. The French are the ones using space for thousand separator (honestly, it looks awful...)
Comment: Using a no-break space as the thousands separator and a comma `,` as the decimal separator is common not in Germany, but in Poland. I've lived in both countries and regularly construct legal documents.
Answer: Your style is certainly adequate, unless you have a particularly fussy userbase.  But it may not be standard, except in some constrained context, and almost exclusively to differentiate USD$ from CAD$, as € and £ aren't (very) ambiguous.
I've seen CAD$1,021,091.21 , which has the advantage of having the country named adjacent to the currency symbol, and the disadvantage of being cluttered near the most significant digit.
Whose standard should you choose?  Perhaps look to MS Excel and publishers-to-the-world  NYTimes, The Guardian, etc..