Tutorial by Examples: ad

Today Fortran is mainly used for numerical computation. This very simple example illustrates the basic program structure to solve quadratic equations: program quadratic !a comment !should be present in every separate program unit implicit none real :: a, b, c real :: discriminant...
Suppose you have defined the following Person class: public class Person { String name; int age; public Person (int age, String name) { this.age = age; this.name = name; } } If you instantiate a new Person object: Person person = new Person(25, &qu...
File f = new File(path); String content = new Scanner(f).useDelimiter("\\Z").next(); \Z is the EOF (End of File) Symbol. When set as delimiter the Scanner will read the fill until the EOF Flag is reached.
If the items in your RecyclerView load data from the network (commonly images) or carry out other processing, that can take a significant amount of time and you may end up with items on-screen but not fully loaded. To avoid this you can extend the existing LinearLayoutManager to preload a number of...
Govendor is a tool that is used to import 3rd party packages into your code repository in a way that is compatible with golang's vendoring. Say for example that you are using a 3rd party package bosun.org/slog: package main import "bosun.org/slog" func main() { slog.Infof(&quo...
Method overloading, also known as function overloading, is the ability of a class to have multiple methods with the same name, granted that they differ in either number or type of arguments. Compiler checks method signature for method overloading. Method signature consists of three things - Met...
Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Sub ReadTextFileExample() Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") Dim sourceFile As Object Dim myFilePath As String Dim myFileText As String myFilePath = &...
A new thread separate from the main thread's execution, can be created using Thread.new. thr = Thread.new { sleep 1 # 1 second sleep of sub thread puts "Whats the big deal" } This will automatically start the execution of the new thread. To freeze execution of the main Thread, ...
SQLiteOpenHelper is a helper class to manage database creation and version management. In this class, the onUpgrade() method is responsible for upgrading the database when you make changes to the schema. It is called when the database file already exists, but its version is lower than the one spec...
ALTER TABLE Employees ADD CONSTRAINT DefaultSalary DEFAULT ((100)) FOR [Salary] This adds a constraint called DefaultSalary which specifies a default of 100 for the Salary column. A constraint can be added at the table level. Types of constraints Primary Key - prevents a duplicate record in...
slice1 := []string{"!"} slice2 := []string{"Hello", "world"} slice := append(slice1, slice2...) Run in the Go Playground
This type of Singleton is thread safe, and prevents unnecessary locking after the Singleton instance has been created. Java SE 5 public class MySingleton { // instance of class private static volatile MySingleton instance = null; // Private constructor private MySingleton()...
A simple program that writes "Hello, world!" to test.txt, reads back the data, and prints it out. Demonstrates simple file I/O operations. package main import ( "fmt" "io/ioutil" ) func main() { hello := []byte("Hello, world!") //...
Write the following command in your terminal: adb shell getprop This will print all available information in the form of key/value pairs. You can just read specific information by appending the name of a specific key to the command. For example: adb shell getprop ro.product.model Here are a...
While composer provides a system to manage dependencies for PHP projects (e.g. from Packagist), it can also notably serve as an autoloader, specifying where to look for specific namespaces or include generic function files. It starts with the composer.json file: { // ... "autoload&q...
Method GetCustomAttributes returns an array of custom attributes applied to the member. After retrieving this array you can search for one or more specific attributes. var attribute = typeof(MyClass).GetCustomAttributes().OfType<MyCustomAttribute>().Single(); Or iterate through them forea...
Hash has a default value for keys that are requested but don't exist (nil): a = {} p a[ :b ] # => nil When creating a new Hash, one can specify the default: b = Hash.new 'puppy' p b[ :b ] # => 'puppy' Hash.new also takes a block, which allows you to automatically create n...
Python 2.x2.6 The format() method can be used to change the alignment of the string. You have to do it with a format expression of the form :[fill_char][align_operator][width] where align_operator is one of: < forces the field to be left-aligned within width. > forces the field to be righ...
To add a new column name to the users table, run the command: rails generate migration AddNameToUsers name This generates the following migration: class AddNameToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :name, :string end end When the migration name i...
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...

Page 11 of 114