NAK in CAN when programming stm32f407vg uC

Question: I am getting NAK error in CAN communication. Not really sure why, also frame itself is quite strange as in program I am sending different things. I have got two devices and therefore I monitor 4 logical pins:

Device first (first and second logical view) CAN1 Tx(1) and Rx(2)
Device second CAN2 Tx(3) and CAN2 Rx(4)

A screenshot from saleae of two frames is shown below:

First frame in zoom looks like:

It's the first frame in zoom. I get error as CAN2 keeps high state all the time.
Second frame (and all later) in zoom looks like:

The thing in last on CAN1 Tx is NAK and on CAN1 Rx and CAN2 Rx is ACK. In zoom:

what I want to do in fact is:

Run CAN at 100kB/s
CAN1 and 2 sends the same message (CAN2 in fact does not send anything as    CAN1 and CAN2 sends the same thing)
I want to send/receive 8 bytes of data(for the time being it can be anything)

And the code responsible for setting the CAN is :
CAN_InitTypeDef canInit;
RCC_APB1PeriphClockCmd(CAN_CLK, ENABLE); //enable clock

CAN_DeInit(CANx);

/* CAN cell init */
canInit.CAN_TTCM = DISABLE;
canInit.CAN_ABOM = DISABLE;
canInit.CAN_AWUM = DISABLE;
canInit.CAN_NART = DISABLE; //retransmission
canInit.CAN_RFLM = DISABLE;
canInit.CAN_TXFP = DISABLE;
canInit.CAN_Mode = CAN_Mode_Normal;
canInit.CAN_SJW = CAN_SJW_1tq;

/* CAN Baudrate = 100 kBps (CAN clocked at 42 MHz(168MHz / 4)) */
canInit.CAN_BS1 = CAN_BS1_11tq;
canInit.CAN_BS2 = CAN_BS2_8tq;
canInit.CAN_Prescaler = 21; // 42MHz/21 | 2MHz/(11+8+1)
CAN_Init(CANx, &canInit); //CANx == CAN2

/* CAN filter init */
CAN_FilterInitTypeDef  canFilterInit;
canFilterInit.CAN_FilterNumber = 0;
canFilterInit.CAN_FilterMode = CAN_FilterMode_IdMask;
canFilterInit.CAN_FilterScale = CAN_FilterScale_32bit;
canFilterInit.CAN_FilterIdHigh = 0x0000;
canFilterInit.CAN_FilterIdLow = 0x0000;
canFilterInit.CAN_FilterMaskIdHigh = 0x0000;
canFilterInit.CAN_FilterMaskIdLow = 0x0000;
canFilterInit.CAN_FilterFIFOAssignment = 0;
canFilterInit.CAN_FilterActivation = DISABLE; //do not use filter at all
CAN_FilterInit(&canFilterInit);

/* Enable FIFO 0 message pending Interrupt */
CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);

Frame is as follows:
sendMessage.StdId = 0x7FF;
sendMessage.ExtId = 0x1FFFFFFF;
sendMessage.RTR = CAN_RTR_Data;
sendMessage.IDE = CAN_Id_Extended;
sendMessage.DLC = 8;

for(int dataByte=0; dataByte<8; dataByte++){
  sendMessage.Data[dataByte] = 0xFF;
}

strongDelay();

while(1){
    CAN_Transmit(CAN2, &sendMessage);
}

I do not know what kind of information should else be provided, but what I see:

Id is completely different from the one, that I want to send
Frame is interpreted as RTR, but should be as DATA frame
Some of the bits are wrong as you can see them crossed out in the program
Frequency is just like the one I wanted (so it's not random thing, that is being send)
It rather is not caused by noise in connections (pseudo analog view seems ok)
transciever and other stuff should be ok, because it was bought as ready to go CAN boards.

Any help would be apprecieated, as I am running out of ideas what should I change.
Answer: So, what I did wrong was the fact, that I have forgotten to initialize RCC for CAN1, as it is always needed, when initializing CAN2


Do model species evolve away from Batesian mimics?

Question: Batesian mimics - palatable mimics of a poisonous species - are detrimental to the species they imitate. Predators learn which species are unpalatable by tasting some. If Batesian mimics are rare or nonexistent, few if any of these samples will be tasty and predators'll quickly learn to leave this species alone.  But if Batesian mimics are common, predators have good chance of being rewarded for attacking things that resemble the model species.  It would seem that an overabundance of mimics would create a condition for the model species to evolve to visually differenciate itself: is there any evidence that this occurs?
Comment: This paper may be interesting, https://academic.oup.com/biolinnean/article/32/4/337/2682777/Individual-selection-kin-selection-and-the
Answer: I have found some papers that support the hypothesis that an overabundance of Batesian mimics creates a condition for model species to evolve differentiating characteristics -- in particular,  Franks, D. W., G. D. Ruxton, et al. (2009). "Warning signals evolve to disengage Batesian mimics." Evolution 63(1): 256-267.
The authors argue that new conspicuous traits in unpalatable species evolve in response to mimicry, since a mimic that evolves conspicuousness without being a good-enough match pays full cost of conspicuousness without the benefit of its predator learning advantage.
Answer: There is an ongoing discussion in the literature on whether Batesian mimicry is always parasitic or can also be mutualistic. I don't know much about this discussion and won't be able to make a synthesis. I suspect semantics about what Batesian mimicry really will also matter in this debate.
In Parus major (and from the same first author), I could find an evidence supporting that Batesian mimicry is parasitic (Rowland et al. 2010) and another evidence suggesting it is mutualistic (Rowland et al. 2007) depending upon the details of the study system. Franks et al. 2009 suggests that in extreme cases, Batesian mimicry can indeed be parasitic.


Are there any database engines which will intuit the join condition based on the existing foreign keys?

Question: It seems strange to me that, when I've defined a foreign key, the engine cannot use this information to automatically figure out the correct JOIN expressions, but instead requires me to re-type the same clauses. Are there any databases, perhaps some kind of research project, that will inspect the existing foreign keys?
Answer: I'm not aware of any that use foreign keys (and that would can be messy if you have more than one foreign key back to the same table)
But Oracle will base joins off of name of columns if you don't specify a specific join type nor a join condition, or if you use NATURAL JOIN
Comment: -1 This is not right about Oracle behaviour, and neither was your answer that you link to. As pointed out by Gary (the third comment to your answer), "`natural join` has never been the default". Incidentally, Tom Kyte is surely right when he calls `natural join` [a bug waiting to happen](http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13430766143199)
Comment: Why would it be messy if you have more than one foreign key to the same table. If you are looking at it from the "parent" table perspective it should still be clear as to what record in the child you are interested in.
Comment: @Bitoff you might have more than one relationship between the two tables, and so not a composite key, but actually more than one foreign key to the child table.  Eg, in a previous job, we had a database of organizations, and in that table there are two links to my table of people -- head of the department, and the primary contact (usually, the secretary).  There was a foreign key in the opposite direction, as staff members are assigned to a department, until we had to break it out to support many-to-many relationships.
Comment: I know none of the common RDBMSes do this - as the question states, I put the question out there to see if anyone had heard of anything new in this area.
Answer: It would be really cool if I could write this
from calendar join table1

and the dbms would know that it needs to evaluate this.
from calendar
left join table1 on (work_date between (cal_date - 13) and cal_date)

Really cool.  But not every join is an equi-join.
FWIW, NATURAL JOIN is in the SQL standard. But I'm pretty sure I haven't used it in the last 25 years.
If you find yourself writing the same join clauses over and over, maybe you just need more views.
Answer: There are auto-complete utils for your editor of choice to auto-suggest appropriate join statements if typing is the concern. RedGate's SQL Prompt for handling SQL Server in SSMS & Visual Studio. I believe Quest's TOAD will handle Oracle and some of the other more popular RDMSs.
Comment: No real "concern", just wondering if this is something anyone is looking into addressing.
Comment: @TML I doubt anyone is worried about this as this is really in the domain of application logic to my understanding (where application logic is the things that don't pertain to running a database server, the things we get paid to do)


Mysterious usage of articles and singular/plural

Question: To the best of my knowledge, I believe the following four sentences are all grammatically correct, but why four different expressions for "dog"?
1. I like dogs;
2. Dog is a kind of animal;
3. The dog is the most lovely animal in the world.
4. A dog is able to run as soon as it's born.
Comment: https://english.stackexchange.com/a/147384/71740
Answer:

I like dogs;

Discussing a subject, in general, in the plural form, doesn't have an article.

Dog is a kind of animal;

This is not really correct and probably shouldn't in the list. It might fit a different phrase like "Beef is a kind of meat."

The dog is the most lovely animal in the world.

Discussing a subject, in the abstract, and using the singular form, can have "the" as the article. It's similar to case #1. You can choose between #1 and #3.

A dog is able to run as soon as it's born.

Sometimes it's convenient to talk about a single instance of a class of things. "A car horn is able to beep." "A kangaroo is able to jump."   The general abstract concept of kangaroos isn't able to jump, but a single one might be able to... so it sounds better to say "a kangaroo".
Answer: Sentence 1 is correct and grammatical.
   Sentence 2 would be correct and grammatical and natural if it were "A dog is a kind of animal" or "Dogs are a kind of animal".  As it stands, though, it's not a good sentence.
   Sentence 3 is correct and grammatical if you're referring to a specific dog.  However, it would be better as "The (or That) dog is the loveliest animal in the world."  It would not do to use this sentence to refer to dogs in general, though.
   Sentence 4 is grammatical as far as it goes, but it would be better as "Dogs are able to run as soon as they're born."  However, sentence 4 is not true.  Dogs are not able to run as soon as they're born.  Horses and certain other animals are able to walk and even run or at least trot, shortly--within an hour, typically--after they're born.  Whales are able to swim as soon as they're born.


accessing IIS externally?

Question: What do I need to do to allow external access to my win seven IIS webpage? My internal webpage is hiding behind a router and a firewall (Windows firewall) I need to be able to address certain aspects on my hard disk in order to build the webpage externally. Graphics sitting on my hard disk are not accessible? I used localhost and inetpub. The graphic is sitting inetpub/wwwwroot/fred.jpg.
Answer: First, make sure your ISP does not block port 80.
Second, ensure your computer is up-to-date on Windows updates.
Third, if your website uses an SQL server make sure that all requests are parameterised. Do not expose the SQL server directly to the Internet.
Fourth, you need to set the firewall to allow appropriate incoming connections to the web server. There is a pre-defined rule which you need to enable:

Go to "Control Panel" -> "Administrative Tools" -> "Windows Firewall with Advanced Security".
Choose "Inbound Rules" in the left pane.
Scroll down to "World Wide Web Services (HTTP Traffic-In)" where the Profile is "Domain". (Not the HTTPS one, further down.) Double-click it.
Choose the "Scope" tab. Under "Remote IP addresses" select "These IP addresses" and add the appropriate addresses or ranges which you wish to allow access from [1].
Possibly necessary for you: under the "Advanced" tab, choose "Enable edge traversal".
Under the "General" tab, select "Enabled" and "Allow the connection".

[1] This is to limit the number of hacking attempts your computer will be subjected to. It does not have to be an exact list - just a few /8 ranges (Wikipedia: Classless Inter-Domain Routing) would cut down vastly on the hacking attempts.
Fifth, In IIS Manager, select the web site you are going to be using and in the "Bindings" check that you have something set up for http. If this is the only web site on the computer, "All unassigned" should suffice. Once it is working, have a look in the IIS logs for the website to check what IP address requests come in on and refine the binding/add another one.
Finally, enable the pass-through on your router.
You should now be able to access the web site on your computer from outside.
For troubleshooting, the IIS logs are, by default, in C:\inetpub\logs\LogFiles.
There are services such as No-IP which allow you to have a domain name for the web site so that it does not matter if your external IP address changes - you can simply give clients a domain name instead of an IP address.
I may well have missed something out of all that, please let me know and I'll see about corrections.
Answer: You would need to open port 80 on your firewall/router to go to the address of this PC.  But be warned, opening service to the internet is risky business.  Keep the machine patched and expect hacking attempts.  Don't keep other important data on the same machine.
Comment: He would also need to give IIS-User the NTFS Read-Only rights to the jpg files that he says are not viewable even internally (if I understood the question correctly).
Comment: Why don't you add that as a separate answer.  It may be more what he's having a problem with.
Comment: I may do that if the OP edits his/her question to include more information about the problem, as I am not really sure at the moment.
Comment: thank you. What I want to be able to accomplish is to create a webpage on my IIS and give access to it to anybody simply by giving them an IP number. My router will allow me to set up a NAT connection with should obviate any security problems if I give access to port 80, but only through the router/NAT.

accessing IIS externally?


Equivalence Of Definitions Of Connectedness

Question: In Rudin's Analysis the definition of connectedness is given as follows:
$$$$A subset $A$ of a metric space $X$ is said to be connected if $A$ cannot be written as $$A= C \cup D$$ where $C$ and $D$ are separated sets.
$$$$But in Apostol's Analysis the definition of connectedness is given as :
$$$$A metric space $X$ is said to be connected if it can not be written as $$X =A \cup B$$ where $A$ and $B$ are non empty disjoint open sets of $X$
$$$$I want to know that one definition is for subsets of metric spaces while the other is for metric spaces. Are these two definitions same or do they have different meaning.
Answer: They are equivalent for topological spaces, not just for metric spaces. If $X=A\cup B$, where $A$ and $B$ are non-empty disjoint open sets, then $A$ and $B$ are also closed, since each is the complement of an open set, so
$$A\cap\operatorname{cl}B=A\cap B=\varnothing=A\cap B=(\operatorname{cl}A)\cap B\,,$$
i.e., $A$ and $B$ are separated. Conversely, if $A$ and $B$ are separated, then $A\cap\operatorname{cl}B=\varnothing$, so $B\subseteq\operatorname{cl}B\subseteq X\setminus A=B$, and hence $\operatorname{cl}B=B$. Thus, $B$ is closed, and $A$ is therefore open. A similarly argument shows that $B$ is open.
The first definition is more convenient for subsets, but there is still a kind of equivalence: $C$ and $D$ are separated sets in $X$ if and only if they are relatively open subsets of $A$; they need not, however, be open in $X$ (and generally are not).
Comment: Why $A$ and $B$ are also closed sets?? And what is $X$ is not a full space?
Comment: @user728159: The complement of an open set is always closed. Indeed, that is often taken as the definition of a closed set. And it is **given** that $X$ is the whole space.
Comment: But what if $X$ is not a full space??
Comment: @user728159: I have no idea what you mean by a 'full' space; that is not any kind of standard terminology. A space is a space. Here $X$ is the space in which we're working.


I want to redirect the user to profile page after they log in

Question: I want to redirect the user to profile page after they log in. i tried with some modules but those could not help. i am using D7 version of drupal and tried with login modules
Answer: Hope this will help  you,
In Drupal 7 you can use RULES instead of using any modules only if you looking for redirection.

Go to admin/config/workflow/rules/reaction/add to add new rule

Now enter the RULE name and select the event on which you want to trigger this RULE

Now its time to give some condition(if required) and to trigger the action.

In Action select Page redirect

Give the redirect URL and and check Force redirect

If the rule is not working means, there may be a other same event with higher weight. Therefore you need to increase you rules weight.
Comment: Thi is for the page once they login right.. this one i got it from login destination module. after login the user will have more menu's to browse. my question is which module helps me in making settings for the menu to be update dynamically as per the user login and allow them to browse their own data
Comment: how to do this to target previous page?
Answer: Install and enable the Login Destination module, It have the option to redirect to the specified page.

The Login Destination module allows you to customize the destination
  that a user is redirected to after logging in, registering to the site
  (7.x), using a one-time login link or logging out (7.x). The
  destination can be an internal page or an external URL. It is possible
  to specify certain conditions like referring pages or user roles and
  make the destination depend upon them. You may use PHP snippets to
  provide custom conditions and destinations. It is also possible to
  keep users on the currently visited page after logging in or out.
Comment: okay... is it possible for the logged in users to browse other menus related to their own content?


What do we achieve by imposing ARMA structure on a stationary stochastic process?

Question: Suppose we have some set of data $\{x_t\}_{t=1}^T$, which we model as a part of realization of stationary stochastic process $\{X_t|t\in\mathbb{Z}\}$. Now, as I understand, by a virtue of The Wold Decomposition, we can represent this process as $MA(\infty)$- series of elements constituting White Noise. Further, we can approximate this representation by a stationary solution of some $ARMA(p,q)$ equation. I perceive this as a justification of $ARMA$ modelling, where we restrict considered family of stationary stochastic processes to its particular subset: stationary solutions of $ARMA$ equations. Here, my question arises: what we achieve by doing this in a context of prediction? What are advantages of this approach over simply considering a $\textbf{linear projection}$ of a variable of interest on its past values, which minimizes $MSE$ among all linear forecasting functions?
Answer: Regarding the advantages of ARMA over a linear projection, i.e. an AR model:
In many cases, ARMA(p,q) offers a more parsimonious approximation of MA($\infty$) than an AR(p') could.$^*$ Due to the bias-variance trade-off, parsimonious models tend to be better at prediction.
$^*$I used p' to distinguish from p, as the do not have to coincide.
Comment: Thank you for your reply. I need one clarification: am I right in saying that due to The Wold Decomposition, we obtain a structure of our process, which we can approximate (e.g. by ARMA or AR models); this in turn enable us to simplify our expressions for optimal forecast procedures like conditional expectation and linear projection?
Comment: @Mentossinho, yes, absolutely.


Will downsize from 215/65R16 to 205/60R16 cause any issues?

Question: Left front tire blow out. Due for new tires and decided on decent used matching set. Drive home had vibration like balance. Technician said the wheel was not damaged. Also noted the size difference after I get home. 2004 Toyota Sienna 2WD Is there any easy way to determine if it's the tires or a damaged rim? Note rims are original equipment aluminum.
Answer: Useful resource here on tire sizes:
Tire Size Calculator
But the smaller tires are only slightly narrower and less than 1" smaller radius.  So I very much doubt that is the source of your vibration.  The only real downside is that these will cause your speedo to read a bit high and your engine to turn a bit faster at the same actual speed.
I'd have the balance checked, check the tires for out-of-round (they were used for a reason), and also check the wheel for damage and runout.


How to best utilize the new Type Equivalance features to host the MapPoint Control in a WPF Application

Question: How to best utilize the new Type Equivalance features to host the MapPoint Control in a WPF Application.
This is related to my other question about what is entailed as far as maintaining interop assembleis with regard to the new NoPIA and Type Equivalance features. But now I'm interested in actually getting a working implementation to show off how this could be used with regard to the MapPoint Control ActiveX control.
I was able to follow the advice about ensuring that the Embed Interop Types option in Visual Studio is set to True for my MapPoint reference and I'm able to compile and run code like the following within my WPF application which interestingly treats the MapPoint.MappointControl interface as if it has a constructor.
<code>private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var map = new MapPoint.MappointControl();

    if (map.ActiveMap == null)
    {
        map.NewMap(MapPoint.GeoMapRegion.geoMapNorthAmerica);
    }
}
</code>
This code seems to work so I'm guessing that the COM calls are all happening properly behind the scenes but the problem is getting this ActiveX control integrated into the control heirarcy for my Window. When using the older ActiveX introp methodologies from Windows Forms I would normally have the generated ActiveX control host which represents my ActiveX control but is also a Windows Forms Control as well which allowed me to host it within a Form or within a WindowsFormsHost in a WPF application. From my research so far it looks like I may be able to host the MapPoint Control directly in WPF by creating a class that inherits from the HwndHost class. This however seems like it may be a lot of work duplicating what the Windows Forms methodology used to generate within the interop assembly for free. My assumption was that with the new Type Equivalence features that we would be able to not only instantiate controls but also integrate these controls directly within a WPF or a Windows Forms app with little trouble as well.
Am I missing something? If not what is the most sane way to go about making use of the MapPoint Control in a WPF app? I'm hoping the answer is not to still have Visual Studio or the TlbImp.exe utility generate the old interop assemblies that we had been using in Windows Forms development.
By the way, I did find some details about different methods of importing a type library but I don't quite understand how it may apply to my situation.
Answer: I haven't used MapPoint with WPF, but I think you should only be manually using tblimp.exe for MapPoint 2006 (and earlier). I understand everything is automated for MapPoint 2009, 2010, and presumably MapPoint 2011 when it is released.
Comment: By automated you mean that Visual Studio automatically performs the behavior the TblImp.exe utility? Otherwise if there is some other way that doesn't involve managing the generated interop dll and such it would be excellent if you could point to some resources on the subject.


In admin some urls "?SID=XXXXXXXXXXXXXXXXXXXXX" are coming and it move to login page of admin

Question: I am working in admin and some weird time in URL "?SID=XXXXXXXXXXXX" are coming and then Login page is open on that url. But admin is login. Here XXXXXXXXXXX are some alphanumeric characters.
Comment: Do you want to remove SID from url ?
Comment: I am not getting why this is happening, if admin is login from other page and when i click on manage products page then it display ?SID in url with login page.
Comment: And it is issue in Windows machine only this time.
Answer: The SID is a "session ID". Magento uses this ID to track a user's activity
within the same Magento installation. Normally, Magento powers one website and one store from one installation (database).
Magento could power multiple websites with multiple stores from one
installation, though. The SID allows users to stay logged in while
navigating across these websites/stores.
I think if you have the function enabled, the SID is sent while accessing
catalog URLs so Magento can update the session with the user's
location/state for the current website/store.
If you're not running a multi-website or multi-store environment, it's
safe to disable the SID on the frontend, the ___SID=U is used in the cache as a placeholder for the session ID. It is replaced by Mage_Core_Model_Url::sessionUrlVar() which in turn calls Mage_Core_Model_Url::sessionVarCallback(). These methods are called from Mage_Core_Block_Abstract::_afterCacheUrl(), which means that any URL found in block output will contain the correct session ID (if needed).
So to get rid of the parameter in your own code the "right way" use this:
<code>$url = Mage::getUrl('some/magento/route'); // might append ___SID parameter
$url = Mage::getModel('core/url')->sessionUrlVar($url); // process ___SID
</code>
If the string is displaying in the rendered page that is a bug. Are you
using some custom caching module, or generating URL's using a non-standard way?


Is this small perpendicular wall load bearing to the structure?

Question: Curious to if this wall is load bearing or not. The ceiling joist span 16ft and the only interior wall that runs perpendicular is this small one here. All other interior walls run parallel and don't even land under a joist. Also added roof structure
Comment: Unless there is a beam on each side of the wall providing support for the other roof trusses, I do not think so.  There is no extra heavy weight above the wall?  Usually load bearing walls will go from end to end, or short walls with beams/headers in between.  But a structural engineer on sight will give the best advice.
Answer: If the bottom chord of the roof system is really 2x4s, they rafter ties not joists and not meant to support weight so any interior walls are definitively not load-bearing.
My first thought was that if those were joists, a tiny amount of cost could be saved by using smaller ones over the perpendicular wall or by using off-cuts and not continuous over that wall.   But if they are 2x4 rafter ties, none of that is likely at all.
Comment: yup, looks like a garage-type structure, 16ft 2x4s are ties not joists. 2x8 is minimum for 16ft span


cross-site XmlHttpRequest in Firefox?

Question: I understand (I think) that XmlHttpRequest objects adhere to the "same-domain" policy. However, I want to create a simple (POC) local html file that downloads XML from a web server and does something with it (let's start with a simple "alert()").
Is it possible at all? Do I need a special Firefox config option?
The server from which I'm trying to download is not under my control (it's actually a Google API).
My simple attempt is the code from Mozilla's "Using XMLHttpRequest" page. It returns an error I don't really understand from the "send" method.
Disclaimer: I'm mainly a C/C++ developer - never done any serious JS programming, never tried using these APIs.
Comment: I answered with a solution to work around the limitation in Firefox in another thread: http://stackoverflow.com/questions/330427/can-i-disable-sop-same-origin-policy-on-any-browser-for-development/2771363#2771363
Answer: XMLHttpRequest actually adheres to a much stricter implementation of the same domain policy: while you can set the document.domain property to allow JavaScript served from two sub-domains to talk with each other, you can't do that with XMLHttpRequestObject. In your case, going to a completely different domain, you couldn't do that with JavaScript either.
There are a couple of options. First, you can use a reverse proxy to make it appear that the external site is a sub-domain of your site. Take a look at Apache's mod_proxy, in particular ProxyPassReverse
Another alternative is to return data as a JSON object:

Then add a reference to the specific API(s) you plan to use to your page:

Now you can call the various functions provided by that API:

No XmlHttpRequest required :)
Comment: The API I'm trying to use actually directly returns a JSON object. But the object has no name, so how can I work with it?
If you're logged in to Google Reader, see:
http://www.google.com/reader/api/0/unread-count?output=json
Answer: You can use JSONP to do this.  I do it here using jQuery and PHP.  Basically I use the PHP proxy to wrap the JSON reply so jQuery can handle it.  It's under BSD.
Answer: Alternatively try using IE8.  If you are running from disk and not a website IE8 will ignore all normal domain restrictions and get the data you want.
Answer: With jQuery (and presumably XHR, but I try not to use it directly) you can happily do cross-domain requests, provided that you do not specify unusual headers or non-GET methods.  If you do want to use these, you must have control of the server to enable OPTIONS requests.
See https://developer.mozilla.org/En/HTTP_access_control for details.

cross-site XmlHttpRequest in Firefox?


What is the best or most common way to include web search terms within a complete sentence?

Question: I am looking for a good or common way to include search terms and phrases in complete sentences with clarity when the term/phrase begins and ends.  I do not want to include punctuation near the terms unless the punctuation is part of the term.  I am currently double spacing before the  search term  then continuing the sentence.  I would like to make the search term stand out more but using brackets or parentheses may cause the reader to mistake them for part of the search term.  Italics may give the impression that the search term should be written in italics.  Do you have suggestions, or is there a common way to express search terms that I have failed to find while searching the net?
Comment: what is it that people are reading? Can you provide a sample sentence for context? (Eg are you telling people what to search for, reporting what you searched for, or something else?)
Comment: Mechanical style issues such as this will depend where you want to publish. So talk to the editor or teacher or prof etc. and get guidance as approp. If it's for something you have absolute final say over (your web page for example) just pick something easy to read and stay consistent.
Comment: For example:  To find lessons search  how to play open chords and  guitar chord charts.  How do I separate the search terms from the rest of the sentence and not give the impression that punctuation is to be used as part of the search phrase?  The people reading are often young beginners of self taught guitar seeking resources.  I am not looking for how to quote a specific website.  I am looking for a good way to include a word or a few words in a sentence that are to be entered to the search bar of Google or another search engine, or a browser.
Comment: Boba Fit. Have you any examples of a mechanical style for search words/phrases?
Comment: Evidently there is no common way to emphasize search terms from the rest of a sentence.  I have experimented with commas, brackets, quotation marks, and double spacing.  The problem with punctuation is that the marks give the notion that they are part of the search term.  Maybe italics, if available, will work.
Answer: I think you have some wrong assumptions. Here are a few.
Search engines don't care about punctuation, capitalization, spelling errors and such. However, they can have some input syntax. So these example will give different results:

Hello world
hello -world
"hello world"
hello +world

Ad 1: anything containing hello OR world. Ad 2: anything containing hello, AND NOT world. Ad 3: anything with this exact phrase. Ad 4: anything with hello AND world.
Moreover, results depend on the search engine, on the user (yes, we all are tracked and categorized), time etc. Parenthesen may or may not be interpreted by the search engine.
Read-ability will be very low if you work with double spaces. It's hard to detect, unless you work with proportional fonts, like Courier. Spaces in typesetting are both operational asset (making it narrower or wider to fit lines, paragraphs or pages) and creative element (visual grouping by white space: your question would improve in readability by inserting a few new lines, e.g. for grouping topics).
Alternatives: If you read books on programming, which includes all web related topics, they introduce their font syntax in the beginning. See e.g. publisher O'Reiley. It may read like:

We use bold font to indicate whatever
while italics shall be understood as whatever2
and text like this indicates whatever3
after that they can use this convention in running text as well as in dedicated stand-alone paragraphs with special layout

If you write e.g. a novel you still can introduce your convention as relevant part of the story. E.g. the hero finds some key document, introducing this syntax, and repeating it, whenever he reads find a miracle at the end of the tunnel … and your reader will understand the info as needed (e.g. as resolution, task, puzzle, joke etc.) depending on your stories context and development.
Comment: I had no wrong concept for case sensitivity nor punctuation. I am simply trying not to give the impression to very young readers and those who use English as a second language that punctuation is part of the search term and be able to set the search term (words) apart from the rest of the sentence.  I guess bold or italics will do.
Comment: I have yet to find a standard for including internet search terms within a sentence.  I and currently italicizing them.
Comment: Did you skim through some computer books, e.g. from O'Reiley or some Dummy-series? They spent some time on making good layout and design choices with the reader in mind. (At O`Reiley you can read many books online. Or try books.google.com etc. for a skim)
Comment: Did you skim through some computer books, e.g. from O'Reiley or some Dummy-series? They spent some time on making good layout and design choices with the reader in mind. (At O`Reiley you can read many books online. Or try books.google.com etc. for a skim)
Answer: I have never seen a "mainstream" style guide have an opinion on this, but some of the specialized ones do. For example, Microsoft:

User input: Usually lowercase, unless case sensitive. Bold or italic, depending on the element. If the user input string contains placeholder text, use italic for that text.
Enter hello world
Enter -p password

(The lack of ending punctuation in the examples suggests that they wouldn't be inline but rather in a vertical list.)
Except for WYSWYG editors (which aren't used for searching), I have never seen an input accept emphasis or similar formatting. I would expect that all but the most inexperienced computer users would know that.
If you think that there may be some confusion for a particular search term or sentence, you can always clarify:

Search for "clothe" (including the quotes).

On the web, you also have another option available: format it like this. As the name says, this tag is intended for computer code, but I think it can be useful here. For visual readers, the background makes it clear what's part of the search term, even down to the punctuation. Screen reader users will also likely get a clear idea of what's in the search term (the exact behavior depends on the screen reader); with verbose settings, the code span will be read out loud, character by character, including punctuation which would usually be silent in regular text. Just don't overuse it.


Why do so many wikis use version control systems such as Git to store their data?

Question: What are the advantages and disadvantages of doing this, relative to using a database?  See https://en.wikipedia.org/wiki/Comparison_of_wiki_software
Answer: IMO, a version control system (VCS) like Git allows the administrators of a wiki to easily revert any changes, mistakes, misinformation that may be introduced to the content. They are fast and, in the case of Git, don't rely on only one single centralized repository to contain the content. Git is a distributed system, meaning all copies of a checked-out repository are complete and identical to the repo it was checked out from. This allows any copy of the repo to be restored or updated from most any one of the other distributed copies (this may or may not be relevant to wiki admins/designers/creators - ?).
However, with the development of very fast key-value databases and document databases (Redis, Couch, Mongo, etc) it certainly is reasonable to wonder why wikis use VCS, and why they stick with relational databases like MySQL and Postgres (FYI: there is a new wiki, Wiki.js taking advantage of JavaScript and MongoDB).


Create Balanced Binary Search Tree from Sorted linked list

Question: What's the best way to create a balanced binary search tree from a sorted singly linked list?
Comment: A few questions:
Do you know the number of elements in the sll?
Answer: How about creating nodes bottom-up?
This solution's time complexity is O(N). Detailed explanation in my blog post:
http://www.leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html
Two traversal of the linked list is all we need. First traversal to get the length of the list (which is then passed in as the parameter n into the function), then create nodes by the list's order.
BinaryTree* sortedListToBST(ListNode *& list, int start, int end) {
  if (start > end) return NULL;
  // same as (start+end)/2, avoids overflow
  int mid = start + (end - start) / 2;
  BinaryTree *leftChild = sortedListToBST(list, start, mid-1);
  BinaryTree *parent = new BinaryTree(list->data);
  parent->left = leftChild;
  list = list->next;
  parent->right = sortedListToBST(list, mid+1, end);
  return parent;
}

BinaryTree* sortedListToBST(ListNode *head, int n) {
  return sortedListToBST(head, 0, n-1);
}

Comment: I like this bottom-up approach a lot, and it indeed is O(N).
Comment: Why do we need to do list = list->next; ?
Comment: The blog post says page not found. Please can you help update the link?
Answer: You can't do better than linear time, since you have to at least read all the elements of the list, so you might as well copy the list into an array (linear time) and then construct the tree efficiently in the usual way, i.e. if you had the list [9,12,18,23,24,51,84], then you'd start by making 23 the root, with children 12 and 51, then 9 and 18 become children of 12, and 24 and 84 become children of 51. Overall, should be O(n) if you do it right.
The actual algorithm, for what it's worth, is "take the middle element of the list as the root, and recursively build BSTs for the sub-lists to the left and right of the middle element and attach them below the root".
Comment: I think it did it this way too. The only thing different is that instead of converting the whole linked list into int, I create a array of tree nodes. And then use recursion to link the tree nodes together, so we don't waste memory.
Comment: You should be able to build the tree as you traverse the linked list, without having to copy it into an array first...
Comment: The difference between our two algorithms is quite interesting (to me at least). You build the tree top down, I do it bottom up.
Comment: Well I find it interesting too :) Just taking a look -- I'd wandered off to do some work...
Comment: We both use a stack, too. Yours is implicit in the call stack and mine is an explicit one
Answer: Best isn't only about asynmptopic run time. The sorted linked list has all the information needed to create the binary tree directly, and I think this is probably what they are looking for
Note that the first and third entries become children of the second, then the fourth node has chidren of the second and sixth (which has children the fifth and seventh) and so on...
in psuedo code
read three elements, make a node from them, mark as level 1, push on stack
loop
    read three elemeents and make a node of them
    mark as level 1
    push on stack
    loop while top two enties on stack have same level (n)
         make node of top two entries, mark as level n + 1, push on stack
while elements remain in list

(with a bit of adjustment for when there's less than three elements left or an unbalanced tree at any point)
EDIT:
At any point, there is a left node of height N on the stack. Next step is to read one element, then read and construct another node of height N on the stack. To construct a node of height N, make and push a node of height N -1 on the stack, then read an element, make another node of height N-1 on the stack -- which is a recursive call.
Actually, this means the algorithm (even as modified) won't produce a balanced tree. If there are 2N+1 nodes, it will produce a tree with 2N-1 values on the left, and 1 on the right.
So I think @sgolodetz's answer is better, unless I can think of a way of rebalancing the tree as it's built.
Comment: What are the details when you make node of top two entries?
Comment: I'm not clear from the pseudo-code precisely what your algorithm is doing -- when you say "mark as level 1", are you marking just the middle element of the three as level 1, or are you marking all of them? Could you clarify?
Comment: I'm marking the node made from the three as level 1. It wasn't clear I was making a node with them, so I edited my answer.
Comment: @TimothChen, ah, foo, you've spotted a flaw. you need another value to use as the value of that node. It doesn't break the whole idea but I need to correct what's there. I think you just push another value onto the stack between the two nodes. Then pop the node, value, and node and make a higher level node of that. Too late for tonight to be certain its right (it's 10pm here)
Comment: @Paul: Same question as Timothy :) So you've got two nodes containing [9,12,18] and [23,24,51], and you combine them to make...?
Comment: Yes, there's a flaw. you need to have a node [9, 12, 18], the value 23, and a node [24, 51, 84]. Fixable, though.
Comment: It's fixable, certainly -- the issue is to fix it up in constant time I think.
Comment: I think it's fixavble by alwasy reading one more element and pushing it.
Answer: Trick question!
The best way is to use the STL, and advantage yourself of the fact that the sorted associative container ADT, of which set is an implementation, demands insertion of sorted ranges have amortized linear time.  Any passable set of core data structures for any language should offer a similar guarantee.  For a real answer, see the quite clever solutions others have provided.

What's that? I should offer something useful?
Hum...
How about this?
The smallest possible meaningful tree in a balanced binary tree is 3 nodes.
A parent, and two children.  The very first instance of such a tree is the first three elements.  Child-parent-Child.  Let's now imagine this as a single node.  Okay, well, we no longer have a tree. But we know that the shape we want is Child-parent-Child.
Done for a moment with our imaginings, we want to keep a pointer to the parent in that initial triumvirate.  But it's singly linked!
We'll want to have four pointers, which I'll call A, B, C, and D.  So, we move A to 1, set B equal to A and advance it one.  Set C equal to B, and advance it two.  The node under B already points to its right-child-to-be.  We build our initial tree.  We leave B at the parent of Tree one.  C is sitting at the node that will have our two minimal trees as children.  Set A equal to C, and advance it one. Set D equal to A, and advance it one.  We can now build our next minimal tree.  D points to the root of that tree, B points to the root of the other, and C points to the... the new root from which we will hang our two minimal trees.
How about some pictures?
[A][B][-][C]

With our image of a minimal tree as a node...
[B = Tree][C][A][D][-]

And then
[Tree A][C][Tree B]

Except we have a problem. The node two after D is our next root.
[B = Tree A][C][A][D][-][Roooooot?!]

It would be a lot easier on us if we could simply maintain a pointer to it instead of to it and C.  Turns out, since we know it will point to C, we can go ahead and start constructing the node in the binary tree that will hold it, and as part of this we can enter C into it as a left-node.  How can we do this elegantly?
Set the pointer of the Node under C to the node Under B.
It's cheating in every sense of the word, but by using this trick, we free up B.
Alternatively, you can be sane, and actually start building out the node structure.  After all, you really can't reuse the nodes from the SLL, they're probably POD structs.
So now...
[TreeA]<-[C][A][D][-][B]
[TreeA]<-[C]->[TreeB][B]

And... Wait a sec.  We can use this same trick to free up C, if we just let ourselves think of it as a single node instead of a tree.  Because after all, it really is just a single node.
[TreeC]<-[B][A][D][-][C]

We can further generalize our tricks.
[TreeC]<-[B][TreeD]<-[C][-]<-[D][-][A]
[TreeC]<-[B][TreeD]<-[C]->[TreeE][A]
[TreeC]<-[B]->[TreeF][A]
[TreeG]<-[A][B][C][-][D]
[TreeG]<-[A][-]<-[C][-][D]
[TreeG]<-[A][TreeH]<-[D][B][C][-]
[TreeG]<-[A][TreeH]<-[D][-]<-[C][-][B]
[TreeG]<-[A][TreeJ]<-[B][-]<-[C][-][D]
[TreeG]<-[A][TreeJ]<-[B][TreeK]<-[D][-]<-[C][-]
[TreeG]<-[A][TreeJ]<-[B][TreeK]<-[D][-]<-[C][-]

We are missing a critical step!
[TreeG]<-[A]->([TreeJ]<-[B]->([TreeK]<-[D][-]<-[C][-]))

Becomes :
[TreeG]<-[A]->[TreeL->([TreeK]<-[D][-]<-[C][-])][B]
[TreeG]<-[A]->[TreeL->([TreeK]<-[D]->[TreeM])][B]
[TreeG]<-[A]->[TreeL->[TreeN]][B]
[TreeG]<-[A]->[TreeO][B]
[TreeP]<-[B]

Obviously, the algorithm can be cleaned up considerably, but I thought it would be interesting to demonstrate how one can optimize as you go by iteratively designing your algorithm.  I think this kind of process is what a good employer should be looking for more than anything.
The trick, basically, is that each time we reach the next midpoint, which we know is a parent-to-be, we know that its left subtree is already finished.  The other trick is that we are done with a node once it has two children and something pointing to it, even if all of the sub-trees aren't finished.  Using this, we can get what I am pretty sure is a linear time solution, as each element is touched only 4 times at most.  The problem is that this relies on being given a list that will form a truly balanced binary search tree.  There are, in other words, some hidden constraints that may make this solution either much harder to apply, or impossible.  For example, if you have an odd number of elements, or if there are a lot of non-unique values, this starts to produce a fairly silly tree.
Considerations:

Render the element unique.
Insert a dummy element at the end if the number of nodes is odd.
Sing longingly for a more naive implementation.
Use a deque to keep the roots of completed subtrees and the midpoints in, instead of mucking around with my second trick.
Comment: I think I missed something, I was in a hurry and didn't do a formal proof.  Anyone see an error?  I think it'd almost be easier to hack up an RB-tree implementation.
Comment: I understand displaying your thoughts clearly to the employer. However when I was in the interview I only have 25 minutes from listening to the question on the phone to typing the working solution code on the screen. So I think this much words won't be able to finish it on time.
Answer: This is a python implementation:
def sll_to_bbst(sll, start, end):
    """Build a balanced binary search tree from sorted linked list.

    This assumes that you have a class BinarySearchTree, with properties
    'l_child' and 'r_child'.

    Params:
        sll: sorted linked list, any data structure with 'popleft()' method,
            which removes and returns the leftmost element of the list. The
            easiest thing to do is to use 'collections.deque' for the sorted
            list.
        start: int, start index, on initial call set to 0
        end: int, on initial call should be set to len(sll)

    Returns:
        A balanced instance of BinarySearchTree

    This is a python implementation of solution found here:
    http://leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html

    """

    if start >= end:
        return None

    middle = (start + end) // 2
    l_child = sll_to_bbst(sll, start, middle)
    root = BinarySearchTree(sll.popleft())
    root.l_child = l_child
    root.r_child = sll_to_bbst(sll, middle+1, end)

    return root

Answer: Instead of the sorted linked list i was asked on a sorted array (doesn't matter though logically, but yes run-time varies) to create a BST of minimal height, following is the code i could get out:
typedef struct Node{
     struct Node *left;
     int info;
     struct Node  *right;
}Node_t;

Node_t* Bin(int low, int high) {

     Node_t* node = NULL;
     int mid = 0;

     if(low <= high) {
         mid = (low+high)/2;
         node = CreateNode(a[mid]);
         printf("DEBUG: creating node for %d\n", a[mid]);

        if(node->left == NULL) {
            node->left = Bin(low, mid-1);
        }

        if(node->right == NULL) {
            node->right = Bin(mid+1, high);
        }

        return node;
    }//if(low <=high)
    else {
        return NULL;
    }
}//Bin(low,high)

Node_t* CreateNode(int info) {

    Node_t* node = malloc(sizeof(Node_t));
    memset(node, 0, sizeof(Node_t));
    node->info = info;
    node->left = NULL;
    node->right = NULL;

    return node;

}//CreateNode(info)

// call function for an array example: 6 7 8 9 10 11 12, it gets you desired
// result

 Bin(0,6);

HTH Somebody..
Answer: This is the pseudo recursive algorithm that I will suggest.

createTree(treenode *root, linknode *start, linknode *end)
{
   if(start == end or start = end->next)
   {
      return;
   }
   ptrsingle=start;
   ptrdouble=start;
   while(ptrdouble != end and ptrdouble->next !=end)
   {
    ptrsignle=ptrsingle->next;
    ptrdouble=ptrdouble->next->next;
   }
   //ptrsignle will now be at the middle element.
   treenode cur_node=Allocatememory;
   cur_node->data = ptrsingle->data;
   if(root = null)
       {
           root = cur_node;
       }
   else
      {
         if(cur_node->data (less than) root->data)
          root->left=cur_node
         else
           root->right=cur_node
      }
   createTree(cur_node, start, ptrSingle);
   createTree(cur_node, ptrSingle, End);
}

Root = null;
The inital call will be createtree(Root, list, null);
We are doing the recursive building of the tree, but without using the intermediate array.
To get to the middle element every time we are advancing two pointers, one by one element, other by two elements. By the time the second pointer is at the end, the first pointer will be at the middle.
The running time will be o(nlogn). The extra space will be o(logn). Not an efficient solution for a real situation where you can have R-B tree which guarantees nlogn insertion. But good enough for interview.
Answer: Similar to @Stuart Golodetz and @Jake Kurzer the important thing is that the list is already sorted.
In @Stuart's answer, the array he presented is the backing data structure for the BST.  The find operation for example would just need to perform index array calculations to traverse the tree.  Growing the array and removing elements would be the trickier part, so I'd prefer a vector or other constant time lookup data structure.
@Jake's answer also uses this fact but unfortunately requires you to traverse the list to find each time to do a get(index) operation.  But requires no additional memory usage.
Unless it was specifically mentioned by the interviewer that they wanted an object structure representation of the tree, I would use @Stuart's answer.
In a question like this you'd be given extra points for discussing the tradeoffs and all the options that you have.
Answer: Hope the detailed explanation on this post helps:
http://preparefortechinterview.blogspot.com/2013/10/planting-trees_1.html
Answer: A slightly improved implementation from @1337c0d3r in my blog.
// create a balanced BST using @len elements starting from @head & move @head forward by @len
TreeNode *sortedListToBSTHelper(ListNode *&head, int len) {
    if (0 == len)   return NULL;

    auto left = sortedListToBSTHelper(head, len / 2);
    auto root = new TreeNode(head->val);
    root->left = left;
    head = head->next;
    root->right = sortedListToBSTHelper(head, (len - 1) / 2);
    return root;
}

TreeNode *sortedListToBST(ListNode *head) {
    int n = length(head);
    return sortedListToBSTHelper(head, n);
}

Answer: If you know how many nodes are in the linked list, you can do it like this:
// Gives path to subtree being built.  If branch[N] is false, branch
// less from the node at depth N, if true branch greater.
bool branch[max depth];

// If rem[N] is true, then for the current subtree at depth N, it's
// greater subtree has one more node than it's less subtree.
bool rem[max depth];

// Depth of root node of current subtree.
unsigned depth = 0;

// Number of nodes in current subtree.
unsigned num_sub = Number of nodes in linked list;

// The algorithm relies on a stack of nodes whose less subtree has
// been built, but whose right subtree has not yet been built.  The
// stack is implemented as linked list.  The nodes are linked
// together by having the "greater" handle of a node set to the
// next node in the list.  "less_parent" is the handle of the first
// node in the list.
Node *less_parent = nullptr;

// h is root of current subtree, child is one of its children.
Node *h, *child;

Node *p = head of the sorted linked list of nodes;

LOOP // loop unconditionally

    LOOP WHILE (num_sub > 2)
        // Subtract one for root of subtree.
        num_sub = num_sub - 1;

        rem[depth] = !!(num_sub & 1); // true if num_sub is an odd number
        branch[depth] = false;
        depth = depth + 1;
        num_sub = num_sub / 2;
    END LOOP

    IF (num_sub == 2)
        // Build a subtree with two nodes, slanting to greater.
        // I arbitrarily chose to always have the extra node in the
        // greater subtree when there is an odd number of nodes to
        // split between the two subtrees.

        h = p;
        p = the node after p in the linked list;
        child = p;
        p = the node after p in the linked list;
        make h and p into a two-element AVL tree;
    ELSE  // num_sub == 1

        // Build a subtree with one node.

        h = p;
        p = the next node in the linked list;
        make h into a leaf node;
    END IF

    LOOP WHILE (depth > 0)
        depth = depth - 1;
        IF (not branch[depth])
            // We've completed a less subtree, exit while loop.
            EXIT LOOP;
        END IF

        // We've completed a greater subtree, so attach it to
        // its parent (that is less than it).  We pop the parent
        // off the stack of less parents.
        child = h;
        h = less_parent;
        less_parent = h->greater_child;
        h->greater_child = child;
        num_sub = 2 * (num_sub - rem[depth]) + rem[depth] + 1;
        IF (num_sub & (num_sub - 1))
          // num_sub is not a power of 2
          h->balance_factor = 0;
        ELSE
          // num_sub is a power of 2
          h->balance_factor = 1;
        END IF
    END LOOP

    IF (num_sub == number of node in original linked list)
        // We've completed the full tree, exit outer unconditional loop
        EXIT LOOP;
    END IF

    // The subtree we've completed is the less subtree of the
    // next node in the sequence.

    child = h;
    h = p;
    p = the next node in the linked list;
    h->less_child = child;

    // Put h onto the stack of less parents.
    h->greater_child = less_parent;
    less_parent = h;

    // Proceed to creating greater than subtree of h.
    branch[depth] = true;
    num_sub = num_sub + rem[depth];
    depth = depth + 1;

END LOOP

// h now points to the root of the completed AVL tree.

For an encoding of this in C++, see the build member function (currently at line 361) in https://github.com/wkaras/C-plus-plus-intrusive-container-templates/blob/master/avl_tree.h .  It's actually more general, a template using any forward iterator rather than specifically a linked list.


Why is my model unwrapping wrong?

Question: I made a model of a Sega Mega Drive case, and I want to unwrap the faces to texture it with the label. But the wrap gets distorted. Of course, I can tweak it and make it right but, I still wonder why its not getting unwrapped in a straight line? If I mark seams, it gets divided into 3 parts. I want it to be in 1 part.

the blender file
Answer: Marking seams is the right way to do it. It got split into three pieces because you marked TOO MANY seams. Think of the model as a paper box that you have to unfold flat. ONLY mark the seams where you'd have to make cuts in order to lay the box flat. Don't mark seams all the way around.
Even still, it might not unwrap straight. You may still have to tweak it a little, but that's why nobody likes UVs ;-) Your most useful tool in this case will be scale.
Select a horizontal line of UVs, then type S > Y > 0. That will scale them flat along the Y-axis, making them perfectly horizontal. Then you you can move them up or down. It's tedious, but that's the way it's done.
Comment: Ok thanks for that answer. I get a little confused by the seems but i will try to see if i can find out how to do it without having it split.
Comment: i tried it with seems and had it in one island but it still was not straight, but your tip about "scale" was perfect help. Thanks.

Why is my model unwrapping wrong?


What is the right balance between unit vs. functional testing in a typical web application?

Question: Unit tests are cheaper to write and maintain, but they don't cover all scenarios. What is the right balance between them?
Answer: it is important to distinguish between the intent and scope of these two types of tests:

a unit test typically test a specific feature at the module/class level, e.g. create-X, update-Y, foo-the-bar, compact-the-whizbang, etc. One class may have multiple unit tests
a functional test, also called an 'acceptance test' typically tests a use-case scenario from the outermost interface through to the end of processing, e.g. from the user-interface to the database and back again, from the input process to the notification utility, etc.

these two types of tests are not interchangable, and are in general disjoint. So the notion of striking a 'balance' between them makes no sense. You either need them or you don't.
if you are referring to the ease of coding each type of test in your testing framework, that is a different question - but the use of the framework (say, NUnit vs. a user-bot) does not change the type/nature of the test.
the best "balance", in general, would be to unit-test for confidence and completeness, and functional-test for client acceptance
Answer: I agree with Steven Lowe that there is no trade-off between unit testing and functional testing, as they are used for very different purposes.
Unit tests are about method and type verification, and also regression testing. Functional tests are about functional, scenario, and feasibility testing. In my opinion, there is almost no overlap,
If it helps, here are my testing categories.
Developers start from the inside and work outwards, focusing on code:

Assertions - verify data flow and structures
Debugger - verify code flow and data
Unit testing - verify each function
Integration testing - verify sub-systems
System testing - verify functionality
Regression tests - verify defects stay fixed
Security tests - verify system can't be penetrated easily.

Testers start from the outside and work inwards, focusing on features:

Acceptance tests - verify end-user requirements
Scenario tests - verify real-world situations
Global tests - verify feasible inputs
Regression tests - verify defects stay fixed
Usability tests - verify that system is easy to use
Security tests - verify system can't be penetrated easily
Code coverage - testing untouched code
Compatibility - with previous releases
Looking for quirks and rough edges.

End-users work from the outside, and usually have little focus:

Acceptance tests - verify end-user requirements
Scenario tests - verify real-world situations
Usability tests - verify that system is easy to use
Looking for quirks and rough edges.
Answer: I like Brian Marick's quadrant on automated tests where the distinctions are business vs. technology facing and support programming vs. critique product.
With that framework the question of balance becomes, what do I need right now?
Answer: On the app I am working on at the moment, there are probably 10:1 unit to functional tests. The unit test work simply things like retrieving entities from DB, error handling tests for db/network connectivity etc. These things run quick - minutes or less and are run by devs daily.
functional tests while fewer tend to be kitchen sink approach - can user complete order etc. tend to cover the business domain end of things are run by business analsyts and operations - sadly for us, often by hand. These things take weeks to run and usually to finalize a release cycle.
Answer: My current project is at about 60% unit test coverage and all user stories have happy-day coverage of user stories in selenium tests, some have additional coverage.
We're continually discussing this: Is there really any point of pushing unit-test coverage of increasingly absurd scenarios for much higher coverage ?
The argument is that expanding selenium tests increases test coverage on things that have business value. Does the customer really care about unit test corner cases that may fail?
When you get good at selenium testing, the cost of writing new tests with business value decreases. For us they're just as simple as unit tests.
The run-time cost is another issue. We have a small cluster of boxes running these tests all of the time.
So we tends to favour web-tests more, probably because we've gotten good at writing them and they provide undeniable business value.
Answer: Originally I leaned heavily towards preferring unit tests over functional/acceptance tests due to the initial cost factor of acceptance tests. However, over time I have changed my philosophy and am now a strong proponent of choosing acceptance tests wherever possible and only using unit tests when acceptance tests can't meet my needs.
The basic rational behind choosing acceptance over unit tests is the same as the basic rational for SOLID code. Your implementation should be able to change drastically with refactoring etc, but all business cases - acceptance tests- should be able to remain un-changed and prove acceptable system behavior (tests pass). With unit tests there's often a natural strong coupling of test to implementation code. Even though it's test code, it's still code and strong coupling as-we-know should be avoided. By choosing acceptance tests you're often led down the spiral of success to create well-planned, consumable de-coupled api's letting your implementation change behind the scenes without forcing your tests to change. Also, your developer implementation thoughts are in-line with the business system-behavior thoughts. In the end I find that all of this is better for business and for coder satisfaction.
From a theory standpoint I often ask my-self if a piece of code can't be tested via an acceptance test why that piece of code should exist? IE - if it's not part of a valid business scenario, then does that code add value or is it currently and will it remain solely cost?
Additionally, if you comment/document your acceptance tests well, those comments/documents generally are the most current and accurate language of the system - which usually will let you avoid other less valuable documentation approaches. Unit tests don't lend themselves to that form of "business-term" communication.
Lastly, I haven't formed this view point from just my personal development, it's proven successful with a couple different project teams in my "very corporate" work environment.
JB
http://jb-brown.blogspot.com
Answer: Tests should run quickly and help localise problems.
Unit tests allow you to do this by only testing the module in question.
However functional/integration/acceptance tests can be made to run sufficiently quickly in most web scenarios.
Answer: I once read that a unit test is an "Executable requirement", which makes perfect sense to me. If your test is not focused on proving a business requirement then it really is of no use. If you have detailed requirements (and that is the acid test) then you will write a number of unit tests to exercise each possible scenario which will in turn ensure the integrity of your data structure algorithms and logic. If you are testing something that is not a requirement but you know must be true for the test to pass then it is more than likely that you are missing requirements.


Could Facebook have been implemented in Adobe Flex?

Question: I am considering creating a website with the complexity of Facebook that should be able to scale into the millions of users. My question is: Is there any reason not to use Adobe Flex for such large project apart from the obvious point of requiring everyone to have Flash installed and not having to rely on Adobe? In my view Adobe Flex would reduce the server load for Facebook, because more of the work could me done on the client side. Do you agree?
Comment: I'm really glad it wasn't implemented in Flex, it would suck not being able to use facebook on my open source OS.
Answer: Of course Facebook could have been implemented in Flash. But then the question is would it have succeeded? There are reasons big web companies like Google, Facebook and Yahoo only use Flash as sparingly as possible.
The thing I would fear most is alienating users. The Flash plugin isn't the best piece of software out there. It is slow and likely to crash once in a while. If your app gets bigger you might get some loading times that might not be acceptable to your users. Also in my opinion full Flash sites just don't feel right because they behave differently from HTML websites. All great websites like Google, Flickr, Stackoverflow or Facebook feel very light and slick which is very elegant makes up for great usability.
And then HTML and JavaScript are a lot more flexible. Do you want your website to be available on smartphonse? The iPhone has no Flash and even with phones that do you have the problem that users will very likely hate a full Flash site since those phones don't necessarily scale Flash as nicely as they scale HTML and Flash draws battery like crazy. If someone comes up with another revolution like smartphones you can be sure it supports HTML and JavaScript but you can't be so sure about Flash.
Then the question is how would you gain any efficiency? Of course you can write your UI with Flex and just call very lightweight webservices like you would use them for AJAX and you can even cache some of the content of the site locally so that you don't transmit more data as necessary for user interaction (the UI is transmitted only once). But you can also do that with JavaScript. You can write your UI in HTML and JavaScript, load it once and then just pull the naked JSON data from the servers and render it using JavaScript. You can also fetch lots of this data in advance to get the number of requests down. But still such an approach has its cons. Did you ever notice that when you type an answer on stackoverflow and someone else submits an answer you get notified while typing your answer. Such real time features are very cool and you might want this at some point in time which means more server interaction.
But whatever you do your servers still have to scale if your site grows. Even if you minimize the number of GET requests that hit your servers they will still grow a lot when your site gets popular and you will need a lot of servers to handle you will just improve your users/servers ratio.
The most interesting point though is that Flex is much easier to program than AJAX (think about browser incompatibilities for instance) and still AJAX was not only invented but the whole world messes with all those problems that come with it instead of using Flex. I think this tells a lot about of the value of the result you get when creating a full website in Flash.
Answer: Go to facebook and do view source...do you see all that JavaScript? That all runs client side
Comment: Not necessarily if you use a JavaScript library like ExtJS you can bring all the components down on first load and then only show the ones you need when you click a link on the client. Also when you have jQuery hosted on Google it will already be cached for the user if he visits another sire first that also uses the Google hosted version
Comment: @David - Keep in mind that Flash/Flex isn't multithreaded either.
Comment: But things like multithreading are as far as I know only supported using GoogleGears. This means that utiizing the client will be lots more complicated.
Comment: @David, I believe your over-utilizing client side code then.. You shouldn't need multi-threading code to be run in a browser for all practical purposes. (you do know your not suppose to create SQL queries on the client side right?)
Comment: your client would call a service on the server which could be parallelized there..for all you know the client is still running a PIII 600 MHZ box..
Comment: Consider www.grooveshark.com. If that had been built using Javascript, wouldn't there be a lot more load on the servers because a connection needs to be established every time a link is clicked?
Comment: That is very interesting, thanks for the point. I will research the maturity of ExtJS.
Comment: The number of HTTP requests for a Flex application will probably be about the same as a site that makes very heavy use of AJAX. The only possible advantage for Flex is that if you make a number of RemoteObject requests within a small enough interval, the Flash Player will combine those requests into a single HTTP request.  That can have drawbacks however.
Answer: Johannes is right to point out the difference for server vs. client. The server side stuff is what needs to scale.
As an example, the Microsoft Silverlight team has assembled a facebook client app in silverlight (using the Facebook public API). My point is, using todays technologies, it is entirely possible to write a web application targeting many different kinds of client technologies: classic web browsers (HTML/javascript), 'rich internet applications' (flex, silverlight), ...
See also the myriad of Twitter clients out there.
Comment: I like your point of using many clients. It does add complexity, though.
Answer: The company I work for has a large app in Flash that is used by Governments. It is very hard to maintain and does fail sometimes. The problem is all of the .fla and .as files that have to be altered just to make a small change. Yes, the app could have been built better but even so, it is still harder to maintain than an HTML/JavaScript front end.
While I love writing Flash/Flex apps, I believe they should complement a site and not be the site.
Using a good JavaScript framework like jQuery takes the Browser compatibility question out of the picture (for the most part) and allows a lot of functionality.
Comment: Why do more files have to be updated when a site is implemented in Flex? Is your point that creating a good architecture in Flex is more difficult than in HTML/Javascript?
Comment: This is in Flash but the same could occur in Flex. There are SWF Files that contain the UI and the UI logic then AS files that contain the business logic. These AS files must communicate with a server side database layer (PHP in this case). That means if you have a problem it is either in the PHP, AS, or SWF. While a PHP app usually just has a PHP class for the Data and a UI page to communicate with that class.
Answer: Flex is the GUI for the client. You still need server-side storage and that's what has to scale. The user interface could be in Flex, while most of your users won't like such interfaces.
Comment: I don't get the downvotes here (maybe the argumentative statement about "users won't like such interfaces"?) The fundamental issue of client vs. server is a very valid point.
Answer: You will have to do a custom version of your site for the iPad/iPhone.
There are other ways of moving load to the client side. Javascript will give you porting headaches, but less than moving away from the entire architecture like Flex.
OTOH when you get a million users you'll have the resources to reimplement your site.
Comment: Ipad/iphone support is an excellent point. Reimplementing a site is never favourable, even with nearly unlimited resources.
Comment: Sorry, I was being a bit facetious :-) The correct answer is, when you have "million of users", you'll be able to pay someone else to reimplement it for you, or sell it to Google :-)
Comment: By the way I think facetious is an excellent name for a Facebook clone :-)
Answer: I don't think you would see a performance advantage with a site like Facebook, because the content is highly dynamic, comes from many different places, and is created by many independent entities.  Flash (and therefore Flex) is better for monolithic apps from a single source that don't need to change very often.
The default in Flash is to build everything into a single .swf file that holds everything.  It is possible to break out of this default behavior, of course.  You can make web service calls, pull in external components via the SWC mechanism, load static content via HTTP, etc.  Nevertheless, it's not the default pattern, which affects how Flash development libraries and tools work.  Besides, the more of this you do, the less of the "run everything we possibly can on the client side" benefit you get.  It gets soaked up in HTTP connection overhead.
The default on the plain old standards-based web is to store all assets separately and assemble them dynamically at the client.  This is one reason the web is slow -- again, all that HTTP connection overhead -- but also why it is flexible and dynamic.  It mates well with a site like Facebook which requires constant evolution by a lot of independent developers.
I say this having developed a Flex app, which I am happy with.  Only one person -- me -- has to maintain it, and it's naturally a monolithic app.  It plays right into Flex's strengths.


Leaving toxic workplace

Question: Recently the environment at my job has become rather toxic, with two members of upper management having an open feud with employees picking sides and engaging in shouting matches. I want absolutely no part of this, and, as such, I have begun looking for employment elsewhere. However, in the two interviews I've had this week, both interviewers asked (understandably) why I was leaving my current position after just 1 year. I've always been told that interviewers want to hear not why you want to leave your current position, but why you want to take the new position. Is this an exception? When explicitly asked why I'm leaving my current position, is it allowable to mention a toxic work environment, or should I stick with an easy excuse, such as "I am looking to increase my responsibilities"?
Comment: possible duplicate of [How should I explain that I'm looking for a job because my employer may be shutting down?](http://workplace.stackexchange.com/questions/2263/how-should-i-explain-that-im-looking-for-a-job-because-my-employer-may-be-shutt). While the reasons for leaving are different in your question and the one I link, the situation you face is the same. And, welcome to the Workplace.SE.
Answer: You should stay focused on telling the story of what you're running after, not what you're running from.
Badmouthing the current employer might not work in your favor - some might see it as a sign of what you might do to them in the future.
If the HR person probes deeper about your reason for leaving, you can keep it high level like "the culture of that organization was not a good fit". If asked even further, politely decline by saying you prefer not to divulge more details out of respect for the company's reputation. In my opinion, this would be appreciated as it shows maturity and your ability to remain discreet, and not get negative.
Comment: "Better" would make it sound comparative. You should convey clearly the type of environment/culture you'd like to work in, and stick to that. Preferably research the prospective company's culture from website/glassdoor and convey those aspects they are proud of.
Comment: You answered it here... You are running after a combination of the right job profile AND culture.
Comment: So simply say: "I'm looking for a better work culture"?
Comment: @wolfPack88, dg is right. Describe the kind of culture you're looking for and which is that of the hiring firm. Don't get into detail about the ways in which the old employer didn't have that culture. Describe what you're looking for in terms of positive attributes (e.g. collegial, respectful, teamwork etc) rather than in terms of an absence of the bad things that can be found at your current workplace.
Comment: The problem is, what I'm running after is exactly my current job with a better work environment. The work itself is exactly what I want to do, so "what [I'm] running after" is what I already have, which doesn't really answer the interviewer's question.
Comment: Exactly.  Pretty much any negative "I don't like work places where coworkers seem hostile" can be inversed "I like work places where everyone is generally positive and polite".  Approach it like this.
Answer: This recently happened to me. Do not mention the problems of your current employer during your interviews: they will see you as desperate and will use this as leverage to pay you less.
Focus on the positive at your past company, and explain why you would really like to work for the new company.
Answer: To answer your first question, no I don't think it's unusual at all for an employer to ask why you're leaving your current position (or why you left your previous position if currently unemployed) in an interview. My current employer asks this of everyone we interview if they aren't straight out of school.
Regarding the main question, I would actually somewhat disagree with the current answers. While I agree that you shouldn't delve into too many details and come off as badmouthing your current employer, I don't see anything wrong with mentioning that your reason is that the work environment has become bad due to two feuding members of upper management. That answers the question and lets the prospective employer know that you have a legitimate reason for leaving (i.e. you weren't fired for bad behavior or poor performance, etc.)
A candidate we interviewed recently had a situation very similar to what you described. He was working for small company where the CEO and the engineering manager were husband and wife... and then went through a messy divorce. When asked this question, the candidate told us exactly that and that the CEO was now intentionally causing problems with engineering just to spite the engineering manager. That's a good reason for an engineer to want to leave a company, IMO. The candidate didn't go into any details of exactly what all had been going on or badmouth either the CEO or the engineering manager; he just gave us the above information, which sufficiently answers the question. None of us found his answer to be at all unprofessional and we certainly didn't hold it against him in any way. Our CEO just assured him that he isn't married to our engineering manager, so he wouldn't have to worry about that situation arising at our company. - lol

Leaving toxic workplace


Strict exogeneity and lagged variables

Question: I am confused why strict exogeneity must be violated when we have lagged time series variables. My understanding of strict exogeneity is that a variable must be uncorrelated with error terms in all periods. But isn't exogeneity always a necessary assumption for estimation? If $x_t$ and $u_t$ are uncorrelated, and $x_{t-1}$ and $u_{t-1}$ are uncorrelated, how would it violate strict exogeneity if we have a specification with $x_t$ and $x_{t-1}$?
Answer: In the most cases it is assumed that $E[\epsilon_t]=0$. Then, strict exogeneity implies that the regressors are orthogonal to the error term for all observations $s$, i. e. $E[x_s \epsilon_t]=0$. For some time series models this is violated. Consider the AR(1) model $ \ y_t=\beta y_{t-1}+ \epsilon_t \ $ with $ \ \epsilon_t \sim N(0, \sigma^2) \ $  $ \ \forall \ $ $t$. Since you regress $y_t$ on $y_{t-1}$ the error term $\epsilon_t$ is orthogonal to $y_{t-1}$, i. e.
$E[y_{t-1} \epsilon_t]=0$.
However, strict exogeneity requires $y_t$ to be orthogonal to $all$ $\epsilon_t$. That does not hold for the considered model - as will be shown:
$E[y_t \epsilon_t]=E[(\beta y_{t-1}+ \epsilon_t)\epsilon_t] \qquad (by \ \ \ y_t=\beta y_{t-1}+ \epsilon_t)$
                    $ \quad \qquad =\beta E[y_{t-1} \epsilon_t]+E[\epsilon_t^2]$
                    $ \quad  \qquad =E[\epsilon_t^2] \qquad \qquad \qquad \quad (by \ \ \ E[y_{t-1} \epsilon_t]=0)$.
$ \quad  \qquad =\sigma^2 \qquad \qquad \qquad \quad \quad (by \quad  \epsilon_t \sim N(0, \sigma^2))$.
Therefore, $y_t$ is not orthogonal to all error terms but the regressor for $y_{t+1}$. Thus, strict exogeneity is violated.
This implies, there is only strict exogeneity if $\epsilon_t = 0$ for all $t$.
Comment: I've made some changes, the general thrust of the answer is ok. Note in general exogeneity is defined via conditional expectactions.
Comment: @random_guy, the weakness of the argument is in $E[y_{t-1}\varepsilon_t]=0$. You didn't explain where is this coming from. When you regress on the lag, you get automatically $E[y_{t-1}e_t]=0$, where $e_t$ is the residual from the regression, not the error.
Comment: See, this is what you get when you edit your own answer in order to improve it almost 10 months after posting it: a down vote! However, in this context, strict exogeneity implies $E[y_{t-1} \epsilon_t] = 0$, orthogonality and no correlation! And the argument comes after the formulas where I say that even if $y_{t-1}$ is orthogonal to $\epsilon$, this does not hold for ${y_t}$ even though it is the regressor for $y_{t+1}$. Please read page 6 (explanation of strict exogeneity) to page 9 (str. exog. for AR(1) process) of this paper (and up vote ;)):
http://press.princeton.edu/chapters/s6946.pdf
Comment: Hello, thanks for your edits. I am aware of this but thought I can show the violation of strict exogeneity via the implication of zero correlation if E[e]=0.
Comment: Yes it is perfectly ok to do that, hence the upvote.
Answer:
Strict exogeneity and lagged variables

The problem your refers on is about strict exogeneity and lagged dependent variables. The two things together are contradictory.
Indeed as shown in random guy answer if we have a model like
$y_t = \beta_1 y_{t-1} + \epsilon_t$
(we assume $[\epsilon_t]=0$)
We have that $E[y_t \epsilon_t]=\sigma^2$
However if other lagged variables as $x_{t-j}$ are included, and dependent are not, the contradiction disappear.
Moreover the main point, in my view, is that exogeneity is a causal concept (in any detailed form) and it must be write on a structural equation not a regression one. Indeed the equation above must be intended as structural. (Read here for more about: Under which assumptions a regression can be interpreted causally?)
The reply of random_guy is mathematically correct but terminology used is ambiguous and tend to mix concepts. Mainly regression equation and/or errors and exogeneity assumpion. Speaking about AR (autoregressive) model the conflation become even more evident. I read the the ref suggested in the comment (http://assets.press.princeton.edu/chapters/s6946.pdf), and It suffer from the same problem. This problem is quite common (read here: How would econometricians answer the objections and recommendations raised by Chen and Pearl (2013)?)

Strict exogeneity and lagged variables


Freezing all mobs, testing for a player in a boat, then unfreezing all mobs

Question: Is there a way that I can freeze all mobs using a command, then test for a player getting on a boat, then unfreeze all the entities? If you are curious as to why I would be wondering this, here is a link to one of my other questions: Making mobs invincible
Comment: So I understand what it is you want to do, you want your bats to be motionless until someone gets in a boat that's riding said bat?  Rewording your question to better reflect your general problem might yield better answers.
Comment: This is a pretty complicated problem, I would suggest freezing all mobs isn't the way to go. Instead possibly spawning a thrown potion of slowness with infinite time as the mob is spawned. Then clearing the effects once you detect the player is in the boat (Still trying to think of a way to detect that)
Comment: Actually, given how the plane is made, clearing effects would break it. Unfortunately I don't know of any other way to freeze it in place.
Comment: @DBS actually, I found a way to do this, just give the bat a potion of slowness effect set to 255 for a few seconds to give the rider time to get on.
Answer: You could use the /effect command to apply slowness to every entity with a really high level and time as such:
<code>/effect @e 2 1000000 255 true
</code>
Then when you detect your player in the boat (this is where my knowledge ends), you can clear the effect as such:
<code>/effect @e clear
</code>
Comment: Note that using a straight `@e` selector is going to cycle through every entity in existence, including those that cannot accept potion effects. A quick way to target only 'living' mobs is to supply the `team` parameter. For example, leaving it blank (`@e[team=]`) will target living entities not on a team. Alternatively, the mobs that should be affected could be added to a specific team. You should also be using name IDs instead of numerical ("slowness" rather than "2").


Virtual resolution + scrolling?

Question: I created a small, pocket computer from Raspberry Pi 3 and small 4" display with resolution 480x320. It is very hard to do anything on such small screen, so I've been wondering, if there's a way to virtually enlarge screen resolution, such that if mouse pointer approaches one of its edges, screen scrolls. This is purely software feature, so shouldn't depend on the screen itself. Is it possible?
Comment: @David, imagine, that we set virtual resolution to 1920x1080. Screen has physical resolution of 480x320, so displays only left-top rectangle of the bigger screen. Now when I move mouse to right edge of the screen, the view "scrolls", so that I see part more to the right. Applications thinks, that we have FullHD resolution, but at the moment only part of it is displayed on the screen. On Windows press Win+Num Plus - Windows zooms image in and you can scroll by moving mouse. I want to achieve the same, but with bigger resolution, not zoom.
Comment: Hi @Spook, what do you mean by saying "screen scrolls". What would scrolling have to do with screen resolution? Shouldn't it be, for example, that if the mouse approaches an application, or you double tap something, you zoom in?
If you have an example of what you want to achieve (something done in some other project unrelated to the RPi) it might be easier to give you a suggestion.
Comment: I understand now. What screen are you using? Is it HDMI?
Comment: @David, no, GPIO (SPI).
Answer: This feature is called "viewport panning" and it can be enabled using xrandr:
xrandr --output default --mode 800x600 --fb 1280x1024 --panning 1280x1024

You still need a framebuffer large enough to fit the whole virtual screen, so you might need to set framebuffer_width and framebuffer_height in config.txt.
If your screen comes with a custom driver, this will only work if the driver implements RandR extensions.
Answer: There are a couple of questions online regarding how to dynamically change your RPi's screen resolution. Here's an explanation on changing your screen's resolution without rebooting your RPi. This explains how to zoom out to fit the entire display on your screen.
To understand the different HDMI output formats check the official documentation on the video options in the config.txt file. Here you can find additional information about this file.
You will probably want to run a script that changes these configurations without the need to reboot your RPi. Once you test out your script, you can configure your RPi to run it in the background every time you boot it.

Virtual resolution + scrolling?


Custom EditItem Page

Question: Is there a way to create a custom edit item page for SharePoint list items using HTML/CSS/JS? I want to be able to modify EditItem.aspx so that I could add divide the fields into different sections and insert buttons on the page. I've tried to using Mark Rackley's solution for this task but I am unable to pre-populate the fields in my HTML page with existing data.
Answer: Option 1:
Does it have to be entirely in SharePoint?  Why not build the page out using exactly the things that you know, HTML/CSS/JS and make all of your connections to a SharePoint list?
Option 2:
Edit the form in SharePoint designer.

Custom EditItem Page


Regarding wave displacement equation

Question: in some textbook i read that one can describe wave displacement by y(t)=Asin(ωt+ϕ) and y(t)=Acos(ωt+ϕ) . i know both these terms are periodic but how one can use any of these equations in numericals and get the correct answer because both these terms have different trigonometric values ???
Answer: Imagine standing at a fixed point in space with a wave traveling towards you. It's clear that if you measure the amplitude of the wave it will vary periodically with respect to time. Now the point $t=0$ can be chosen arbitrarily and the value you measure at $t=0$ will depend upon $\phi$, the phase. If we take the amplitude to be $0$ at $t=0$ the wave will be described by: $y(t) = A \sin(\omega t); (\phi=0)$. If instead we have maximum amplitude at $t=0$ the wave will be described by: $y(t) = A \cos(\omega t); (\phi=0)$. However this corresponds to $y(t) = A \sin(\omega t+\pi/2); (\phi=\pi/2)$. So you see that both the sine and the cosine solution describe the same physical wave but you just need to shift the phase (you can easily see this by plotting the sine and cosine and notice that they are equal but shifted over $\pi/2$.)
Answer: it depends on the language of the problem. Also it depends on the phase constant you want to deal with.For example if you assume phase constant=0 at mean position then you could easily deal with the sine equation. As the wave is a travelling wave  i prefer you to use the sine equation in solving problems

Regarding wave displacement equation


Why am I not able to use $this is an opencart helper?

Question: I have the following helper function in system/helper/wholesaler.php:
<?php
function is_wholesaler() {
  return $this->customer->getCustomerGroupId() != 1 ? TRUE : FALSE;
}
?>

I loaded the helper in system/startup.php
The problem is that when I try to use the function I get a fatal error "Fatal error: Using $this when not in object context". Is there a way to use $this in a helper?
One alternative option would be to send $this as an argument in is_wholesaler() or add the function in library/customer.php and call it with $this->customer->is_wholesaler() in my opencart template view files.
Answer: $this refers to an object (class) instance, you can't use it in a individual, you can put function is_wholesaler into a class like:
class Helper{
    private $customer;

    public function __construct($customer){
        $this->customer = $customer;
    }

    function is_wholesaler() {
        return $this->customer->getCustomerGroupId() != 1 ? TRUE : FALSE;
    }
}

$customer = new Customer(); //I suppose you have a class named Customer in library/customer.php
$helper = new Helper($customer);
$is_wholesaler = $heler->is_wholesaler();

or, you just modify the function is_wholesaler it self as following:
function is_wholesaler() {
    $customer = new Customer(); //still suppose you have a class named Customer
    return $customer->getCustomerGroupId() != 1 ? TRUE : FALSE;
}

Answer: Try to create an object for the Customer and you can use that object as an reference for that class
$h = new Customer();
function is_wholesaler() {
    return $h->getCustomerGroupId() != 1 ? TRUE : FALSE;
}

Or you can also create reference like
return Customer::getCustomerGroupId() != 1 ? TRUE : FALSE;

Comment: Thanks but it's not working... Unknown: Non-static method Customer::getCustomerGroupId() should not be called statically in


Trans dip stick reads same hot and cold is that normal

Question: I check the trany fluid yesterday when van was in nuetral and warm the today checked it before starting it up and it at the same level is that normal
Comment: I never knew an AT that the fluid level was checked without starting the engine; This is required to fill the torque converter on any AT that I am familiar with.
Comment: Are you sure the trans fluid was hot?
Comment: Is checking in neutral the correct method?
Answer: With a automatic transmission equipped with a dip stick most manufacturers recommended
procedure is first.
Drive vehicle few miles bring tranmission fluid normal operating temperature.
Stop set hand brake put tranmission into park.
Remove dipstick wipe off reinsert back into travsmission.
With engine idling step on brake pedal and cycle through gears from 1st back to park
pausing in each gear for 5 seconds.
With engine still on remove dip stick wipe off reinsert now remove and make sure fluid
is within the hash marks on dip stick.
Answer: Checking in park with engine idling is the proper procedure.  Go out to the car when it's been sitting overnight and just turn it on and check.  A few miles of city driving should warm it up - stopping and taking off creates more heat than cruising.  Wait until your temp gauge is at normal operating temp then check again.  Transmission fluid definitely expands when it's hot so what you are describing is strange.


Deploying Application Page Project 2 Different Places

Question: I have 1 application page project and it is deployed.  Now I want to make a change to it and deploy it somewhere else (same server and site) without retracting the currently deployed one.  From one application page project I want two separate deployments.  How do I do this?  Having looked in the project properties I do not see any way to change that.  I know that it has to be deployed to layouts, as with all application pages, and I tried deploying after changing its name but it still retracted the existing application page.
Answer: Application Pages are deployed to the server hard drive in one place for the whole farm.  This means you cannot deploy the same page in the same location without affecting the previous deployment.
You would need to create a separate solution that deploys it in a different location (i.e. a different folder within /_layouts).
Comment: Rats!  Ah well, I'll just make another solution for the minor changes then..Actually, could I just make it another project in the same solution?  Or does it deploy according to solution?
Comment: In Visual Studio you can have multiple SharePoint projects in your VS solution.  (Solution in VS is different than Solution in SharePoint).