Tutorial by Examples

function randomAngleRadians():Number { return Math.random() * Math.PI * 2; } Example outputs: 5.490068569213088 3.1984284719180205 4.581117863808207
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 display the hunks that are staged for commit: git diff --cached
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...
2.2 func removeCharactersNotInSetFromText(text: String, set: Set<Character>) -> String { return String(text.characters.filter { set.contains( $0) }) } let text = "Swift 3.0 Come Out" var chars = Set([Character]("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ&...
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...
In [11]: df = pd.DataFrame([[1, 2, None, 3], [4, None, 5, 6], [7, 8, 9, 10], [None, None, None, None]]) Out[11]: 0 1 2 3 0 1.0 2.0 NaN 3.0 1 4.0 NaN 5.0 6.0 2 7.0 8.0 9.0 10.0 3 NaN NaN NaN NaN Fill missing values with a sin...
When creating a DataFrame None (python's missing value) is converted to NaN (pandas' missing value): In [11]: df = pd.DataFrame([[1, 2, None, 3], [4, None, 5, 6], [7, 8, 9, 10], [None, None, None, None]]) Out[11]: 0 1 2 3 0 1.0 2.0 NaN 3.0 1 ...
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...
function isEven(n:Number):Boolean { return ((n & 1) == 0); } Examples: isEven(1); // false isEven(2); // true isEven(1.1); // false isEven(1.2); // false isEven(2.1); // true isEven(2.2); // true
function isOdd(n:Number):Boolean { return ((n & 1) == 1); } Examples: isOdd(1); // true isOdd(2); // false isOdd(1.1); // true isOdd(1.2); // true isOdd(2.1); // false isOdd(2.2); // false
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...

Page 232 of 1336