By default, the caret ^ metacharacter matches the position before the first
character in the string.
Given the string "charsequence" applied
against the following patterns: /^char/ & /^sequence/, the engine will try to match as follows:
/^char/
^ - charsequence
c - charsequ...
Proper indentation gives not only the aesthetic look but also increases the readability of the code.
For example, consider the following code:
%no need to understand the code, just give it a look
n = 2;
bf = false;
while n>1
for ii = 1:n
for jj = 1:n
if ii+jj>30
bf = true;
break
end...
For multiple quotechars use regex in place of sep:
df = pd.read_csv(log_file,
sep=r'\s(?=(?:[^"]*"[^"]*")*[^"]*$)(?![^\[]*\])',
engine='python',
usecols=[0, 3, 4, 5, 6, 7, 8],
names=['ip', 'time', 'request', 'statu...
Any loop may be terminated or continued early at any point by using the Exit or Continue statements.
Exiting
You can stop any loop by exiting early. To do this, you can use the keyword Exit along with the name of the loop.
LoopExit StatementForExit ForFor EachExit ForDo WhileExit DoWhileExit Whil...
You can set a setUp and tearDown function.
A setUp function prepares your environment to tests.
A tearDown function does a rollback.
This is a good option when you can't modify your database and you need to create an object that simulate an object brought of database or need to init a configu...
var pattern = createPattern(imageObject,repeat)
Creates a reusable pattern (object).
The object can be assigned to any strokeStyle and/or fillStyle.
Then stroke() or fill() will paint the Path with the pattern of the object.
Arguments:
imageObject is an image that will be used as a patter...
You can also perform this task recursively, but I have chosen in this example to use an iterative approach. This task is useful if you are inserting all of your nodes at the beginning of a linked list. Here is an example:
#include <stdio.h>
#include <stdlib.h>
#define NUM_ITEMS 10...
CPython allows access to the code object for a function object.
The __code__object contains the raw bytecode (co_code) of the function as well as other information such as constants and variable names.
def fib(n):
if n <= 2: return 1
return fib(n-1) + fib(n-2)
dir(fib.__code__)
de...
To install NLTK with Continuum's anaconda / conda.
If you are using Anaconda, most probably nltk would be already downloaded in the root (though you may still need to download various packages manually).
Using conda:
conda install nltk
To upgrade nltk using conda:
conda update nltk
With a...
Get current date and time
lib.date = TEXT
lib.date {
data = date:U
strftime = %d.%m.%Y %H:%M:%S
wrap = Today is |
}
Get last login time and date from fe_users
lib.date = TEXT
lib.date {
data = TSFE:fe_user|user|lastlogin
strftime = %d.%m.%Y %H:%M:%S
wrap = Last logi...
Given this setup code:
var dict = new Dictionary<int, string>()
{
{ 1, "First" },
{ 2, "Second" },
{ 3, "Third" }
};
Use the Remove method to remove a key and its associated value.
bool wasRemoved = dict.Remove(2);
Executing this code remo...
In some situations, one might want to return from a function before finishing an entire loop. The return statement can be used for this.
function primefactor(n)
for i in 2:n
if n % i == 0
return i
end
end
@assert false # unreachable
end
Usage:
jul...
Although not traditionally considered loops, the @goto and @label macros can be used for more advanced control flow. One use case is when the failure of one part should lead to the retry of an entire function, often useful in input validation:
function getsequence()
local a, b
@label start
...
A Mixin is a set of properties and methods that can be used in different classes, which don't come from a base class. In Object Oriented Programming languages, you typically use inheritance to give objects of different classes the same functionality; if a set of objects have some ability, you put th...
MySQLi is a PHP Extension which enables PHP to communicate with MySQL Databases. MySQLi comes built in with PHP. MySQLi was introduced with PHP 5.0.
For More details about Installations Refer official PHP MySQLi Documentation
Here is a class (Dog) creating its own dependency (Food):
class Dog {
public Dog() {
var food = new Food();
this.eat(food);
}
}
Here is the same class being injected with its dependency using constructor injection:
class Dog {
public Dog(Food food) {
...
The JOIN operation performs a join between two tables, excluding any unmatched rows from the first table. From Oracle 9i forward, the JOIN is equivalent in function to the INNER JOIN. This operation requires an explicit join clause, as opposed to the CROSS JOIN and NATURAL JOIN operators.
Example:
...
The next function is useful even without iterating. Passing a generator expression to next is a quick way to search for the first occurrence of an element matching some predicate. Procedural code like
def find_and_transform(sequence, predicate, func):
for element in sequence:
if predi...
If you want to change an attribute of a control such as a textbox or label from another thread than the GUI thread that created the control, you will have to invoke it or else you might get an error message stating:
"Cross-thread operation not valid: Control 'control_name' accessed from a th...