Wikipedia:Reference desk/Archives/Computing/2017 July 17

Computing desk
< July 16 << Jun | July | Aug >> July 18 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


July 17

edit

Is this Javascript code obfuscated?

edit

When I look at the source of a web page, I often find Javascript code like the following:

(function y(f, c, p) {
  function l(b, g) {
    if (!c[b]) {
      if (!f[b]) {
        var d = 'function' == typeof require && require;
        if (!g && d) return d(b, !0);
        if (k) return k(b, !0);
        d = Error('Cannot find module \'' + b + '\'');
        throw d.code = 'MODULE_NOT_FOUND',
        d;
      }
      d = c[b] = {
        a: {
        }
      };
      f[b][0].call(d.a, function (c) {
        var d = f[b][1][c];
        return l(d ? d : c)
      }, d, d.a, y, f, c, p)
    }
    return c[b].a
  }
  for (var k = 'function' == typeof require && require, g = 0; g < p.length; g++) l(p[g]);
  return l
})

Does this function have to be written this way in order to work correctly, or is it intentionally obfuscated? To me, it looks like the latter, because it is creating an inline function that itself creates another function; however, I'm no Javascript expert, so I thought I'd ask here. Thanks! OldTimeNESter (talk) 12:27, 17 July 2017 (UTC)[reply]

Javascript is commonly written as functions embedded in functions. The only problem with this code is that the variable names are very poorly chosen (and there is at least one syntax error). 209.149.113.5 (talk) 12:33, 17 July 2017 (UTC)[reply]
The pattern of wrapping all your code in one big function and then calling that is a self invoking function, and is a common pattern to avoid dumping one's symbols wholesale into the global namespace. The code you've pasted doesn't invoke itself, but I wonder if that's just because you've not pasted quite enough of the original. The second function of note is the argument to call, which is a lambda, and is again a very common pattern. I don't think the code has been deliberately obfuscated, although the unhelpful symbol names suggest that it has been (lightly) minified. -- Finlay McWalter··–·Talk 12:36, 17 July 2017 (UTC)[reply]
Yes, the single-character variable names are typical of minified JavaScript, as are the use of !0 as shorthand for true, and the absence of comments. Presumably the original didn't have the line breaks and indentation shown in the example. AndrewWTaylor (talk) 12:47, 17 July 2017 (UTC)[reply]
Yes, the original code was minified (I cleaned it up with Prettify). I didn't know that !0 was minified shorthand for true: typically when I see something like that in (say) a C program, it's because the programmer is deliberately trying to be unclear. Thanks for everyone's answers. OldTimeNESter (talk) 18:00, 17 July 2017 (UTC)[reply]
Or perhaps they are saving two keystrokes (not a good idea). Bubba73 You talkin' to me? 01:29, 18 July 2017 (UTC)[reply]
In this case, it isn't saving keystrokes. It is saving characters, which reduces file size, which cuts down on network usage. 209.149.113.5 (talk) 13:15, 18 July 2017 (UTC)[reply]

Map app(s)

edit

Does “Google Maps” do off-line maps. If not, which one could you refer that would be a reliable one please.

Note: I recall (when I was young), Graham (or something alike) that wasn’t a mobile app but was an actual machine, consisted capability of re-directing you to/with other routes when the directed road was conjected (traffic issue). This functionality is desired for the Smart Phone app I’m requesting to you. 103.67.159.235 (talk) 18:02, 17 July 2017 (UTC)[reply]

The Google Maps Android has been able to do offline maps for several years now although you need to tell it and select the area and need to update it regularly or it will stop working. It's disabled in several locations because of local laws, I don't know if Bangladesh is one of them. Note that I'm pretty sure no app can get traffic conditions when offline. While some standalone GPSes did do this via specialised radio transmissions I doubt that ever existed in Bangladesh and even if it did it's not something that carried over into phones probably because in most developed countries using 2 way data is simpler and has some advantages. Nil Einne (talk) 18:18, 17 July 2017 (UTC)[reply]
Actually Traffic message channel suggests I may be partially wrong. Some apps can accept TMC info but they generally required a specialised receiver to be connected to the phone. I still doubt you will find TMC info in Bangladesh though. (I'm actually a bit surprised that a specialised receiver is needed since I'm pretty sure the many Android phones with FM receivers can usually decode RDS at least for data display in the radio app, when FM reception is working i.e. you have headphones or something else plugged into the headphone jack. So I would have thought decoding the RDS-TMC sent via FM would be possible. But to be fair, I'm not sure how standardised the FM receiver control part is as I've generally only used the builtin app. Maybe the APIs are so unstandard or poorly implemented it wasn't worth the effort.) Nil Einne (talk) 19:26, 17 July 2017 (UTC)[reply]
[1] makes me think maybe I'm right on the last point although some developers have tried with varying success. Nil Einne (talk) 19:28, 17 July 2017 (UTC)[reply]
Could you refer me to something good please. Also, which {https://play.google.com/store/search?q=tomtom&hl=en_GB TomTom] are you talking about? Thanks in advance. 116.58.200.32 (talk) 17:22, 18 July 2017 (UTC)[reply]
I don't understand your question. What do you mean something good? Also I didn't talk about any TomTom so I have no idea what your second question is about. I did provide a link on the TomTom forums which mentions how the feature was in some third party software (not TomTom) although only supporting certain HTC phones and this was in 2013, but that's a different point and in no way explains why you're interested in TomTom. Finally if you're still interested in TMC have you actually confirmed TMC is available where you live in Bangladesh? If it isn't I don't get why you're bothering to worry about this. Nil Einne (talk) 04:45, 20 July 2017 (UTC)[reply]

Hello, I would like an offline Map system that doesn't require the 'google maps every 30 day updating issue' with all the facilities discussed above. A reliable one with no detailing problem please. I wished to update with will. 103.67.156.7 (talk) 17:47, 18 July 2017 (UTC)[reply]

Galileo Offline Maps is one option.[2] Graeme Bartlett (talk) 23:43, 18 July 2017 (UTC)[reply]
I use Here (formerly Nokia) for offline maps. But what facilities? You haven't actually specified anything except traffic and not updating but as already explained to you, traffic conditions nearly always requires an internet connection. The only time it doesn't is when you have a device to get TMC messages but since you don't have such a device it's silly to talk about hypotheticals. If you ever actually by a device to get TMC messages you should find out what software supports it. There is a very slightly possibility you may be able to get TMC messages over the phones built in FM radio but this seems to be very poorly supported. And in any case all of this requires that there even are TMC messages over FM (or some other system if you're talking about an additional device) where you live which has not been established. Nil Einne (talk) 04:45, 20 July 2017 (UTC)[reply]
Give me something good, that I can last with for some time. 116.58.204.222 (talk) 14:58, 20 July 2017 (UTC)[reply]
You've already been given two options. There are undoutedly many more. If there's something about these options that doesn't work for you, you'll need to explain what that is Nil Einne (talk) 15:02, 20 July 2017 (UTC)[reply]

Network Activity Light

edit

On a typical Ethernet network card or network switch, the activity light blinks when there is network activity.

What exactly triggers the activity light to blink? Does it blink once after so many packets within a time frame or is it dependent on a specific type of packet that's sent/received? — Preceding unsigned comment added by 136.159.16.240 (talk) 21:32, 17 July 2017 (UTC)[reply]

Often they're literally just connected to the data pin. This can actually be a security flaw, believe it or not. In this paper security researchers describe snooping a network by pointing a telescope at their network switch and decoding the blinky lights.
A lot of people don't realize this. People's initial instinct is that it's probably impossible, but apparently, it's not for some brands of older network equipment. (I assume that modern equipment is fast enough that the LEDs can't keep up, but I don't know for sure.) ApLundell (talk) 21:55, 17 July 2017 (UTC)[reply]
Thanks for that paper - it was an interesting read. Since modern network cards I've come in contact with only blinks at most a few times per second, is it fair to assume that the blinking is still triggered by the data pin but just rate limited by the firmware? I dug through some datasheets but haven't found any more details on what precisely makes it blink. 136.159.16.240 (talk) 00:10, 18 July 2017 (UTC)[reply]
If anyone is wondering about the last point, [3] suggests standard indicator LEDs may be limited to 1 Mhz while [4] 10 to 50 Mhz although 1Mhz may be more realistic for a simple circuit. Of course the later highlights another point namely even if the LED is capable, I doubt the circuit would be. Since we're talking about very simple modulation even 50 Mhz seems too low to be able to get useful info for many networks anyway. Nil Einne (talk) 12:51, 18 July 2017 (UTC)[reply]
Actually the circuit point got me thinking. I know basically zero about high frequency circuit design but my impression is you have to be careful about what you do. I can't help thinking that ignoring security or other similar considerations, attaching the indicator LED directly to the data pin is simply a bad idea given the requirements for modern very high frequency circuits. Nil Einne (talk) 13:00, 18 July 2017 (UTC)[reply]

PHP help

edit

In PHP using chunk_split makes a string echo each character on a new line. For example;

echo chunk_split('hello', 1);

returns;

h
e
l
l
o

How can I make it give each character a line number, so it would instead look like;

1: h
2: e
3: l
4: l
5: o

Thanks for your help. 31.145.83.202 (talk) 23:21, 17 July 2017 (UTC)[reply]

If you want each character with a line number, it's easier to just iterate over the string.
$x = "hello";
for ($i = 0; $i < strlen($x); $i++) {
    echo "$i: {$x[$i]}\n";
}
— Preceding unsigned comment added by 136.159.16.240 (talkcontribs)
foreach (str_split('hello', 1) as $index => $value) {
    echo "$index: $value\n";
}
-- Finlay McWalter··–·Talk 11:02, 18 July 2017 (UTC)[reply]


Thanks for the answers. I'm afraid that both go over my head (I'm very new to PHP). Could you explain in baby steps exactly what is happening at each step? I'm really keen to learn PHP but I need a little help. Thanks for your time. 36.81.2.206 (talk) 12:12, 18 July 2017 (UTC)[reply]

Both are simply using a for loop. It appears that your confusion is with the concept of a for loop, which is not a PHP concept. It is a general programming concept. First, you need to understand the concept of a loop. The program will step through the code line by line. When it hits the end of the loop, it starts over at the beginning of the loop again. In these two examples, the loop contains one instruction. So, that instruction will repeat over and over until the condition for the loop is not met. The first example is a classic for loop. The condition is compound. There is an initializer (set $i = 0), a condition ($i<strlen($x)), and an increment ($i++). Before it starts, it sets $i to zero. After every time through the loop, it increments $i by one. It runs as long as $i<strlen($x). The second example uses a specialized foreach. It executes the loop on every member of a set. In this case, the set is the string 'hello' split into an array containing 1 character per element of the array. So, for each character in 'hello', it performs the loop. The str_split command creates an array. So, the foreach lets you use $index to refer to the index value of each element and $value to refer the value of each element. Then, the loop is performed. Fully understanding for loops is the first part of this. When you feel that you have for loops down, please explain what else is giving you trouble. 209.149.113.5 (talk) 13:13, 18 July 2017 (UTC)[reply]

Thanks very much for the explanation. I managed to get both to work, however they both start the count from "0" instead of "1" resulting in;

0:h
1:e
2:l
3:l
4:0

instead of;

1:h
2:e
3:l
4:l
5:o

How would I go about making it start at "1"? I tried changing "$i = 0" to "$i = 1" which starts the count at "1" but now misses out the first character "h" resulting instead in;

1:e
2:l
3:l
4:o

89.218.188.4 (talk) 18:25, 18 July 2017 (UTC)[reply]

Add one to the variable. Instead of printing "$i : $v\n", print ($i+1)." : $v\n". 209.149.113.5 (talk) 14:29, 19 July 2017 (UTC)[reply]
Such a simple solution! Thank you very much to everyone for all of your help 89.218.188.4 (talk) 12:11, 20 July 2017 (UTC)[reply]
  Resolved