Tutorial by Examples: c

To add a new indexed column email to the users table, run the command: rails generate migration AddEmailToUsers email:string:index This will generate the following migration: class AddEmailToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :email, :string add_i...
To remove existing column name from users table, run the command: rails generate migration RemoveNameFromUsers name:string This will generate the following migration: class RemoveNameFromUsers < ActiveRecord::Migration[5.0] def change remove_column :users, :name, :string end end ...
To add a reference to a team to the users table, run this command: $ rails generate migration AddTeamRefToUsers team:references This generates the following migration: class AddTeamRefToUsers < ActiveRecord::Migration[5.0] def change add_reference :users, :team, foreign_key: true ...
To create a new users table with the columns name and salary, run the command: rails generate migration CreateUsers name:string salary:decimal This will generate the following migration: class CreateUsers < ActiveRecord::Migration[5.0] def change create_table :users do |t| t.s...
To add multiple columns to a table, separate field:type pairs with spaces when using rails generate migration command. The general syntax is: rails generate migration NAME [field[:type][:index] field[:type][:index]] [options] For example, the following will add name, salary and email fields to ...
To rollback the latest migration, either by reverting the change method or by running the down method. Run command: 5.0 rake db:rollback 5.0 rails db:rollback Rollback the last 3 migrations 5.0 rake db:rollback STEP=3 5.0 rails db:rollback STEP=3 STEP provide the number of ...
To broaden the selections of a structured query language (SQL-SELECT) statement, wildcard characters, the percent sign (%) and the underscore (_), can be used. The _ (underscore) character can be used as a wildcard for any single character in a pattern match. Find all employees whose Fname start w...
Match any single character within the specified range (e.g.: [a-f]) or set (e.g.: [abcdef]). This range pattern would match "gary" but not "mary": SELECT * FROM Employees WHERE FName LIKE '[a-g]ary' This set pattern would match "mary" but not "gary": SEL...
Use the : operator to create sequences of numbers, such as for use in vectorizing larger chunks of your code: x <- 1:5 x ## [1] 1 2 3 4 5 This works both ways 10:4 # [1] 10 9 8 7 6 5 4 and even with floating point numbers 1.25:5 # [1] 1.25 2.25 3.25 4.25 or negatives -4:4 ...
Say you want to perform in action (in this case, logging "Foo"), while doing something else (logging "Bar"). Normally, if you don't use concurrency, one of these actions is going to be fully executed, and the other run will run only after it's completely finished. But with concur...
From the official documentation: With Gradle: repositories { mavenCentral() // jcenter() works as well because it pulls from Maven Central } dependencies { compile 'com.github.bumptech.glide:glide:4.0.0' compile 'com.android.support:support-v4:25.3.1' annotationProcessor 'com.githu...
The services lifecycle has the following callbacks onCreate() : Executed when the service is first created in order to set up the initial configurations you might need. This method is executed only if the service is not already running. onStartCommand() : Executed every time startService...
Ruby uses the case keyword for switch statements. As per the Ruby Docs: Case statements consist of an optional condition, which is in the position of an argument to case, and zero or more when clauses. The first when clause to match the condition (or to evaluate to Boolean truth, if the condi...
You can create a new class that inherits from HashSet: Set<String> h = new HashSet<String>() {{ add("a"); add("b"); }}; One line solution: Set<String> h = new HashSet<String>(Arrays.asList("a", "b")); Using guava: Se...
A method of a struct that change the value of the struct itself must be prefixed with the mutating keyword struct Counter { private var value = 0 mutating func next() { value += 1 } } When you can use mutating methods The mutating methods are only available on str...
// Execute a command a capture standard out. exec.Command creates the command // and then the chained Output method gets standard out. Use CombinedOutput() // if you want both standard out and standerr output out, err := exec.Command("echo", "foo").Output() if err != nil { ...
cmd := exec.Command("sleep", "5") // Does not wait for command to complete before returning err := cmd.Start() if err != nil { log.Fatal(err) } // Wait for cmd to Return err = cmd.Wait() log.Printf("Command finished with error: %v", err)
Generally, the syntax is: SELECT <column names> FROM <table name> WHERE <condition> For example: SELECT FirstName, Age FROM Users WHERE LastName = 'Smith' Conditions can be complex: SELECT FirstName, Age FROM Users WHERE LastName = 'Smith' AND (City = 'New York' OR C...
A header file may be included by other header files. A source file (compilation unit) that includes multiple headers may therefore, indirectly, include some headers more than once. If such a header file that is included more than once contains definitions, the compiler (after preprocessing) dete...
In a nutshell, conditional pre-processing logic is about making code-logic available or unavailable for compilation using macro definitions. Three prominent use-cases are: different app profiles (e.g. debug, release, testing, optimised) that can be candidates of the same app (e.g. with extra log...

Page 81 of 826