Calling a function every 60 seconds

If you don’t care if the code within the timer may take longer than your interval, use setInterval(): setInterval(function, delay) That fires the function passed in as first parameter over and over. A better approach is, to use setTimeout along with a self-executing anonymous function: (function(){ // do some stuff setTimeout(arguments.callee, 60000); })(); that guarantees, … Read more

PHP function to generate v4 UUID

Instead of breaking it down into individual fields, it’s easier to generate a random block of data and change the individual byte positions. You should also use a better random number generator than mt_rand(). According to RFC 4122 – Section 4.4, you need to change these fields: time_hi_and_version (bits 4-7 of 7th octet), clock_seq_hi_and_reserved (bit … Read more

Defining private module functions in python

In Python, “privacy” depends on “consenting adults’” levels of agreement – you can’t force it (any more than you can in real life;-). A single leading underscore means you’re not supposed to access it “from the outside” — two leading underscores (w/o trailing underscores) carry the message even more forcefully… but, in the end, it … Read more

jQuery’s .click – pass parameters to user function

For thoroughness, I came across another solution which was part of the functionality introduced in version 1.4.3 of the jQuery click event handler. It allows you to pass a data map to the event object that automatically gets fed back to the event handler function by jQuery as the first parameter. The data map would … Read more

Meaning of = delete after function declaration

Deleting a function is a C++11 feature: The common idiom of “prohibiting copying” can now be expressed directly: class X { // … X& operator=(const X&) = delete; // Disallow copying X(const X&) = delete; }; […] The “delete” mechanism can be used for any function. For example, we can eliminate an undesired conversion like … Read more

How to get the function name from within that function?

In ES6, you can just use myFunction.name. Note: Beware that some JS minifiers might throw away function names, to compress better; you may need to tweak their settings to avoid that. In ES5, the best thing to do is: function functionName(fun) { var ret = fun.toString(); ret = ret.substr(‘function ‘.length); ret = ret.substr(0, ret.indexOf(‘(‘)); return … Read more

Proper use of const for defining functions

There’s no problem with what you’ve done, but you must remember the difference between function declarations and function expressions. A function declaration, that is: function doSomething () {} Is hoisted entirely to the top of the scope (and like let and const they are block scoped as well). This means that the following will work: … Read more

strdup() – what does it do in C?

Exactly what it sounds like, assuming you’re used to the abbreviated way in which C and UNIX assigns words, it duplicates strings 🙂 Keeping in mind it’s actually not part of the current (C17) ISO C standard itself(a) (it’s a POSIX thing), it’s effectively doing the same as the following code: char *strdup(const char *src) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)