Tutorial by Examples

C++11 // Include sequence containers #include <vector> #include <deque> #include <list> #include <array> #include <forward_list> // Include sorting algorithm #include <algorithm> class Base { public: // Constructor that set variable to the va...
To add a new unique column email to users, run the following command: rails generate migration AddEmailToUsers email:string:uniq This will create the following migration: class AddEmailToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :email, :string add_index...
BigInteger is in an immutable object, so you need to assign the results of any mathematical operation, to a new BigInteger instance. Addition: 10 + 10 = 20 BigInteger value1 = new BigInteger("10"); BigInteger value2 = new BigInteger("10"); BigInteger sum = value1.add(value...
Model with ForeignKey We will work with these models : from django.db import models class Book(models.Model): name= models.CharField(max_length=50) author = models.ForeignKey(Author) class Author(models.Model): name = models.CharField(max_length=50) Suppose we often (always) access ...
You can access each property that belongs to an object with this loop for (var property in object) { // always check if an object has a property if (object.hasOwnProperty(property)) { // do stuff } } You should include the additional check for hasOwnProperty because an o...
It is undefined behavior to access an index that is out of bounds for an array (or standard library container for that matter, as they are all implemented using a raw array): int array[] = {1, 2, 3, 4, 5}; array[5] = 0; // Undefined behavior It is allowed to have a pointer pointing to the en...
pip may be used to install BeautifulSoup. To install Version 4 of BeautifulSoup, run the command: pip install beautifulsoup4 Be aware that the package name is beautifulsoup4 instead of beautifulsoup, the latter name stands for old release, see old beautifulsoup
Here is an example class which has a couple of instance variables, without using properties: @interface TestClass : NSObject { NSString *_someString; int _someInt; } -(NSString *)someString; -(void)setSomeString:(NSString *)newString; -(int)someInt; -(void)setSomeInt:(NSString *)...
The default property getters and setters can be overridden: @interface TestClass @property NSString *someString; @end @implementation TestClass // override the setter to print a message - (void)setSomeString:(NSString *)newString { NSLog(@"Setting someString to %@", newS...
Assuming a source file of hello_world.v and a top level module of hello_world. The code can be run using various simulators. Most simulators are compiled simulators. They require multiple steps to compile and execute. Generally the First step is to compile the Verilog design. Second step is to ...
The program outputs Hello World! to standard output. module HELLO_WORLD(); // module doesn't have input or outputs initial begin $display("Hello World"); $finish; // stop the simulator end endmodule Module is a basic building block in Verilog. It represent a collection...
The syntax for Java generics bounded wildcards, representing the unknown type by ? is: ? extends T represents an upper bounded wildcard. The unknown type represents a type that must be a subtype of T, or type T itself. ? super T represents a lower bounded wildcard. The unknown type repres...
A belongs_to association sets up a one-to-one connection with another model, so each instance of the declaring model "belongs to" one instance of the other model. For example, if your application includes users and posts, and each post can be assigned to exactly one user, you'd declare th...
A has_one association sets up a one-to-one connection with another model, but with different semantics. This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each user in your application has only one account, you'd declare the...
A has_many association indicates a one-to-many connection with another model. This association generally is located on the other side of a belongs_to association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application ...
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) print(df) # Output: # A B # 0 1 4 # 1 2 5 # 2 3 6 Directly assign df['C'] = [7, 8, 9] print(df) # Output: # A B C # 0 1 4 7 # 1 2 5 8 # 2 3 6 9 Add a constant column df['C'] = 1 print(df) # Ou...
For programmers coming from GCC or Clang to Visual Studio, or programmers more comfortable with the command line in general, you can use the Visual C++ compiler from the command line as well as the IDE. If you desire to compile your code from the command line in Visual Studio, you first need to set...
When using labels, both the start and the stop are included in the results. import pandas as pd import numpy as np np.random.seed(5) df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"), index = ["R" + str(i) for i in range(5)]) ...
DataFrame: import pandas as pd import numpy as np np.random.seed(5) df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"), index = ["R" + str(i) for i in range(5)]) df Out[12]: A B C D E R0 99 78 61 16 73...
Group by one column Using the following DataFrame df = pd.DataFrame({'A': ['a', 'b', 'c', 'a', 'b', 'b'], 'B': [2, 8, 1, 4, 3, 8], 'C': [102, 98, 107, 104, 115, 87]}) df # Output: # A B C # 0 a 2 102 # 1 b 8 98 # 2 c 1 107 # 3 a...

Page 224 of 1336