Is there a rule of thumb regarding the minimum threshold for a person to be 2nd author of a paper? I’ve been working on a machine-learning project for the past several months, and I will publish a paper on it soon. On the other hand, there is a person with whom I have worked on various things since a year ago. However, I haven’t told this particular project to him until it was pretty much completed. Even after I revealed it to him, his net contribution to the project seems to me rather negligible. 

For example, he made no contribution in terms of original ideas, designing of the algorithm (as he wasn’t informed of my project until later) or writing the paper, and his only contribution to the codes is just one small function, which is a variant of a function I wrote and he thought was useful for supplementing an evaluation of my algorithm. Though he offered to run my algorithm on his GPU; it seems that he hasn’t tested it yet. So far, all the results were achieved with my GPU. Besides, even if he gets a good result on his GPU with the code exactly same as mine, I'm not sure whether he deserves to be a second author of the paper.

There is one project we worked on before but didn’t result in any paper, to which my algorithm can be applied, so that another paper can be published on. My suggestion is that I will help him to apply my code to this past project, so that he can be a co-author of the past project rather than the current project I’m working on. 

Does this sound reasonable? Or am I being too parsimonious? Is there any relevant rule of thumb?
There’s no minimum limit. Second authors can contribute ideas, work or anything that went into the paper. Some might even cynically say that contributing reputation is enough.

Having said that, if you’re not satisfied that your friend has actually contributed anything significant to the paper that warrants author status, you can always mention him in your acknowledgement section instead of adding him as a second author.