Tutorial by Examples

Default installation of R on Windows stored files (and thus library) on a dedicated folder per R version on program files. That means that by default, you would work with several versions of R in parallel and thus separate libraries. If this not what you want and you prefer to always work with a s...
When you show a location to your users, you might want the MKMapView to display a coordinate at a zoom-level instead of setting a region to show. This functionality is not implemented by default, so you need to extend MKMapView with a methods that do the complex calculation from a coordinate and zoo...
In Python 2, writing directly to a file handle returns None: Python 2.x2.3 hi = sys.stdout.write('hello world\n') # Out: hello world type(hi) # Out: <type 'NoneType'> In Python 3, writing to a handle will return the number of characters written when writing text, and the number of by...
Prerequisites Have Maven installed. Have an IDE installed such as Intellij, Eclipse, or NetBeans. Create a Maven project Create a Maven project with the standard project structure (i.e. Group ID as com.organization.app and Artifact ID as SpringBatchExample: SpringBatchExample |-- pom.xml ...
Setting up key value observing. In this case, we want to observe the contentOffset on an object that our observer owns // // Class to observe // @interface XYZScrollView: NSObject @property (nonatomic, assign) CGPoint contentOffset; @end @implementation XYZScrollView @end // // Clas...
Install module and read docs npm i formidable@latest Example of server on 8080 port var formidable = require('formidable'), http = require('http'), util = require('util'); http.createServer(function(req, res) { if (req.url == '/upload' && req.method.toLowerCase() == 'pos...
Interface: public interface FooService { public int doSomething(); } Class: @Service public class FooServiceImpl implements FooService { @Override public int doSomething() { //Do some stuff here return 0; } } It should be noted that a class must imple...
Often times you will need to be able to manage your notifications, by being able to keep track of them and cancel them. Track a notification You can assign a UUID (universally unique identifier) to a notification, so you can track it: Swift let notification = UILocalNotification() let uuid = NS...
public void iterate(final String dirPath) throws IOException { final DirectoryStream<Path> paths = Files.newDirectoryStream(Paths.get(dirPath)); for (final Path path : paths) { if (Files.isDirectory(path)) { System.out.println(path.getFileName()); } } ...
Each gem has a file in the format of <gem name>.gemspec which contains metadata about the gem and it's files. The format of a gemspec is as follows: Gem::Specification.new do |s| # Details about gem. They are added in the format: s.<detail name> = <detail value> end The ...
Once you have created your gem to publish it you have to follow a few steps: Build your gem with gem build <gem name>.gemspec (the gemspec file must exist) Create a RubyGems account if you do not already have one here Check to make sure that no gems exist that share your gems name Publis...
MY_CONSTANT = "Hello, world" # constant Constant = 'This is also constant' # constant my_variable = "Hello, venus" # not constatn Constant name start with capital letter. Everything that start with capital letter are considered as constant in Ruby. So class and module are al...
MY_CONSTANT = "Hello, world" MY_CONSTANT = "Hullo, world" The above code results in a warning, because you should be using variables if you want to change their values. However it is possible to change one letter at a time in a constant without a warning, like this: MY_CONST...
def say_hi MESSAGE = "Hello" puts MESSAGE end The above code results in an error: SyntaxError: (irb):2: dynamic constant assignment.
class Message DEFAULT_MESSAGE = "Hello, world" def speak(message = nil) if message puts message else puts DEFAULT_MESSAGE end end end The constant DEFAULT_MESSAGE can be changed with the following code: Message::DEFAULT_MESSAGE = "Hullo, wo...
Local variables (unlike the other variable classes) do not have any prefix local_variable = "local" p local_variable # => local Its scope is dependent on where it has been declared, it can not be used outside the "declaration containers" scope. For example, if a local va...
Class variables have a class wide scope, they can be declared anywhere in the class. A variable will be considered a class variable when prefixed with @@ class Dinosaur @@classification = "Like a Reptile, but like a bird" def self.classification @@classification ...
Global variables have a global scope and hence, can be used everywhere. Their scope is not dependent on where they are defined. A variable will be considered global, when prefixed with a $ sign. $i_am_global = "omg" class Dinosaur def instance_method p "global vars ca...
Instance variables have an object wide scope, they can be declared anywhere in the object, however an instance variable declared on class level, will only be visible in the class object. A variable will be considered an instance variable when prefixed with @. Instance variables are used to set and g...
def results = [] (1..4).each{ def what = (it%2) ? 'odd' : 'even' results << what } assert results == ['odd', 'even', 'odd', 'even'] Here, the if-condition (in (parentheses)) is slightly more complex than just testing for existence/Groovy-Truth.

Page 549 of 1336