Django: no such table: django_session

It could be that the server uses a different working directory than the manage.py command. Since you provide a relative path to the sqlite database, it is created in the working directory. Try it with an absolute path, e.g.: Remember that you have to either run ./manage.py syncdb again or copy your current database with the existing tables to /tmp. … Read more

c++ parse int from string [duplicate]

In C++11, use std::stoi as: std::string s = “10”; int i = std::stoi(s); Note that std::stoi will throw exception of type std::invalid_argument if the conversion cannot be performed, or std::out_of_range if the conversion results in overflow(i.e when the string value is too big for int type). You can use std::stol or std:stoll though in case int seems too small for the input string. In C++03/98, any of the following can be … Read more

Sort array of objects by object fields

Use usort, here’s an example adapted from the manual: You can also use any callable as the second argument. Here are some examples: Using anonymous functions (from PHP 5.3) usort($your_data, function($a, $b) {return strcmp($a->name, $b->name);}); From inside a class usort($your_data, array($this, “cmp”)); // “cmp” should be a method in the class Using arrow functions (from PHP 7.4) usort($your_data, fn($a, $b) => strcmp($a->name, … Read more

Can’t run C program: “a.out: command not found”

When you type a command name (a.out is no different from any other command name in this respect), the shell searches for an executable file with that name. It performs this search using a list of directory names stored in your $PATH environment variable. You can see your current $PATH by typing at your shell prompt. A typical value might … Read more

Shebang doesn’t work with python3

Generally, take care of some pitfalls: set the executable flag on the script: chmod u+x test.py try to execute with a preceding dot “./”, so call ./test.py otherwise it might execute some other script from within your PATH also make sure you don’t have windows line endings, this seems to prevent the shebang evaluation, too. There are some suggestions around, e.g. in this answer, on … Read more

simple Haskell loop

You could define a recursive function that prints “a string” n times (n being the parameter of the function), like this: A somewhat more general approach would be to define a function that repeats any IO action n times: The above function already exists in Control.Monad under the name replicateM_.

remove all variables except functions

Here’s a one-liner that removes all objects except for functions: It uses setdiff to find the subset of objects in the global environment (as returned by ls()) that don’t have mode function (as returned by lsf.str())

Categories R