The JavaScript event loop is a fundamental concept that allows JavaScript to perform non-blocking operations, even though it is single-threaded. The event loop continuously checks the call stack and the message queue. If the call stack is empty, it takes the first event from the queue and pushes its associated callback onto the call stack for execution.
Here’s a simple example to illustrate how the event loop works:
1 2 3 4 5 6 7 8 9 10 11 console.
In the previous post about regular expressions we explained how to express a variable number of characters at certain position in our regex. And how to write a regex that would allow us to capture words inside a context (specific characters before and after the word). But we’ve seen that context is considered part of the matching by the regex engine and we need to avoid that. Let’s see how to solve that issue.
In the first post about regular expressions we’ve explained how it is possible to write a regex matching specific characters (or character group/type) at certain position. In a way that makes it very easy to write a regex that finds an x followed by a white space, followed by a y. But what if we need to find an a followed by four to six decimal digits, followed by a b.
Not kidding! Developers fear the regex. And yeah, I get it. They look ugly. But they are powerful.
And it is way more hard to read them than to write them. Which is not ideal. But at least you can benefit from writing a regex here and there. Probably document them in-code with a meaningful comment for your future self and you’ll be fine. Learning to write some basic, simple yet powerful regex is not impossible and I’m writing this post to prove that.
This code snippet shows how to get the local MAC (hardware) address in POSIX systems. It should work in Windows too, using Cygwin or similar.
#include <netdb.h>#include <unistd.h>#include <string.h>#include <sys/fcntl.h>#include <sys/errno.h>#include <sys/ioctl.h>#include <sys/socket.h>#include <arpa/inet.h>#include <net/if.h>#include <stdio.h> int main(int argc, char ** argv) { struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_STREAM,0)) < 0) { perror("socket"); return -1; } strcpy(ifr.ifr_name, argv[1]); if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { perror("ioctl"); return -1; } unsigned char *hwaddr = (unsigned char *)ifr.
We use cookies on this website to give you the best experience. To find out more, read our privacy policy and cookie policy.