These are the most common ways to create an instance of Guid:
Creating an empty guid (00000000-0000-0000-0000-000000000000):
Guid g = Guid.Empty;
Guid g2 = new Guid();
Creating a new (pseudorandom) Guid:
Guid g = Guid.NewGuid();
Creating Guids with a specific value:
Guid g = n...
Prerequisite: Installing Gradle
Once you have Gradle installed, you can setup a new or existing project by running
cd $PROJECT_DIR
gradle init --type=java-library
Note that there are other project types like Scala you can get started with, but we'll use Java for this example.
You will end up ...
let x = true
match x with
| true -> printfn "x is true"
yields a warning
C:\Program Files (x86)\Microsoft VS Code\Untitled-1(2,7): warning FS0025: Incomplete pattern matches on this expression. For example, the value 'false' may indicate a case not covered by the pattern(s).
...
type Person = {
Age : int
PassedDriversTest : bool }
let someone = { Age = 19; PassedDriversTest = true }
match someone.PassedDriversTest with
| true when someone.Age >= 16 -> printfn "congrats"
| true -> printfn "wait until you are 16"
| false -> p...
compile built-in function can be used to precompile an expression to a code object; this code object can then be passed to eval. This will speed up the repeated executions of the evaluated code. The 3rd parameter to compile needs to be the string 'eval'.
>>> code = compile('a * b + c', '&l...
>>> variables = {'a': 6, 'b': 7}
>>> eval('a * b', globals=variables)
42
As a plus, with this the code cannot accidentally refer to the names defined outside:
>>> eval('variables')
{'a': 6, 'b': 7}
>>> eval('variables', globals=variables)
Traceback (most ...
You can fetch the current properties of the Annotation by using Reflection to fetch the Method or Field or Class which has an Annotation applied to it, and then fetching the desired properties.
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String key() default "foo";...
As the static keyword is used for accessing fields and methods without an instantiated class, it can be used to declare constants for use in other classes. These variables will remain constant across every instantiation of the class. By convention, static variables are always ALL_CAPS and use unders...
Static gives a method or variable storage that is not allocated for each instance of the class. Rather, the static variable is shared among all class members. Incidentally, trying to treat the static variable like a member of the class instance will result in a warning:
public class Apple {
pu...
It is possible to create a QtQuick view directly from C++ and to expose to QML C++ defined properties. In the code below the C++ program creates a QtQuick view and exposes to QML the height and width of the view as properties.
main.cpp
#include <QApplication>
#include <QQmlContext>
#...
Jagged arrays are arrays that instead of primitive types, contain arrays (or other collections). It's like an array of arrays - each array element contains another array.
They are similar to multidimensional arrays, but have a slight difference - as multidimensional arrays are limited to a fixed nu...
The Page directive defines the attributes specific to the page file for the page parser and the compiler.
The basic syntax of Page directive is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Trace="tr...
>>> '{0:.0f}'.format(42.12345)
'42'
>>> '{0:.1f}'.format(42.12345)
'42.1'
>>> '{0:.3f}'.format(42.12345)
'42.123'
>>> '{0:.5f}'.format(42.12345)
'42.12345'
>>> '{0:.7f}'.format(42.12345)
'42.1234500'
Same hold for other way of referenc...
You can also use regular expressions to split a string. For example,
import re
data = re.split(r'\s+', 'James 94 Samantha 417 Scarlett 74')
print( data )
# Output: ['James', '94', 'Samantha', '417', 'Scarlett', '74']
You can get rid of manage.py and use the django-admin command instead. To do so, you will have to manually do what manage.py does:
Add your project path to your PYTHONPATH
Set the DJANGO_SETTINGS_MODULE
export PYTHONPATH="/home/me/path/to/your_project"
export DJANGO_SETTINGS_MODULE...
If you have a vsix file, you can install it by running the file.
Get the vsix file (this is the extension installer)
Run the file.
In the window that opens, confirm the installation.
In Visual studio
go to Tools > Extensions and updates...
In the window that opens go to online
Select Visual Studio Gallery
You can search for an extension on the search box at the upper right corner
Select the extension you want to add
Click on download.
Once download is complete, click...
int x = 5 / 0; // Undefined behavior
Division by 0 is mathematically undefined, and as such it makes sense that this is undefined behavior.
However:
float x = 5.0f / 0.0f; // x is +infinity
Most implementation implement IEEE-754, which defines floating point division by zero to return N...