Tutorial by Examples

Encapsulation is a basic concept in OOP. It is about wrapping data and code as a single unit. In this case, it is a good practice to declare the variables as private and then access them through Getters and Setters to view and/or modify them. public class Sample { private String name; privat...
1. Add Devise Gem Open up your Gemfile and add this line gem 'devise' Then run; bundle install 2. Set up devise in your app Run the following command in the terminal rails g devise:install 3. Configure Devise Ensure you have defined default url options in your environments files. Open...
In order to ssh into a server your identity's public key has to be added to the list of trusted keys. Most commonly this is done per-user: ssh-copy-id -i ~/.ssh/<identity>.pub <user>@<hostname> Which can be also done manually: cat ~/.ssh/<identity>.pub | ssh <user>...
import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; @Path("hello") public class HelloWorldResource { private String message = "Hello StackOverflow!"; @GET @Produces(&...
Coming from imperative languages many developers wonder how to write a for-loop that exits early as F# doesn't support break, continue or return. The answer in F# is to use tail-recursion which is a flexible and idiomatic way to iterate while still providing excellent performance. Say we want to ...
Many people don't make use of file.path when making path to a file. But if you are working across Windows, Mac and Linux machines it's usually good practice to use it for making paths instead of paste. FilePath <- file.path(AVariableWithFullProjectPath,"SomeSubfolder","SomeFileNam...
The following function is returning another function as its result which can be later assigned to a variable and called: func jediTrainer () -> ((String, Int) -> String) { func train(name: String, times: Int) -> (String) { return "\(name) has been trained in the Force \(times)...
Every function has its own function type, made up of the parameter types and the return type of the function itself. For example the following function: func sum(x: Int, y: Int) -> (result: Int) { return x + y } has a function type of: (Int, Int) -> (Int) Function types can thus be use...
Every object in R is assigned a class. You can use class() to find the object's class and str() to see its structure, including the classes it contains. For example: class(iris) [1] "data.frame" str(iris) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4...
Problem: When you use many labels inside a view, you maybe get a warning: How can we fix this warning? Solution: We calculate and set the priorities in order. The priorities must be different from labels. It means which is important will get higher priority. For example, in my case, I set the ve...
Step 1: In Xcode: File -> New -> File -> Resource -> GPX File -> Next -> Give the GPX file a name(It's Taipei in this example) -> Create Step 2: Edit the GPX file <?xml version="1.0"?> <gpx version="1.1" creator="Xcode"> <wpt ...
import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.Response; @Path("hello") public class HelloWorldResource { @POST @Path("/receiveParams") public Response receiveHello(@FormParam("name") String ...
Often in R you'll want to know things about an object or variable you're working with. This can be useful when reading someone else's code or even your own, especially when using packages that are new to you. Suppose we create a variable a: a <- matrix(1:9, 3, 3) What data type is this? Yo...
Often data comes in tables. Generally one can divide this tabular data in wide and long formats. In a wide format, each variable has its own column. PersonHeight [cm]Age [yr]Alison17820Bob17445Carl18231 However, sometimes it is more convenient to have a long format, in which all variables are in o...
Arrow is an elegant JSON parsing library in Swift. It allows to parse JSON and map it to custom model classes with help of an <-- operator: identifier <-- json["id"] name <-- json["name"] stats <-- json["stats"] Example: Swift model struct Profile {...
The Oracle Java Style Guide states: Modifiers should not be written out when they are implicit. (See Modifiers in Oracle Official Code Standard for the context and a link to the actual Oracle document.) This style guidance applies particularly to interfaces. Let's consider the following code ...
In this exercise, we will generate four bootstrap linear regression models and combine the summaries of these models into a single data frame. library(broom) #* Create the bootstrap data sets BootData <- lapply(1:4, function(i) mtcars[sample(1:nrow(mtcars), ...
This example shows how PLINQ can be used to calculate the even numbers between 1 and 10,000 using multiple threads. Note that the resulting list will won't be ordered! var sequence = Enumerable.Range(1, 10000); var evenNumbers = sequence.AsParallel() .Where(x => x % 2...
The degree of parallelism is the maximum number of concurrently executing tasks that will be used to process the query. var sequence = Enumerable.Range(1, 10000); var evenNumbers = sequence.AsParallel() .WithDegreeOfParallelism(4) .Where(x =&gt...
This example shows how PLINQ can be used to calculate the even numbers between 1 and 10,000 using multiple threads. Order will be maintained in the resulting list, however keep in mind that AsOrdered may hurt performance for a large numbers of elements, so un-ordered processing is preferred when pos...

Page 474 of 1336