Tutorial by Examples: c

The zero value of slice is nil, which has the length and capacity 0. A nil slice has no underlying array. But there are also non-nil slices of length and capacity 0, like []int{} or make([]int, 5)[5:]. Any type that have nil values can be converted to nil slice: s = []int(nil) To test whether a...
Consider this simple class: class SmsUtil { public bool SendMessage(string from, string to, string message, int retryCount, object attachment) { // Some code } } Before C# 3.0 it was: var result = SmsUtil.SendMessage("Mehran", "Maryam", "Hello...
A callback is a method that gets called at specific moments of an object's lifecycle (right before or after creation, deletion, update, validation, saving or loading from the database). For instance, say you have a listing that expires within 30 days of creation. One way to do that is like this: ...
PHP 7 introduces a new kind of operator, which can be used to compare expressions. This operator will return -1, 0 or 1 if the first expression is less than, equal to, or greater than the second expression. // Integers print (1 <=> 1); // 0 print (1 <=> 2); // -1 print (2 <=> 1...
The simple answer is that you cannot do this. Once an array has been created, its size cannot be changed. Instead, an array can only be "resized" by creating a new array with the appropriate size and copying the elements from the existing array to the new one. String[] listOfCities = ne...
setTimeout Executes a function, after waiting a specified number of milliseconds. used to delay the execution of a function. Syntax : setTimeout(function, milliseconds) or window.setTimeout(function, milliseconds) Example : This example outputs "hello" to the console after 1 secon...
This example illustrates how to create a simple program that will sum two int arrays with CUDA. A CUDA program is heterogenous and consist of parts runs both on CPU and GPU. The main parts of a program that utilize CUDA are similar to CPU programs and consist of Memory allocation for data that ...
import pandas as pd df = pd.DataFrame({'Sex': ['M', 'M', 'F', 'M', 'F', 'F', 'M', 'M', 'F', 'F'], 'Age': [20, 19, 17, 35, 22, 22, 12, 15, 17, 22], 'Heart Disease': ['Y', 'N', 'Y', 'N', 'N', 'Y', 'N', 'Y', 'N', 'Y']}) df Age Heart Disease Sex 0 20 ...
To access functions and properties of nullable types, you have to use special operators. The first one, ?., gives you the property or function you're trying to access, or it gives you null if the object is null: val string: String? = "Hello World!" print(string.length) // Compile erro...
If the compiler can infer that an object can't be null at a certain point, you don't have to use the special operators anymore: var string: String? = "Hello!" print(string.length) // Compile error if(string != null) { // The compiler now knows that string can't be null print(...
In order to install PostgreSQL on OSX, you need to know which versions are currently supported. Use this command to see what versions you have available. sudo port list | grep "^postgresql[[:digit:]]\{2\}[[:space:]]" You should get a list that looks something like the following: post...
If need set value 0 to column B, where in column A are duplicated data first create mask by Series.duplicated and then use DataFrame.ix or Series.mask: In [224]: df = pd.DataFrame({'A':[1,2,3,3,2], ...: 'B':[1,7,3,0,8]}) In [225]: mask = df.A.duplicated(keep=False) In...
Use drop_duplicates: In [216]: df = pd.DataFrame({'A':[1,2,3,3,2], ...: 'B':[1,7,3,0,8]}) In [217]: df Out[217]: A B 0 1 1 1 2 7 2 3 3 3 3 0 4 2 8 # keep only the last value In [218]: df.drop_duplicates(subset=['A'], keep='last') Out[218]: ...
When working with regular expressions one modifier for PCRE is g for global match. In R matching and replacement functions have two version: first match and global match: sub(pattern,replacement,text) will replace the first occurrence of pattern by replacement in text gsub(pattern,replace...
Running the command: grep sam someFile.txt When someFile.txt contains: fred 14 m foo sam 68 m bar christina 83 f baz bob 22 m qux Sam 41 m quux Will produce this output: sam 68 m bar
The logical NOT (!) operator performs logical negation on an expression. Syntax: !expression Returns: a Boolean. Description The logical NOT (!) operator performs logical negation on an expression. Boolean values simply get inverted: !true === false and !false === true. Non-boolean val...
dc is one of the oldest language on Unix. It is using the reverse polish notation, which means that you are first stacking numbers, then operations. For example 1+1 is written as 1 1+. To print an element from the top of the stack use command p echo '2 3 + p' | dc 5 or dc <<< '2 3...
It's often useful to combine multiple plot types in one graph (for example a Barplot next to a Scatterplot.) R makes this easy with the help of the functions par() and layout(). par() par uses the arguments mfrow or mfcol to create a matrix of nrows and ncols c(nrows, ncols) which will serve as a ...
All DATEs have a time component; however, it is customary to store dates which do not need to include time information with the hours/minutes/seconds set to zero (i.e. midnight). Use an ANSI DATE literal (using ISO 8601 Date format): SELECT DATE '2000-01-01' FROM DUAL; Convert it from a string ...
Convert it from a string literal using TO_DATE(): SELECT TO_DATE( '2000-01-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS' ) FROM DUAL; Or use a TIMESTAMP literal: CREATE TABLE date_table( date_value DATE ); INSERT INTO date_table ( date_value ) VALUES ( TIMESTAMP '2000-01-01 12:00:00' ); Oracl...

Page 159 of 826