How do sites like codepad.org and ideone.com sandbox your program?

codepad.org has something based on geordi, which runs everything in a chroot (i.e restricted to a subtree of the filesystem) with resource restrictions, and uses the ptrace API to restrict the untrusted program’s use of system calls. See http://codepad.org/about . I’ve previously used Systrace, another utility for restricting system calls. If the policy is set … Read more

Detecting a (naughty or nice) URL or link in a text string

I’m concentrating my answer on trying to avoid spammers. This leads to two sub-assumptions: the people using the system will therefore be actively trying to contravene your check and your goal is only to detect the presence of a URL, not to extract the complete URL. This solution would look different if your goal is … Read more

What is tail-recursion elimination?

Tail call elimination is an optimization that saves stack space. It replaces a function call with a goto. Tail recursion elimination is the same thing, but with the added constraint that the function is calling itself. Basically, if the very last thing a function A does is return A(params…) then you can eliminate the allocation … Read more

How to solve the violations of the Law of Demeter?

My understanding of consequences of the Law of Demeter seems to be different to DrJokepu’s – whenever I’ve applied it to object oriented code it’s resulted in tighter encapsulation and cohesion, rather than the addition of extra getters to contract paths in procedural code. Wikipedia has the rule as More formally, the Law of Demeter … Read more

Shortest distance between two line segments

This is my solution in Python. Works with 3d points and you can simplify for 2d. import numpy as np def closestDistanceBetweenLines(a0,a1,b0,b1,clampAll=False,clampA0=False,clampA1=False,clampB0=False,clampB1=False): ”’ Given two lines defined by numpy.array pairs (a0,a1,b0,b1) Return the closest points on each segment and their distance ”’ # If clampAll=True, set all clamps to True if clampAll: clampA0=True clampA1=True clampB0=True … Read more

Best practices: Many small functions/methods, or bigger functions with logical process components inline? [closed]

I always break long methods up into logical chunks and try to make smaller methods out of them. I don’t normally turn a few lines into a separate method until I need it in two different places, but sometimes I do just to help readability, or if I want to test it in isolation. Fowler’s … Read more

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