If you have nested lists, it is desireable to clone the nested lists as well. This action is called deep copy.
>>> import copy
>>> c = [[1,2]]
>>> d = copy.deepcopy(c)
>>> c is d
False
>>> c[0] is d[0]
False
You can create shallow copies of lists using slices.
>>> l1 = [1,2,3]
>>> l2 = l1[:] # Perform the shallow copy.
>>> l2
[1,2,3]
>>> l1 is l2
False
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...
For-loops iterate over an iterating collection. An iterating collection is any class which structurally unifies with Iterator<T> or Iterable<T> types from the Haxe standard library.
A for-loop which logs numbers in range 0 to 10 (exclusive) can be written as follows:
for (i in 0...10) ...
Pre -Requsite:
Download Visual Studio IDE
Create a new project
Install specflow visual studio integration, Nunit Adapter & Nunit framework
Download specflow for visual studio as shown below
All we need to do is to use set() method of $query object.
It takes two arguments, first what we want to set and second what value to set.
add_action( 'pre_get_posts', 'change_posts_per_page' );
function change_posts_per_page( $query ) {
if( !$query->is_main_query() || is_admin() ) retu...
Haskell supports many forms of concurrency and the most obvious being forking a thread using forkIO.
The function forkIO :: IO () -> IO ThreadId takes an IO action and returns its ThreadId, meanwhile the action will be run in the background.
We can demonstrate this quite succinctly using ghci:
...
The angular.forEach accepts an object and an iterator function. It then runs the iterator function over each enumerable property/value of the object. This function also works on arrays.
Like the JS version of Array.prototype.forEach The function does not iterate over inherited properties (prototype...
Formatting a JavaScript date in modern browsers
In modern browsers (*), Date.prototype.toLocaleDateString() allows you to define the formatting of a Date in a convenient manner.
It requires the following format :
dateObj.toLocaleDateString([locales [, options]])
The locales parameter should be...
A form gives the user a way to change data in your application, in a structured way. To mutate a simple array of data, we create a form using a form builder:
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\F...
A custom form type is a class which defines a reusable form component. Custom form components can be nested to create complicated forms.
Instead of creating a form in the controller using a form builder, you can use your own type to make the code more readable, reusable and maintanable.
Create a c...
You can test for IndexedDB support in the current environment by checking for the presence of the window.indexedDB property:
if (window.indexedDB) {
// IndexedDB is available
}
Specifies custom foreign key name if a foreign key not following EF's convention is desired.
public class Person
{
public int IdAddress { get; set; }
[ForeignKey(nameof(IdAddress))]
public virtual Address HomeAddress { get; set; }
}
This can also be used when you have multipl...
Create this class :
public class InputFilterMinMax implements InputFilter {
private int min, max;
public InputFilterMinMax(int min, int max) {
this.min = min;
this.max = max;
}
public InputFilterMinMax(String min, String max) {
this.min = Integer...
You can use the following code for going back and forward.
if (!function_exists('codepoint_encode')) {
function codepoint_encode($str) {
return substr(json_encode($str), 1, -1);
}
}
if (!function_exists('codepoint_decode')) {
function codepoint_decode($str) {
re...
Each resource directory under the res folder (listed in the example above) can have different variations of the contained resources in similarly named directory suffixed with different qualifier-values for each configuration-type.
Example of variations of `` directory with different qualifier value...
C and C++ are well known as high-performance languages - largely due to the heavy amount of code customization, allowing a user to specify performance by choice of structure.
When optimizing it is important to benchmark relevant code and completely understand how the code will be used.
Common opti...
Extractor behavior can be used to derive arbitrary values from their input. This can be useful in scenarios where you want to be able to act on the results of a transformation in the event that the transformation is successful.
Consider as an example the various user name formats usable in a Window...
Creating a Window with OpenGL context (extension loading through GLEW):
#define GLEW_STATIC
#include <GL/glew.h>
#include <SDL2/SDL.h>
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO); /* Initialises Video Subsystem in SDL */
/* Setting up OpenGL version a...