The shift operators allow programmers to adjust an integer by shifting all of its bits to the left or the right. The following diagram shows the affect of shifting a value to the left by one digit.
Left-Shift
uint value = 15; // 00001111
uint doubled = value << 1; // Resu...
Within a catch block the throw keyword can be used on its own, without specifying an exception value, to rethrow the exception which was just caught. Rethrowing an exception allows the original exception to continue up the exception handling chain, preserving its call stack or associated data:
try...
You can use the CONVERT function to cast a datetime datatype to a formatted string.
SELECT GETDATE() AS [Result] -- 2016-07-21 07:56:10.927
You can also use some built-in codes to convert into a specific format. Here are the options built into SQL Server:
DECLARE @convert_code INT = 100 -- See ...
A Sub is a procedure that performs a specific task but does not return a specific value.
Sub ProcedureName ([argument_list])
[statements]
End Sub
If no access modifier is specified, a procedure is Public by default.
A Function is a procedure that is given data and returns a value, ideally...
Slices are the typical way go programmers store lists of data.
To declare a slice variable use the []Type syntax.
var a []int
To declare and initialize a slice variable in one line use the []Type{values} syntax.
var a []int = []int{3, 1, 4, 1, 5, 9}
Another way to initialize a slice is with...
Define your class that will represent your custom error.
public class ErrorDto
{
public int Code { get; set; }
public string Message { get; set; }
// other fields
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
Then put nex...
A shell script is a very versatile way to extend your build to basically anything you can think of.
As an exmaple, here is a simple script to compile protobuf files and add the result java files to the source directory for further compilation:
def compilePb() {
exec {
// NOTICE: grad...
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.transformS...
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 core concepts of RxJava are its Observables and Subscribers. An Observable emits objects, while a Subscriber consumes them.
Observable
Observable is a class that implements the reactive design pattern. These Observables provide methods that allow consumers to subscribe to event changes. The ev...
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...
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...
To show some content in a new window, a Stage needs to be created. After creation and initialisation show or showAndWait needs to be called on the Stage object:
// create sample content
Rectangle rect = new Rectangle(100, 100, 200, 300);
Pane root = new Pane(rect);
root.setPrefSize(500, 500);
...
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...
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...
Creating a Snackbar can be done as follows:
Snackbar.make(view, "Text to display", Snackbar.LENGTH_LONG).show();
The view is used to find a suitable parent to use to display the Snackbar. Typically this would be a CoordinatorLayout that you've defined in your XML, which enables adding ...
The String List passed as a parameter to the share() method contains the paths of all the files you want to share.
It basically loops through the paths, adds them to Uri, and starts the Activity which can accept Files of this type.
public static void share(AppCompatActivity context,List<Strin...
Functions can either be named or unnamed (anonymous functions):
var namedSum = function sum (a, b) { // named
return a + b;
}
var anonSum = function (a, b) { // anonymous
return a + b;
}
namedSum(1, 3);
anonSum(1, 3);
4
4
But their names are private to their own scope:
...