If you need to roll for a true or false in an "x% chance" situation, use:
function roll(chance:Number):Boolean {
return Math.random() >= chance;
}
Used like:
var success:Boolean = roll(0.5); // True 50% of the time.
var again:Boolean = roll(0.25); // True 25% of the time.
...
To get any random color:
function randomColor():uint
{
return Math.random() * 0xFFFFFF;
}
If you need more control over the red, green and blue channels:
var r:uint = Math.random() * 0xFF;
var g:uint = Math.random() * 0xFF;
var b:uint = Math.random() * 0xFF;
var color:uint = r <&...
This is the built-in way to deal with "exceptions" without relying on third party libraries like Try::Tiny.
my $ret;
eval {
$ret = some_function_that_might_die();
1;
} or do {
my $eval_error = $@ || "Zombie error!";
handle_error($eval_error);
};
# use $ret
...
Gets System.Type object for a type.
System.Type type = typeof(Point) //System.Drawing.Point
System.Type type = typeof(IDisposable) //System.IDisposable
System.Type type = typeof(Colors) //System.Drawing.Color
System.Type type = typeof(List<>) //System.Collections....
Value Type (where T : struct)
The built-in primitive data types, such as char, int, and float, as well as user-defined types declared with struct, or enum. Their default value is new T() :
default(int) // 0
default(DateTime) // 0001-01-01 12:00:00 AM
default(char) // '...
To get started with Thymeleaf visit official download page.
Maven dependency
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
Gradle dependency
compile gr...
Current file
You can get the name of the current PHP file (with the absolute path) using the __FILE__ magic constant. This is most often used as a logging/debugging technique.
echo "We are in the file:" , __FILE__ , "\n";
Current directory
To get the absolute path to the di...
array_chunk() splits an array into chunks
Let's say we've following single dimensional array,
$input_array = array('a', 'b', 'c', 'd', 'e');
Now using array_chunk() on above PHP array,
$output_array = array_chunk($input_array, 2);
Above code will make chunks of 2 array elements and create a...
The first step in optimizing for speed is finding the slowest sections of code. The Timer VBA function returns the number of seconds elapsed since midnight with a precision of 1/256th of a second (3.90625 milliseconds) on Windows based PCs. The VBA functions Now and Time are only accurate to a secon...
std::sort, found in the standard library header algorithm, is a standard library algorithm for sorting a range of values, defined by a pair of iterators. std::sort takes as the last parameter a functor used to compare two values; this is how it determines the order. Note that std::sort is not stable...
This will teach you how to make your first project using IDEA.
Launch IDEA, and click Create New Project from the startup screen:
Click Next on the next screen. We're creating a simple Java project, so we don't need any addons or extras to this project
Use the next screen to create the Java H...
A series is a one-dimension data structure. It's a bit like a supercharged array, or a dictionary.
import pandas as pd
s = pd.Series([10, 20, 30])
>>> s
0 10
1 20
2 30
dtype: int64
Every value in a series has an index. By default, the indices are integers, running fro...
Simple example of how to create a custom plugin and DSL for your gradle project.
This sample uses one of the three possible ways of creating plugins.
The three ways are:
inline
buildSrc
standalone plugins
This example shows creating a plugin from the buildSrc folder.
This sample will crea...