Tutorial by Examples: ad

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 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 ...
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);...
A popular form of data analysis is split-apply-combine, in which you split your data into groups, apply some sort of processing on each group, and then combine the results. Let's consider a data analysis where we want to obtain the two cars with the best miles per gallon (mpg) for each cylinder cou...
The latest SDK can be downloaded here The latest SDK libraries are also available on NuGet under Microsoft's official crmsdk account
Each migration should have an up() method and a down() method. The purpose of the up() method is to perform the required operations to put the database schema in its new state, and the purpose of the down() method is to reverse any operations performed by the up() method. Ensuring that the down() me...
type person = {Name: string; Age: int} with // Defines person record member this.print() = printfn "%s, %i" this.Name this.Age let user = {Name = "John Doe"; Age = 27} // creates a new person user.print() // John Doe, 27
Given this setup code: var dict = new Dictionary<int, string>() { { 1, "First" }, { 2, "Second" }, { 3, "Third" } }; You may want to read the value for the entry with key 1. If key doesn't exist getting a value will throw KeyNotFoundException,...
The module cmath includes additional functions to use complex numbers. import cmath This module can calculate the phase of a complex number, in radians: z = 2+3j # A complex number cmath.phase(z) # 0.982793723247329 It allows the conversion between the cartesian (rectangular) and polar repr...
function Invoke-MyCmdlet { [CmdletBinding(SupportsShouldProcess = $true)] param() # ... }
class Person { [string] $Name [int] $Age Person([string] $Name) { $this.Name = $Name } Person([string] $Name, [int]$Age) { $this.Name = $Name $this.Age = $Age } }
Reading a file line by line public class Main { public static void main(String[] args) { try { Scanner scanner = new Scanner(new File("example.txt")); while(scanner.hasNextLine()) { String line = scanner.nextLine(); ...
DT[where, select|update|do, by] syntax is used to work with columns of a data.table. The "where" part is the i argument The "select|update|do" part is the j argument These two arguments are usually passed by position instead of by name. Our example data below is mtcars =...
<PROJECT_ROOT>\app\build.gradle is specific for app module. <PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules. If you use another module in your project, as a local library you would have another...
Java SE 8 An array of strings can be joined using the static method String.join(): String[] elements = { "foo", "bar", "foobar" }; String singleString = String.join(" + ", elements); System.out.println(singleString); // Prints "foo + bar + foobar&qu...
Swift label1.layer.shadowOffset = CGSize(width: 3, height: 3) label1.layer.shadowOpacity = 0.7 label1.layer.shadowRadius = 2 Swift 3 label1.layer.shadowOffset = CGSize(width: 3, height: 3) label1.layer.shadowOpacity = 0.7 label1.layer.shadowRadius = 2 Objective-C label1.layer.shadowOffs...
Assuming you created the serial port object s as in this example, then % Read one byte data = fread(s, 1); % Read all the bytes, version 1 data = fread(s); % Read all the bytes, version 2 data = fread(s, s.BytesAvailable); % Close the serial port fclose(s);
As there is currently no simple way of combining dictionaries in Swift, it can be useful to overload the + and += operators in order to add this functionality using generics. // Combines two dictionaries together. If both dictionaries contain // the same key, the value of the right hand side dicti...
// View to hold the CAGradientLayer. let view: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 320)) // Initialize gradient layer. let gradientLayer: CAGradientLayer = CAGradientLayer() // Set frame of gradient layer. gradientLayer.frame = view.bounds // Color at...

Page 12 of 114