How do I expire a PHP session after 30 minutes?

You should implement a session timeout of your own. Both options mentioned by others (session.gc_maxlifetime and session.cookie_lifetime) are not reliable. I’ll explain the reasons for that. First: session.gc_maxlifetimesession.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and cleaned up. Garbage collection occurs during session start. But the garbage collector is … Read more

Hide element by class in pure Javascript

document.getElementsByClassName returns an HTMLCollection(an array-like object) of all elements matching the class name. The style property is defined for Element not for HTMLCollection. You should access the first element using the bracket(subscript) notation. Updated jsFiddle To change the style rules of all elements matching the class, using the Selectors API: If for…of is available:

paint() and repaint() in Java

I’ve spent maybe the last two hours browsing and reading up on these methods and the Graphics class, and maybe I’m stupid, haha, but I’m just not understanding them. What are they for? I understand that they’re supposed redraw or update components on the screen, but I have never understood why this is required (I’m … Read more

Optimization of a function in R ( L-BFGS-B needs finite values of ‘fn’)

At some point in the optimization, your function is returning a value greater than .Machine$double.xmax (which is 1.797693e+308 on my machine). Since your function f1(…) is defined as sum(log(exp(…))), and since log(exp(z)) = z for any z, why not use this: Note that the vector of parameters (par) must be the first argument to f1.

Categories R

Replacing a character from a certain index

How can I replace a character in a string from a certain index? For example, I want to get the middle character from a string, like abc, and if the character is not equal to the character the user specifies, then I want to replace it. Something like this maybe?