PresenceOf - Validates that a value is not null or empty string
$validator->add('name', new \Phalcon\Validation\Validator\PresenceOf([
'message' => 'The name is required'
]));
Email - Checks if a value has a correct e-mail format
$validator->add('email', new \Phalcon\Validation\Va...
2.1.3
1. Preview Different Devices
There is a preview panel at the right of the android studio. In thispanel there is a button with device name with which you are previewing the UI of your app like this .
Click on small dropdown indicator of this and a floating panel will appear with all the pr...
VB 14.0 introduces the ability to add comments after implicit line continuation.
Dim number =
From c As Char 'Comment
In "dj58kwd92n4" 'Comment
Where Char.IsNumber(c) 'Comment
Select c 'Comment
It forces you to explicitly declare all variables.
What is the difference between explicitly declaring and implicitly declaring a variable?
Explicitly declaring a variable:
Dim anInteger As Integer = 1234
Implicitly declaring a variable:
'Did not declare aNumber using Dim
aNumber = 1234
C...
String Concatenation can be done by using the System.String.Concat method, or (much easier) using the + operator:
string first = "Hello ";
string second = "World";
string concat = first + second; // concat = "Hello World"
concat = String.Concat(first, second); // ...
Add the following code to the onCreate()/onResume() method:
SensorManager sensorManager;
Sensor mAccelerometer;
final float movementThreshold = 0.5f; // You may have to change this value.
boolean isMoving = false;
float[] prevValues = {1.0f, 1.0f, 1.0f};
float[] currValues = new float[3];
...
Consider the following code as an illustration:
public String joinWords(List<String> words) {
String message = "";
for (String word : words) {
message = message + " " + word;
}
return message;
}
Unfortunate this code is inefficient if the w...
6.0
Default SET format is MMDDhhmm[[CC]YY][.ss], that's (2 digits each)
For example, to set July 17'th 10:10am, without changing the current year, type:
adb shell 'date 07171010.00'
Tip 1: the date change will not be reflected immediately, and a noticable change will happen only after the syst...
com.android.dex.DexException: Multiple dex files define Lcom/example/lib/Class;
This error occurs because the app, when packaging, finds two .dex files that define the same set of methods.
Usually this happens because the app has accidentally acquired 2 separate dependencies on the same library....
By default:
Use val, not var, wherever possible. This allows you to take seamless advantage of a number of functional utilities, including work distribution.
Use recursion and comprehensionss, not loops.
Use immutable collections. This is a corrolary to using val whenever possible.
Focus on da...
Say we have Products and Categorys in a many-to-many relationship:
public class Product
{
public Product()
{
Categories = new HashSet<Category>();
}
public int ProductId { get; set; }
public string ProductName { get; set; }
public virtual ICollection<...
Pressing C-h a will run the emacs function apropos-command which makes emacs prompt for words (or a regexp) to search for. It will then show a buffer containing a list of names and descriptions related to that topic, including key bindings for each of the functions available via keystrokes.
Pressin...
C-h k runs the function describe-key, which looks up the function mapped to the key strokes provided, and presents a description of the function which will be run when these keys are pressed.
C-h c runs the function describe-key-briefly, which only displays the function name mapped to given key seq...
C-h f runs the function describe-function, which displays information on the usage and purpose of a given function. This is especially useful for functions that do not have a mapped key binding that can be used for documentation lookup via C-h k.
Another powerful & mature concurrency tool in Haskell is Software Transactional Memory, which allows for multiple threads to write to a single variable of type TVar a in an atomic manner.
TVar a is the main type associated with the STM monad and stands for transactional variable. They're used m...
Zip two arrays into an array of pairs:
Prelude Data.Vector> Data.Vector.zip y y
fromList [(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11)] :: Data.Vector.Vector
Intersection of Hashes
To get the intersection of two hashes, return the shared keys the values of which are equal:
hash1 = { :a => 1, :b => 2 }
hash2 = { :b => 2, :c => 3 }
hash1.select { |k, v| (hash2.include?(k) && hash2[k] == v) } # => { :b => 2 }
Union (...
These rules apply only if you use manual reference counting!
You own any object you create
By calling a method whose name begins with alloc, new, copy or mutableCopy.
For example:
NSObject *object1 = [[NSObject alloc] init];
NSObject *object2 = [NSObject new];
NSObject *object3 = [object2 ...
Here is a quick example of using multiple forms in one Django view.
from django.contrib import messages
from django.views.generic import TemplateView
from .forms import AddPostForm, AddCommentForm
from .models import Comment
class AddCommentView(TemplateView):
post_form_class = AddPo...