All values in Rust have exactly one owner. The owner is responsible for dropping that value when it goes out of scope, and is the only one who may move the ownership of the value. The owner of a value may give away references to it by letting other pieces of code borrow that value. At any given time...
All values in Rust have a lifetime. A value's lifetime spans the segment of code from the value is introduced to where it is moved, or the end of the containing scope
{
let x = String::from("hello"); // +
// ... :
let y = S...
Because generating documentation is based on markdown, you have to do 2 things :
1/ Write your doctest and make your doctest examples clear to improve readability (It is better to give a headline, like "examples" or "tests"). When you write your tests, do not forget to give 4 s...
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...
Specifies how the database generates values for the property. There are three possible values:
None specifies that the values are not generated by the database.
Identity specifies that the column is an identity column, which is typically used for integer primary keys.
Computed specifies that th...
By Code-First convention, Entity Framework creates a column for every public property that is of a supported data type and has both a getter and a setter. [NotMapped] annotation must be applied to any properties that we do NOT want a column in a database table for.
An example of a property that we ...
[Table("People")]
public class Person
{
public int PersonID { get; set; }
public string PersonName { get; set; }
}
Tells Entity Framework to use a specific table name instead of generating one (i.e. Person or Persons)
We can also specify a schema for the table using [T...
public class Person
{
public int PersonID { get; set; }
[Column("NameOfPerson")]
public string PersonName { get; set; }
}
Tells Entity Framework to use a specific column name instead using the name of the property. You can also specify the database data type a...
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...
Error handling is important but can make an elegant algorithm into a mess.
Railway Oriented Programming (ROP)
is used to make error handling elegant and composable.
Consider the simple function f:
let tryParse s =
let b, v = System.Int32.TryParse s
if b then Some v else None
let f (g : ...
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/...
One of the great things about Linq is that it is so easy to extend. You just need to create an extension method whose argument is IEnumerable<T>.
public namespace MyNamespace
{
public static class LinqExtensions
{
public static IEnumerable<List<T>> Batch<T&...
One of the easiest examples of using shared services is when we want to store some data from a given page of our application, and then get that data again but from another page.
One option could be to send that data as a parameter (for instance, if one page calls the other one) but if we want to us...
The following sqoop command will be used to import the data from RDBMS table into HBase table, if the table does not exists in HBase it will create a new table and import the data into this table
sqoop import \
--query 'select emp_id, emp_name, emp_sal from employee where $CONDITIONS' \
...
Anonymous class listener
Before Java 8, it’s very common that an anonymous class is used to handle click event of a JButton, as shown in the following code. This example shows how to implement an anonymous listener within the scope of btn.addActionListener.
JButton btn = new JButton("My Butto...
In Visual Studio go to your Solution Explorer then click on Project you will be adding model Right mouse. Choose ADO.NET Entity Data Model
Then choose Generate from database and click Next in next window click New Connection... and point to the database you want to generate model from (Could be M...
Sometimes you would like to change main WordPress query.
Filter pre_get_posts is the way to go.
For example using pre_get_posts you can tell main loop to show only 5 posts. Or to show posts only from one category, or excluding any category etc.
add_action( 'pre_get_posts', 'my_callback_function' ...