Rectangle 27 5

The statement is not exactly true

Also, there the problem of perceived performance : since V8 is natively non blocking, Web dev leads to more performant projects because you save the IO wait. And V8 is mainly used for dev Web where IO is key, so they compare it to similar projects. But you can use Python in many, many other areas than web dev. And you can even use C extensions for a lot of tasks, such as scientific computations or encryption, and crunch data with blazing perfs.

But on the web, most popular Python and Ruby projects are blocking. Python, especially, has the legacy of the synchronous WSGI standard, and frameworks like the famous Django are based on it.

You can write asynchronous Python (like with Twisted, Tornado, gevent or asyncio) or Ruby. But it's not done often. The best tools are still blocking.

However, they are some reasons for why the default implementations in Ruby and Python are not as speedy as V8.

Like Jrg W Mittag pointed out, the guys working on V8 are VM geniuses. Python is dev by a bunch a passionate people, very good in a lot of domains, but are not as specialized in VM tuning.

The Python Software foundation has very little money : less than 40k in a year to invest in Python. This is kinda crazy when you think big players such as Google, Facebook or Apple are all using Python, but it's the ugly truth : most work is done for free. The language that powers Youtube and existed before Java has been handcrafted by volunteers.

They are smart and dedicated volunteers, but when they identify they need more juice in a field, they can't ask for 300k to hire a top notch specialist for this area of expertise. They have to look around for somebody who would do it for free.

While this works, it means you have to be very a careful about your priorities. Hence, now we need to look at :

Even with the latest modern features, writing Javascript is terrible. You have scoping issues, very few collections, terrible string and array manipulation, almost no stdlist apart from date, maths and regexes, and no syntactic sugar even for very common operations.

But in V8, you've got speed.

This is because, speed was the main objective for Google, since it's a bottleneck for page rendering in Chrome.

In Python, usability is the main objective. Because it's almost never the bottleneck on the project. The scarce resource here is developer time. It's optimized for the developer.

What blocks Ruby, Python to get Javascript V8 speed? - Stack Overflow

javascript python ruby performance language-design
Rectangle 27 8

And what exactly you want is here

You can put One thing Fixed

Demo : With Basic styles Link is Broken Now Please Use this Instead

Great demos -- but why don't you recommend the "Both things fixed" solution? Cross-browser support? Style?

The Demo: "With Basic styles" link is broken.

jquery - Making a scrollable table with fixed header and fixed sidebar...

jquery html css table
Rectangle 27 5

This is not exactly what I want

Simply displaying the traffic layer can be done using the JavaScript API like the following

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 13,
    center: {lat: 34.04924594193164, lng: -118.24104309082031}
  });

  var trafficLayer = new google.maps.TrafficLayer();
  trafficLayer.setMap(map);
}

This will not only give you access to the traffic layer, but also to the transit and bicycling layers as well.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Traffic layer</title>
    <style>
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 13,
          center: {lat: 34.04924594193164, lng: -118.24104309082031}
        });

        var trafficLayer = new google.maps.TrafficLayer();
        trafficLayer.setMap(map);
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
    </script>
  </body>
</html>

PS: before using it make sure you use your API KEY in

<script async defer
        src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
        </script>

Experience usualy tells us that when you are suggesting a route to a user, if the said route has a red traffic line the user will automatically search for something else - forcing him to do another query would be cumbersome.

Thus Traffic layers are a good solution to avoid the previous behavior.

This however also means that you can't simply pick a part of the layer (say, the one matching your polyline) and paste it there - that is not the purpose of layers.

If this solution is not good for you, there is another way...

The Directions Service which caluculates the directions between two points.

provideRouteAlternatives
departureTime
drivingOptions

departureTime (required for the drivingOptions object literal to be valid) specifies the desired time of departure as a Date object. (...) For Google Maps APIs Premium Plan customers, if you include the departureTime in the request, the API returns the best route given the expected traffic conditions at the time, and includes the predicted time in traffic (duration_in_traffic) in the response. (...)

So if you make a request for alternative routes and have a departureTime you will have a duration_in_traffic in the reponse for each route, and with it you can draw the polygon with the colour you want depending on how good or bad the path is.

Using only Google Maps APIs and Services, this is as far as you can go. If these options still don't suit you then you will need to mix your map with traffic data from third-parties.

Better if i get the traffic only for the selected source and destination's path

This is not exactly what question is asked for. How to display traffic color on a selected direction from a source to destination. Like how google maps display when you search for a route from one place to another.

@Jyotirmay I beg to differ. This is the closest thing he can get to what he wants, given the current state of the Maps API. I believe downvoting my answer is harsh at best, given the effort and time put into it and the range of possibilities available.

javascript - How to show Traffic layer on top of Directions polyline i...

javascript google-maps google-maps-api-3 google-polyline
Rectangle 27 7

"Vertical centering is only possible if the element is positioned absolutely and has a known height." This statement is not exactly correct.

You can try and use display:inline-block; and its possibility to be aligned vertically within its parent's box. This technique allows you to align element without knowing its height and width, although it requires you to know parent's height, at the least.

<div id="container">
    <div id="aligned-middle" class="inline-block">Middleman</div>
    <div class="strut inline-block">&nbsp;</div>
</div>
#container {
    /* essential for alignment */
    height:300px;
    line-height:300px;
    text-align:center;
    /* decoration */
    background:#eee;
}
    #aligned-middle {
        /* essential for alignment */
        vertical-align:middle;
        /* decoration */
        background:#ccc;
        /* perhaps, reapply inherited values, so your content is styled properly */
        line-height:1.5;
        text-align:left;
    }
    /* this block makes all the "magic", according to http://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align specification: "The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its 'overflow' property has a computed value other than 'visible', in which case the baseline is the bottom margin edge." */
    #container .strut {
        /* parent's height */
        height:300px;
    }
.inline-block {
    display:inline-block;
    *display:inline;/* for IE < 8 */
    *zoom:1;/* for IE < 8 */
}

Then #aligned-middle will be centered within #container. This is the simplest use of this technique, but it's a nice one to be familiar with.

Rules marked with "/* for IE < 8 */" should be placed in a separate stylsheet, via use of conditional comments.

edit: (this particular snippet tested in ie6 and ff3.6, but I use this a lot, it's pretty cross-browser. if you would need support for ff < 3, you would also need to add display:-moz-inline-stack; under display:inline-block; within .inline-block rule.)

javascript - Cross browser div center alignment using CSS - Stack Over...

javascript jquery html css alignment
Rectangle 27 4

It is not exactly true that "assert fails only in debug mode."

In Object Oriented Software Construction, 2nd Edition by Bertrand Meyer, the author leaves a door open for checking preconditions in release mode. In that case, what happens when an assertion fails is that... an assertion violation exception is raised! In this case, there is no recovery from the situation: something useful could be done though, and it is to automatically generate an error report and, in some cases, to restart the application.

The motivation behind this is that preconditions are typically cheaper to test than invariants and postconditions, and that in some cases correctness and "safety" in the release build are more important than speed. i.e. For many applications speed is not an issue, but robustness (the ability of the program to behave in a safe way when its behaviour is not correct, i.e. when a contract is broken) is.

Should you always leave precondition checks enabled? It depends. It's up to you. There is no universal answer. If you're making software for a bank, it might be better to interrupt execution with an alarming message than to transfer $1,000,000 instead of $1,000. But what if you're programming a game? Maybe you need all the speed you can get, and if someone gets 1000 points instead of 10 because of a bug that the preconditions didn't catch (because they're not enabled), tough luck.

In both cases you should ideally have catched that bug during testing, and you should do a significant part of your testing with assertions enabled. What is being discussed here is what is the best policy for those rare cases in which preconditions fail in production code in a scenario which was not detected earlier due to incomplete testing.

To summarize, you can have assertions and still get the exceptions automatically, if you leave them enabled - at least in Eiffel. I think to do the same in C++ you need to type it yourself.

Your point is definitely valid. The SO didn't specify a particular language -- in the case of C# the standard assert is System.Diagnostics.Debug.Assert, which does only fail in a Debug build, and will be removed at compile time in a Release build.

Design by contract using assertions or exceptions? - Stack Overflow

exception design assert design-by-contract
Rectangle 27 225

This is exactly the same as

while (x--)
{
   printf("%d ", x);
}
for(--x++;--x;++x--)
unsigned

@MateenUlhaq, that is wrong according to the standard the expression --x++ has undefined behaviour according to 1.9.15

What is the "-->" operator in C++? - Stack Overflow

c++ operators code-formatting standards-compliance
Rectangle 27 219

This is exactly the same as

while (x--)
{
   printf("%d ", x);
}
for(--x++;--x;++x--)
unsigned

@MateenUlhaq, that is wrong according to the standard the expression --x++ has undefined behaviour according to 1.9.15

What is the "-->" operator in C++? - Stack Overflow

c++ operators code-formatting standards-compliance
Rectangle 27 219

This is exactly the same as

while (x--)
{
   printf("%d ", x);
}
for(--x++;--x;++x--)
unsigned

@MateenUlhaq, that is wrong according to the standard the expression --x++ has undefined behaviour according to 1.9.15

What is the "-->" operator in C++? - Stack Overflow

c++ operators code-formatting standards-compliance
Rectangle 27 11

This is not exactly true. The example code really means that the method ts in B hides the method ts in A. So its not exactly overriding. Over on Javaranch there is a nice explanation.

It is true just not precise. static methods cannot be overridden but can be hidden if you are calling them on a instance reference rather than the class name.

java - Behaviour of final static method - Stack Overflow

java methods static final
Rectangle 27 11

This is not exactly true. The example code really means that the method ts in B hides the method ts in A. So its not exactly overriding. Over on Javaranch there is a nice explanation.

It is true just not precise. static methods cannot be overridden but can be hidden if you are calling them on a instance reference rather than the class name.

java - Behaviour of final static method - Stack Overflow

java methods static final
Rectangle 27 13

The equality operator (==) checks whether two operands are the same and returns true if they are the same and false if they are different.

  • They have to have the same type.
  • If number values have the same value they are identical, unless one or both are NaN.
  • If string values have the same value they are identical, unless the strings differ in length or content.
  • If both values refer to the same object, array or function they are identical.

What is exactly the meaning of "===" in javascript? - Stack Overflow

javascript
Rectangle 27 13

The equality operator (==) checks whether two operands are the same and returns true if they are the same and false if they are different.

  • They have to have the same type.
  • If number values have the same value they are identical, unless one or both are NaN.
  • If string values have the same value they are identical, unless the strings differ in length or content.
  • If both values refer to the same object, array or function they are identical.

What is exactly the meaning of "===" in javascript? - Stack Overflow

javascript
Rectangle 27 53

'===' means equality without type coersion. In other words, if using the triple equals, the values must be equal in type as well.

0==false   // true
0===false  // false, because they are of a different type
1=="1"     // true, auto type coersion
1==="1"    // false, because they are of a different type
type coercion

What is exactly the meaning of "===" in javascript? - Stack Overflow

javascript
Rectangle 27 53

'===' means equality without type coersion. In other words, if using the triple equals, the values must be equal in type as well.

0==false   // true
0===false  // false, because they are of a different type
1=="1"     // true, auto type coersion
1==="1"    // false, because they are of a different type
type coercion

What is exactly the meaning of "===" in javascript? - Stack Overflow

javascript
Rectangle 27 6

All good answers - behavior should be exactly the same.

HOWEVER - Just suppose it DID make a difference. Suppose one of them took 3 more instructions per iteration.

ONLY if what you do inside the loop is almost nothing, which is almost never the case.

My point is, there is micro-optimization and macro-optimization. Micro-optimization is like "getting a haircut to lose weight".

++i
i++

@Dennis Zickefoose: The difference between ++i and i++ can potentially be significant if i is an instance of a class rather than a built-in and the compiler does not apply the trivial optimisation. The advice is to acquire a habit so that it won't catch you out when it counts.

The thing about ++i vs i++ is that it doesn't cost you anything to make the "optimization". True, in most cases it makes absolutely no difference, but they're equally easy to type, so why not prefer the potentially most efficient by default? And I suppose the same applies here. If one was a tiny bit faster than the other, why not go for the faster one? What would we lose by doing it? Both are fairly easy to read and type out.

@Dennis Zickefoose: You're right. I see that a lot on SO, and Clifford's comment is right. In addition, there's something I don't see a lot on SO, and that is how to do macro-optimization, like a 43x speedup: stackoverflow.com/questions/926266/. So I wonder about our priorities.

@Mike: Yeah, but that's an apples to oranges comparison. Getting a haircut takes actual time, and probably even money. I agree it is such a microoptimization that it doesn't really matter. But it also doesn't cost us anything. if I can choose to go left or right, and the distance is the same, the terrain is the same, everything is the same, except that the left path has some marginal microscopic benefit, why not go left? You're right, it's not an impressive argument. But when the cost is literally zero, I see no reason to prefer the less optimal route.

c++ - Is "for(;;)" faster than "while (TRUE)"? If not, why do people u...

c++ c optimization readability infinite-loop
Rectangle 27 6

All good answers - behavior should be exactly the same.

HOWEVER - Just suppose it DID make a difference. Suppose one of them took 3 more instructions per iteration.

ONLY if what you do inside the loop is almost nothing, which is almost never the case.

My point is, there is micro-optimization and macro-optimization. Micro-optimization is like "getting a haircut to lose weight".

++i
i++

@Dennis Zickefoose: The difference between ++i and i++ can potentially be significant if i is an instance of a class rather than a built-in and the compiler does not apply the trivial optimisation. The advice is to acquire a habit so that it won't catch you out when it counts.

The thing about ++i vs i++ is that it doesn't cost you anything to make the "optimization". True, in most cases it makes absolutely no difference, but they're equally easy to type, so why not prefer the potentially most efficient by default? And I suppose the same applies here. If one was a tiny bit faster than the other, why not go for the faster one? What would we lose by doing it? Both are fairly easy to read and type out.

@Dennis Zickefoose: You're right. I see that a lot on SO, and Clifford's comment is right. In addition, there's something I don't see a lot on SO, and that is how to do macro-optimization, like a 43x speedup: stackoverflow.com/questions/926266/. So I wonder about our priorities.

@Mike: Yeah, but that's an apples to oranges comparison. Getting a haircut takes actual time, and probably even money. I agree it is such a microoptimization that it doesn't really matter. But it also doesn't cost us anything. if I can choose to go left or right, and the distance is the same, the terrain is the same, everything is the same, except that the left path has some marginal microscopic benefit, why not go left? You're right, it's not an impressive argument. But when the cost is literally zero, I see no reason to prefer the less optimal route.

c++ - Is "for(;;)" faster than "while (TRUE)"? If not, why do people u...

c++ c optimization readability infinite-loop
Rectangle 27 6

All good answers - behavior should be exactly the same.

HOWEVER - Just suppose it DID make a difference. Suppose one of them took 3 more instructions per iteration.

ONLY if what you do inside the loop is almost nothing, which is almost never the case.

My point is, there is micro-optimization and macro-optimization. Micro-optimization is like "getting a haircut to lose weight".

++i
i++

@Dennis Zickefoose: The difference between ++i and i++ can potentially be significant if i is an instance of a class rather than a built-in and the compiler does not apply the trivial optimisation. The advice is to acquire a habit so that it won't catch you out when it counts.

The thing about ++i vs i++ is that it doesn't cost you anything to make the "optimization". True, in most cases it makes absolutely no difference, but they're equally easy to type, so why not prefer the potentially most efficient by default? And I suppose the same applies here. If one was a tiny bit faster than the other, why not go for the faster one? What would we lose by doing it? Both are fairly easy to read and type out.

@Dennis Zickefoose: You're right. I see that a lot on SO, and Clifford's comment is right. In addition, there's something I don't see a lot on SO, and that is how to do macro-optimization, like a 43x speedup: stackoverflow.com/questions/926266/. So I wonder about our priorities.

@Mike: Yeah, but that's an apples to oranges comparison. Getting a haircut takes actual time, and probably even money. I agree it is such a microoptimization that it doesn't really matter. But it also doesn't cost us anything. if I can choose to go left or right, and the distance is the same, the terrain is the same, everything is the same, except that the left path has some marginal microscopic benefit, why not go left? You're right, it's not an impressive argument. But when the cost is literally zero, I see no reason to prefer the less optimal route.

c++ - Is "for(;;)" faster than "while (TRUE)"? If not, why do people u...

c++ c optimization readability infinite-loop
Rectangle 27 34

The PrimeFaces process and standard JSF execute attributes should point to spaceseparated component identifiers of components which JSF should process during the entire JSF lifecycle upon an ajax request (get request parameters, validate them, update model, execute action). The process defaults to @form, the current form, and the execute defaults to @this, the current component. In command links/buttons this is mandatory to execute the actions associated with the link/button itself.

However, in your datatable you have process="@this infoAnggaranForm:Anggaran", thus two components to process. If you omit @this but keep the other component, then it will only process/execute the other component and not the link/button component. If you omit the process attribute it will default to @form. If you have more other input components in the same form, then they will also be processed.

Depending on the concrete functional requirement, you could just keep it process="@this infoAnggaranForm:Anggaran", or omit it. JSF will then process/execute at least both the button and the other component, exactly as you want.

In command links/buttons this is mandatory to execute the actions associated with the link/button itself. <-- ahhhhh, this is new to me, and enlightening. Thank you ! About the process attribute of primefaces tags, i think it defaults to @all based on my tests. And as you said already, execute defaults to @this. Thanks again BalusC !

jsf - What is the function of @this exactly? - Stack Overflow

jsf jsf-2 primefaces
Rectangle 27 470

This highly upvoted legacy answer is technically correct but only covers a very specific scenario, when your string value is EXACTLY "true" or "false" (MUST be lowercase as well).

JSON.parse("true");

or with jQuery

$.parseJSON("true");

The problem with this is that many potential value generate a parse error which stops JS execution. So running JSON.parse("FALSE") bombs Javascript. The point of the question, I think, is not to simply solve these exact cases, but also be resilient to other cases.

It's pretty simple to just say JSON.parse("TRUE".toLowerCase()) so that it can parse correctly.

@Ebenezar I can respect that, yet my time is spent optimizing for other >99%. Folks using ie7 in 15 are obviously not very well concerned with the internet thing. cheers.

why there are so many upvotes? This is inefficient and horrible.What's next? 'true'.length === 4?

How can I convert a string to boolean in JavaScript? - Stack Overflow

javascript
Rectangle 27 11

These expressions compile to the exact same bytecode, so they're exactly equally efficient. not in tends to be more readable, but it's a matter of opinion.

>>> import dis
>>> def f(x, y):
...     return not x in y
...
>>> def g(x, y):
...     return x not in y
...
>>> dis.dis(f)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_FAST                1 (y)
              6 COMPARE_OP               7 (not in)
              9 RETURN_VALUE
>>> dis.dis(g)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_FAST                1 (y)
              6 COMPARE_OP               7 (not in)
              9 RETURN_VALUE

Thanks. I did not know about dis. This seems very useful.

list - Effect of the position of 'not' in python statement on performa...

python list boolean-operations