The class we are going to test is:
public class Service {
private Collaborator collaborator;
public Service(Collaborator collaborator) {
this.collaborator = collaborator;
}
public String performService(String input) {
return collaborator.transformStri...
Enumerable is the most popular module in Ruby. Its purpose is to provide you with iterable methods like map, select, reduce, etc. Classes that use Enumerable include Array, Hash, Range.
To use it, you have to include Enumerable and implement each.
class NaturalNumbers
include Enumerable
de...
The following prints the message Hello, World! to console
public void hello() {
Observable.just("Hello, World!") // create new observable
.subscribe(new Action1<String>() { // subscribe and perform action
@Override
public void call(String st) {
Sy...
Comparable is one of the most popular modules in Ruby. Its purpose is to provide with convenience comparison methods.
To use it, you have to include Comparable and define the space-ship operator (<=>):
class Rectangle
include Comparable
def initialize(a, b)
@a = a
@b = b
...
DELETE FROM `table_name` WHERE `field_one` = 'value_one'
This will delete all rows from the table where the contents of the field_one for that row match 'value_one'
The WHERE clause works in the same way as a select, so things like >, <, <> or LIKE can be used.
Notice: It is necessa...
DELETE FROM table_name ;
This will delete everything, all rows from the table. It is the most basic example of the syntax. It also shows that DELETE statements should really be used with extra care as they may empty a table, if the WHERE clause is omitted.
DELETE FROM `table_name` WHERE `field_one` = 'value_one' LIMIT 1
This works in the same way as the 'Delete with Where clause' example, but it will stop the deletion once the limited number of rows have been removed.
If you are limiting rows for deletion like this, be aware that it will delete th...
Statement-level parallel hints are the easiest:
SELECT /*+ PARALLEL(8) */ first_name, last_name FROM employee emp;
Object-level parallel hints give more control but are more prone to errors; developers often forget to use the alias instead of the object name, or they forget to include some objec...
In C#, there are two different kinds of equality: reference equality and value equality. Value equality is the commonly understood meaning of equality: it means that two objects contain the same values. For example, two integers with the value of 2 have value equality. Reference equality means that ...
There are few approaches available there:
You can subscribe for keyboard appearance events notifications and change offset manually:
//Swift 2.0+
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourVCClas...
Controller class names are pluralized. The reason is the controller controls multiple instances of object instance.
For Example: OrdersController would be the controller for an orders table. Rails will then look for the class definition in a file called orders_controller.rb in the /app/controllers ...
The model is named using the class naming convention of unbroken MixedCase and is always the singular of the table name.
For Example: If a table was named orders, the associated model would be named Order
For Example: If a table was named posts, the associated model would be named Post
Rails will...
Common usage of lock is a critical section.
In the following example ReserveRoom is supposed to be called from different threads. Synchronization with lock is the simplest way to prevent race condition here. Method body is surrounded with lock which ensures that two or more threads cannot execute i...
Private inheritance is useful when it is required to restrict the public interface of the class:
class A {
public:
int move();
int turn();
};
class B : private A {
public:
using A::turn;
};
B b;
b.move(); // compile error
b.turn(); // OK
This approach efficiently pr...
If you have an existing class that you'd like to use, perform Step 2 and then skip to Step 5. (For some cases, I had to add an explicit #import <Foundation/Foundation.h to an older ObjC File)
Step 1: Add Objective-C Implementation -- .m
Add a .m file to your class, and name it CustomObje...
Step 1: Create New Swift Class
Add a .swift file to your project, and name it MySwiftObject.swift
In MySwiftObject.swift:
import Foundation
class MySwiftObject : NSObject {
var someProperty: AnyObject = "Some Initializer Val"
init() {}
func someFunction(someArg...
app/assets/javascripts/channels/notifications.coffee
App.notifications = App.cable.subscriptions.create "NotificationsChannel",
connected: ->
# Called when the subscription is ready for use on the server
$(document).on "change", "input", (e)=>
...
Java-like enumerations can be created by extending Enumeration.
object WeekDays extends Enumeration {
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
def isWeekend(day: WeekDays.Value): Boolean = day match {
case WeekDays.Sat | WeekDays.Sun => true
case _ => false
}
isWeekend...
An alternative to extending Enumeration is using sealed case objects:
sealed trait WeekDay
object WeekDay {
case object Mon extends WeekDay
case object Tue extends WeekDay
case object Wed extends WeekDay
case object Thu extends WeekDay
case object Fri extends WeekDay
case objec...