What does shift() do in Perl?

shift() is a built in Perl subroutine that takes an array as an argument, then returns and deletes the first item in that array. It is common practice to obtain all parameters passed into a subroutine with shift calls. For example, say you have a subroutine foo that takes three arguments. One way to get … Read more

What does “<

<() is called process substitution in the manual, and is similar to a pipe but passes an argument of the form /dev/fd/63 instead of using stdin. < reads the input from a file named on command line. Together, these two operators function exactly like a pipe, so it could be rewritten as find /bar -name … Read more

Why does numpy have a corresponding function for many ndarray methods?

As others have noted, the identically-named NumPy functions and array methods are often equivalent (they end up calling the same underlying code). One might be preferred over the other if it makes for easier reading. However, in some instances the two behave different slightly differently. In particular, using the ndarray method sometimes emphasises the fact … Read more

Python: Can a subclass of float take extra arguments in its constructor?

As float is immutable you have to overwrite __new__ as well. The following should do what you want: class Foo(float): def __new__(self, value, extra): return float.__new__(self, value) def __init__(self, value, extra): float.__init__(value) self.extra = extra foo = Foo(1,2) print(str(foo)) 1.0 print(str(foo.extra)) 2 See also Sub-classing float type in Python, fails to catch exception in __init__()

How to avoid SQL injection in CodeIgniter?

CodeIgniter’s Active Record methods automatically escape queries for you, to prevent sql injection. $this->db->select(‘*’)->from(‘tablename’)->where(‘var’, $val1); $this->db->get(); or $this->db->insert(‘tablename’, array(‘var1’=>$val1, ‘var2’=>$val2)); If you don’t want to use Active Records, you can use query bindings to prevent against injection. $sql=”SELECT * FROM tablename WHERE var = ?”; $this->db->query($sql, array($val1)); Or for inserting you can use the insert_string() … Read more

How does __builtin___clear_cache work?

It is just emitting some weird machine instruction[s] on target processors requiring them (x86 don’t need that). Think of __builtin___clear_cache as a “portable” (to GCC and compatible compilers) way to flush the instruction cache (e.g. in some JIT library). In practice, how could one find what the right begin and end to use? To be … Read more