A simple cursor syntax, operating on a few example test rows:
/* Prepare test data */
DECLARE @test_table TABLE
(
Id INT,
Val VARCHAR(100)
);
INSERT INTO @test_table(Id, Val)
VALUES
(1, 'Foo'),
(2, 'Bar'),
(3, 'Baz');
/* Test data prepared */
/* Iterator variabl...
COPY is PostgreSQL's bulk-insert mechanism. It's a convenient way to transfer data between files and tables, but it's also far faster than INSERT when adding more than a few thousand rows at a time.
Let's begin by creating sample data file.
cat > samplet_data.csv
1,Yogesh
2,Raunak
3,Varun
...
Media queries allow one to apply CSS rules based on the type of device / media (e.g. screen, print or handheld) called media type, additional aspects of the device are described with media features such as the availability of color or viewport dimensions.
General Structure of a Media Query
@media ...
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...
Assertions are used not to perform testing of input parameters, but to verify that program flow is corect -- i.e., that you can make certain assumptions about your code at a certain point in time. In other words: a test done with Debug.Assert should always assume that the value tested is true.
Debu...
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...
This function executes an AJAX request using the HEAD method allowing us to check whether a file exists in the directory given as an argument. It also enables us to launch a callback for each case (success, failure).
function fileExists(dir, successCallback, errorCallback) {
var xhttp = new XM...
The Python interpreter compiles code to bytecode before executing it on the Python's virtual machine (see also What is python bytecode?.
Here's how to view the bytecode of a Python function
import dis
def fib(n):
if n <= 2: return 1
return fib(n-1) + fib(n-2)
# Display the disas...
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...
This example goes over how to set up CoreNLP from the GitHub repo. The GitHub code has newer features than the official release, but may be unstable. This example will take you through downloading, building, and running a simple command-line invocation of CoreNLP.
Prerequisites:
Java 8 or newer....
A common use case for a for loop is to iterate over a predefined range or collection, and do the same task for all its elements. For instance, here we combine a for loop with a conditional if-elseif-else statement:
for i in 1:100
if i % 15 == 0
println("FizzBuzz")
elsei...
The while loop runs its body as long as the condition holds. For instance, the following code computes and prints the Collatz sequence from a given number:
function collatz(n)
while n ≠ 1
println(n)
n = iseven(n) ? n ÷ 2 : 3n + 1
end
println("1... and 4, 2, 1, ...
In Julia, a for loop can contain a comma (,) to specify iterating over multiple dimensions. This acts similarly to nesting a loop within another, but can be more compact. For instance, the below function generates elements of the Cartesian product of two iterables:
function cartesian(xs, ys)
f...
Julia provides macros to simplify distributing computation across multiple machines or workers. For instance, the following computes the sum of some number of squares, possibly in parallel.
function sumofsquares(A)
@parallel (+) for i in A
i ^ 2
end
end
Usage:
julia> sumo...
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
...
For branching
The short-circuiting conditional operators && and || can be used as lightweight replacements for the following constructs:
x && y is equivalent to x ? y : x
x || y is equivalent to x ? x : y
One use for short-circuit operators is as a more concise way to test a ...
d = Dates.dayofweek(now())
if d == 7
println("It is Sunday!")
elseif d == 6
println("It is Saturday!")
elseif d == 5
println("Almost the weekend!")
else
println("Not the weekend yet...")
end
Any number of elseif branches may be used...