The most common conditional in Julia is the if...else expression. For instance, below we implement the Euclidean algorithm for computing the greatest common divisor, using a conditional to handle the base case:
mygcd(a, b) = if a == 0
abs(b)
else
mygcd(b % a, a)
end
The if...else for...
A Mixin is a set of properties and methods that can be used in different classes, which don't come from a base class. In Object Oriented Programming languages, you typically use inheritance to give objects of different classes the same functionality; if a set of objects have some ability, you put th...
Here is a class (Dog) creating its own dependency (Food):
class Dog {
public Dog() {
var food = new Food();
this.eat(food);
}
}
Here is the same class being injected with its dependency using constructor injection:
class Dog {
public Dog(Food food) {
...
using System;
using System.IO;
public class Program
{
public static void Main()
{
string filePath = "somePath";
if(File.Exists(filePath))
{
Console.WriteLine("Exists");
}
else
...
$string = "a;b;c\nd;e;f";
// $1, $2 and $3 represent the first, second and third capturing groups
echo preg_replace("(^([^;]+);([^;]+);([^;]+)$)m", "$3;$2;$1", $string);
Outputs
c;b;a
f;e;d
Searches for everything between semicolons and reverses the order.
Polymorphism is one of the pillar of OOP. Poly derives from a Greek term which means 'multiple forms'.
Below is an example which exhibits Polymorphism. The class Vehicle takes multiple forms as a base class.
The Derived classes Ducati and Lamborghini inherits from Vehicle and overrides the base cl...
Pug (old name is Jade) is a clean, whitespace sensitive syntax for writing HTML. Here is a simple example:
doctype html
html(lang="en")
head
title= pageTitle
script(type='text/javascript').
if (foo) bar(1 + 5)
body
h1 Pug - node template engine
#container...
This example is about deliberately ignoring or "squashing" exceptions. Or to be more precise, it is about how to catch and handle an exception in a way that ignores it. However, before we describe how to do this, we should first point out that squashing exceptions is generally not the co...
This exception occurs when a collection is modified while iterating over it using methods other than those provided by the iterator object. For example, we have a list of hats and we want to remove all those that have ear flaps:
List<IHat> hats = new ArrayList<>();
hats.add(new Ushanka...
pip is your friend when you need to install any package from the plethora of choices available at the python package index (PyPI). pip is already installed if you're using Python 2 >= 2.7.9 or Python 3 >= 3.4 downloaded from python.org. For computers running Linux or another *nix with a native...
curl -XGET http://www.example.com:9200/myIndexName/_search?pretty=true&q=*:*
This uses the Search API and will return all the entries under index myIndexName.
Reference Link: Here
After Successfully installing Xamarin Studio on OS X.
It's time for the first Hello World Application.
Hello World Application: Xamarin.Forms
What is Xamarin Forms :
Xamarin.Forms is a new library that enables you to build native UIs for iOS, Android and Windows Phone from a single, shared C# c...
Specifies a numeric minimum and maximum range for a property
using System.ComponentModel.DataAnnotations;
public partial class Enrollment
{
public int EnrollmentID { get; set; }
[Range(0, 4)]
public Nullable<decimal> Grade { get; set; }
}
If we try to insert/upd...
public class Person
{
public int PersonID { get; set; }
public string PersonName { get; set; }
[Index]
public int Age { get; set; }
}
Creates a database index for a column or set of columns.
[Index("IX_Person_Age")]
public int Age { get; set; }
This creates ...
To find active ScriptableObjects during runtime, you can use Resources.FindObjectsOfTypeAll().
T[] instances = Resources.FindObjectsOfTypeAll<T>();
Where T is the type of the ScriptableObject instance you're searching. Active means it has been loaded in memory in some form before.
This me...
I create a file called database-servlet.xml somewhere on the classpath.
Initially your config file will look like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/...
UITextView has extra paddings by default. Sometimes it's annoying especially if you want to measure some text without view instance and place them at some area precisely.
Do this to remove such paddings.
messageTextView.textContainerInset = UIEdgeInsetsZero
messageTextView.textContainer.lineFragm...