Tutorial by Examples

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 ...
Run command: 5.0 rake db:migrate 5.0 rails db:migrate Specifying target version will run the required migrations (up, down, change) until it has reached the specified version. Here, version number is the numerical prefix on the migration's filename. 5.0 rake db:migrate VERSION=2008090...
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...
ImageView To load an image from a specified URL, Uri, resource id, or any other model into an ImageView: ImageView imageView = (ImageView) findViewById(R.id.imageView); String yourUrl = "http://www.yoururl.com/image.png"; Glide.with(context) .load(yourUrl) .into(imageView);...
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...
In short: XPages is part of IBM Domino Designer. Extra setup or installation isn't required for XPages. First XPage / Hello-World-Example To create your first XPage you have to create a new NSF first. Open the IBM Domino Designer, and open the menu "File" -> "New" -> &...
To control your database in Laravel is by using migrations. Create migration with artisan: php artisan make:migration create_first_table --create=first_table This will generate the class CreateFirstTable. Inside the up method you can create your columns: <?php use Illuminate\Database\Sche...
Create a simple table create table MY_table ( what varchar2(10), who varchar2(10), mark varchar2(10) ); Insert values (you can omit target columns if you provide values for all columns) insert into my_table (what, who, mark) values ('Hello', 'world', '!' ); insert into my_table ...
One of ColdFusion's strengths is how easy it is to work with databases. And of course, query inputs can and should be parameterized. Tag Implementation <cfquery name="myQuery" datasource="myDatasource" result="myResult"> select firstName, lastName from...
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...
Variables inside single quotes ' don't get expanded by POSIX compatible shells, so using a shell variable in a sed substitution requires the use of double quotes " instead of single quotes ': $ var="he" $ echo "hello" | sed "s/$var/XX/" XXllo $ var="he&q...

Page 132 of 1336