Tutorial by Examples

Unfortunately as of C++14 there's no dynamic size matrix class in the C++ standard library. Matrix classes that support dynamic size are however available from a number of 3rd party libraries, including the Boost Matrix library (a sub-library within the Boost library). If you don't want a dependenc...
This is useful to see if there are any non-printable characters, or non-ASCII characters. e.g. If you have copy-pasted the code from web, you may have quotes like ” instead of standard ". $ cat -v file.txt $ cat -vE file.txt # Useful in detecting trailing spaces. e.g. $ echo '” ' | c...
Because in .NET 3.5 and older you don't have Lazy<T> class you use the following pattern: public class Singleton { private Singleton() // prevents public instantiation { } public static Singleton Instance { get { return Nested.instanc...
To create a new Rails 5 API, open a terminal and run the following command: rails new app_name --api The following file structure will be created: create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app create app/as...
RVM is a great tool to manage your ruby versions and set up your working environment. Assuming you already have RVM installed, to get the latest version of ruby, which is needed for these examples, open a terminal and run: $ rvm get stable $ rvm install ruby --latest Check your ruby version by...
All collection objects contain a map method that takes a Function as an argument, which must take a single argument. This returns an Iterable backed by the collection. When the Iterable is iterated, each step calls the function with a new element of the collection, and the result of the call becomes...
A typical singleton class : import javax.inject._ @Singleton class BurgersRepository { // implementation goes here } Another class, requiring access to the first one. import javax.inject._ class FastFoodService @Inject() (burgersRepository: BurgersRepository){ // implementation ...
You will often need to access instances of classes from the framework itself (like the WSClient, or the Configuration). You can inject them in your own classes : class ComplexService @Inject()( configuration: Configuration, wsClient: WSClient, applicationLifecycle: ApplicationLifecycle, ...
Basic usage of dependency injection is done by the annotations. When you need to tweak things a little bit, you need custom code to further specify how you want some classes to be instantiated and injected. This code goes in what is called a Module. import com.google.inject.AbstractModule // Pla...
PBKDF2 ("Password-Based Key Derivation Function 2") is one of the recommended hash-functions for password-hashing. It is part of rfc-2898. .NET's Rfc2898DeriveBytes-Class is based upon HMACSHA1. using System.Security.Cryptography; ... public const int SALT_SIZE = 24; //...
CanCan is a a popular authorization library for Ruby on Rails which restricts user access to specific resources. The latest gem (CanCanCan) is a continuation of the dead project CanCan. Permissions are defined in the Ability class and can be used from controllers, views, helpers, or any other place...
Abilities are defined in the Ability class using can and cannot methods. Consider the following commented example for basic reference: class Ability include CanCan::Ability def initialize(user) # for any visitor or user can :read, Article if user if user.admin? ...
Once the number of abilities definitions start to grow in number, it becomes more and more difficult to handle the Ability file. The first strategy to handle these issue is to move abilities into meaningful methods, as per this example: class Ability include CanCan::Ability def initialize(...
Will select records in TableName that have records matching in TableName1. SELECT * FROM TableName t WHERE EXISTS ( SELECT 1 FROM TableName1 t1 where t.Id = t1.Id)
mount is used to mount another application (basically rack application) or rails engines to be used within the current application syntax: mount SomeRackApp, at: "some_route" Now you can access above mounted application using route helper some_rack_app_path or some_rack_app_url. But ...
Step 1: Create the controller, set the delegate, and conform to the protocol //Swift class ImageUploadViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { let imagePickerController = UIImagePickerController() override func viewDi...
Build numberDescription15.0.4623.1001June 201415.0.4631.1001July 201415.0.4641.1001August 201415.0.4649.1001September 201415.0.4659.1001October 201415.0.4667.1000November 201415.0.4675.1000December 201415.0.4693.1001February 201515.0.4701.1001March 201515.0.4711.1000April 2015 (SP1 REQ)15.0.4719.100...
Although it's bad practice, it's possible to add multiple return statements in a exception handling block: public static int returnTest(int number){ try{ if(number%2 == 0) throw new Exception("Exception thrown"); else return x; } catch(Exception e){ ...
LISP and Scheme's greatest advantage over other mainstream programming language is their macro system. Unlike the C preprocessor and other macro languages, Scheme macros take parsed code as input and return expanded code as output. This is one of the applications of Scheme's “code is data” phrase, a...
In this example we want to create a class that will generate and output to console, a random number between a range of two integers which are passed as arguments during the initialization. public class SimpleRangeRandom implements Runnable { private int min; private int max; pr...

Page 391 of 1336