Tutorial by Examples: and

To conditionally include a block of code, the preprocessor has several directives (e.g #if, #ifdef, #else, #endif, etc). /* Defines a conditional `printf` macro, which only prints if `DEBUG` * has been defined */ #ifdef DEBUG #define DLOG(x) (printf(x)) #else #define DLOG(x) #endif Norm...
Swift's built-in numeric types are: Word-sized (architecture-dependent) signed Int and unsigned UInt. Fixed-size signed integers Int8, Int16, Int32, Int64, and unsigned integers UInt8, UInt16, UInt32, UInt64. Floating-point types Float32/Float, Float64/Double, and Float80 (x86-only). Literal...
Indexes can have several characteristics that can be set either at creation, or by altering existing indexes. CREATE CLUSTERED INDEX ix_clust_employee_id ON Employees(EmployeeId, Email); The above SQL statement creates a new clustered index on Employees. Clustered indexes are indexes that dict...
Classes can define properties that instances of the class can use. In this example, Dog has two properties: name and dogYearAge: class Dog { var name = "" var dogYearAge = 0 } You can access the properties with dot syntax: let dog = Dog() print(dog.name) print(dog.dogYear...
WScript.Echo "Hello world!" This displays a message on the console if run with cscript.exe (the console host) or in a message box if run with wscript.exe (the GUI host). If you're using VBScript as the server-side scripting language for a web page (for classic ASP, for example), Respo...
In MATLAB, the most basic data type is the numeric array. It can be a scalar, a 1-D vector, a 2-D matrix, or an N-D multidimensional array. % a 1-by-1 scalar value x = 1; To create a row vector, enter the elements inside brackets, separated by spaces or commas: % a 1-by-4 row vector v = [1, 2...
When working with dictionaries, it's often necessary to access all the keys and values in the dictionary, either in a for loop, a list comprehension, or just as a plain list. Given a dictionary like: mydict = { 'a': '1', 'b': '2' } You can get a list of keys using the keys() method: ...
Optionals must be unwrapped before they can be used in most expressions. if let is an optional binding, which succeeds if the optional value was not nil: let num: Int? = 10 // or: let num: Int? = nil if let unwrappedNum = num { // num has type Int?; unwrappedNum has type Int print(&quo...
To allow the use of in for custom classes the class must either provide the magic method __contains__ or, failing that, an __iter__-method. Suppose you have a class containing a list of lists: class ListList: def __init__(self, value): self.value = value # Create a set of al...
alist = [1, 2, 3, 4, 1, 2, 1, 3, 4] alist.count(1) # Out: 3 atuple = ('bear', 'weasel', 'bear', 'frog') atuple.count('bear') # Out: 2 atuple.count('fox') # Out: 0
class MultiIndexingList: def __init__(self, value): self.value = value def __repr__(self): return repr(self.value) def __getitem__(self, item): if isinstance(item, (int, slice)): return self.__class__(self.value[item]) r...
Import the ElementTree object, open the relevant .xml file and get the root tag: import xml.etree.ElementTree as ET tree = ET.parse("yourXMLfile.xml") root = tree.getroot() There are a few ways to search through the tree. First is by iteration: for child in root: print(child.ta...
(Note: All examples using let are also valid for const) var is available in all versions of JavaScript, while let and const are part of ECMAScript 6 and only available in some newer browsers. var is scoped to the containing function or the global space, depending when it is declared: var x = 4; /...
Final classes When used in a class declaration, the final modifier prevents other classes from being declared that extend the class. A final class is a "leaf" class in the inheritance class hierarchy. // This declares a final class final class MyFinalClass { /* some code */ } ...
# Set the repository for the scope "myscope" npm config set @myscope:registry http://registry.corporation.com # Login at a repository and associate it with the scope "myscope" npm adduser --registry=http://registry.corporation.com --scope=@myscope # Install a package &quo...
project/jni/main.c #include <stdio.h> #include <unistd.h> int main(void) { printf("Hello world!\n"); return 0; } project/jni/Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello_world LOCAL_SRC_FILES := main.c include $(BU...
To create a new branch, while staying on the current branch, use: git branch <name> Generally, the branch name must not contain spaces and is subject to other specifications listed here. To switch to an existing branch : git checkout <name> To create a new branch and switch to it...
jQuery code is often wrapped in jQuery(function($) { ... }); so that it only runs after the DOM has finished loading. <script type="text/javascript"> jQuery(function($) { // this will set the div's text to "Hello". $("#myDiv").text("Hello"...
These are all equivalent, the code inside the blocks will run when the document is ready: $(function() { // code }); $().ready(function() { // code }); $(document).ready(function() { // code }); Because these are equivalent the first is the recommended form, the following is a ...
var='0123456789abcdef' # Define a zero-based offset $ printf '%s\n' "${var:3}" 3456789abcdef # Offset and length of substring $ printf '%s\n' "${var:3:4}" 3456 4.2 # Negative length counts from the end of the string $ printf '%s\n' "${var:3:-5}" 3456789a...

Page 8 of 153