Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Rather slow, but working method to include any of words:
***
SELECT * FROM mytable
WHERE column1 LIKE '%word1%'
OR column1 LIKE '%word2%'
OR column1 LIKE '%word3%'
***
If you need all words to be present, use this:
***
SELECT * FROM mytable
WHERE column1 LIKE '%word1%'
AND column1 LIKE '%word2%'
AND column1 LIKE '%word3%'
***
If you want something faster, you need to look into full text search, and this is very specific for each database type.
4 years ago
Here's how I'd do it -

For Schemas (or Databases - they are synonyms):
***
SELECT default_character_set_name FROM information_schema.SCHEMATA
WHERE schema_name = "schemaname";
***
For Tables:
***
SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "schemaname"
AND T.table_name = "tablename";
***
For Columns:
***
SELECT character_set_name FROM information_schema.`COLUMNS`
WHERE table_schema = "schemaname"
AND table_name = "tablename"
AND column_name = "columnname";
***
4 years ago
To output to the screen the last queries ran you can use this:
***
DB::enableQueryLog(); // Enable query log

// Your Eloquent query executed by using get()

dd(DB::getQueryLog()); // Show results of log
***
I think the most recent queries will be at the bottom of the array.

You will get something like :
***
array(1) {
[0]=>
array(3) {
["query"]=>
string(21) "select * from "users""
["bindings"]=>
array(0) {
}
["time"]=>
string(4) "0.92"
}
}
***
4 years ago
GCC: GNU Compiler Collection

- Referrers to all the different languages that are supported by the GNU compiler.
gcc: GNU C Compiler
g++: GNU C++ Compiler

The main differences:

1. gcc will compile: *.c\*.cpp files as C and C++ respectively.
2. g++ will compile: *.c\*.cpp files but they will all be treated as C++ files.
3. Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
4. gcc compiling C files has fewer predefined macros.
5. gcc compiling *.cpp and g++ compiling *.c\*.cpp files has a few extra macros.
Extra Macros when compiling *.cpp files:
***
#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
***
4 years ago
emplace_back shouldn't take an argument of type vector::value_type, but instead variadic arguments that are forwarded to the constructor of the appended item.
***
template void emplace_back(Args&&... args);
***
It is possible to pass a value_type which will be forwarded to the copy constructor.

Because it forwards the arguments, this means that if you don't have rvalue, this still means that the container will store a "copied" copy, not a moved copy.
***
std::vector vec;
vec.emplace_back(std::string("Hello")); // moves
std::string s;
vec.emplace_back(s); //copies
***
But the above should be identical to what push_back does. It is probably rather meant for use cases like:
***
std::vector > vec;
vec.emplace_back(std::string("Hello"), std::string("world"));
// should end up invoking this constructor:
//template pair(U&& x, V&& y);
//without making any copies of the strings
***
4 years ago
Using Boost's string algorithms would be easiest:
***
#include

std::string str("hello world! ");
boost::trim_right(str);
***
str is now "hello world!". There's also trim_left and trim, which trims both sides.
4 years ago
***
#include
#include
#include

std::string data = "Abc";
std::transform(data.begin(), data.end(), data.begin(),
[](unsigned char c){ return std::tolower(c); });
***
You're really not going to get away without iterating through each character. There's no way to know whether the character is lowercase or uppercase otherwise.

If you really hate tolower(), here's a specialized ASCII-only alternative that I don't recommend you use:
***
char asciitolower(char in) {
if (in <= 'Z' && in >= 'A')
return in - ('Z' - 'z');
return in;
}
***
std::transform(data.begin(), data.end(), data.begin(), asciitolower);
Be aware that tolower() can only do a per-single-byte-character substitution, which is ill-fitting for many scripts, especially if using a multi-byte-encoding like UTF-8.
4 years ago
You could avoid memory allocation. There are many variants, all having problems in case of multithreading environment.

I prefer this kind of implementation (actually, it is not correctly said I prefer, because I avoid singletons as much as possible):
***
class Singleton
{
private:
Singleton();

public:
static Singleton& instance()
{
static Singleton INSTANCE;
return INSTANCE;
}
};
***
It has no dynamic memory allocation.
4 years ago
Base class constructors are automatically called for you if they have no argument. If you want to call a superclass constructor with an argument, you must use the subclass's constructor initialization list. Unlike Java, C++ supports multiple inheritance (for better or worse), so the base class must be referred to by name, rather than "super()".
***
class SuperClass
{
public:

SuperClass(int foo)
{
// do something with foo
}
};

class SubClass : public SuperClass
{
public:

SubClass(int foo, int bar)
: SuperClass(foo) // Call the superclass constructor in the subclass' initialization list.
{
// do something with bar
}
};
***
4 years ago
char, signed char, and unsigned char are at least 8 bits
signed short, unsigned short, signed int, and unsigned int are at least 16 bits
signed long and unsigned long are at least 32 bits
signed long long and unsigned long long are at least 64 bits
4 years ago
Note that there is no standard C API for milliseconds, so (on Unix) you will have to settle for usleep, which accepts microseconds:
***
#include

unsigned int microseconds;
...
usleep(microseconds);
***
4 years ago
First, make an ifstream:

#include
std::ifstream infile("thefile.txt");
The two standard methods are:

1. *Assume that every line consists of two numbers and read token by token*:
***
int a, b;
while (infile >> a >> b)
{
// process pair (a,b)
}
***
2. *Line-based parsing, using string streams*:
***
#include
#include

std::string line;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int a, b;
if (!(iss >> a >> b)) { break; } // error

// process pair (a,b)
}
***
You shouldn't mix (1) and (2), since the token-based parsing doesn't gobble up newlines, so you may end up with spurious empty lines if you use getline() after token-based extraction got you to the end of a line already.
4 years ago