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
...
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) // '...
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...
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...
Detailed instructions on getting openerp set up or installed in Debian/Ubuntu.
To install from source code, we need Python 2.7, Git and a PostgreSQL database:
$ sudo apt-get install git python-pip python2.7-dev -y
$ sudo apt-get install postgresql -y
$ sudo su -c "createuser -s $(whoami)&qu...
The Flex compiler (mxmlc) is one of the most important parts of the Flex SDK. You can edit AS3 code in any text editor you like. Create a main class file that extends from DisplayObject.
You can trigger builds at the command line as follows:
mxmlc -source-path="." -default-size [width in...
Imagine the following XML:
<root>
<element>hello</element>
<another>
hello
</another>
<example>Hello, <nested> I am an example </nested>.</example>
</root>
The following XPath expression:
//*[text() = 'hel...
List all the existing remotes associated with this repository:
git remote
List all the existing remotes associated with this repository in detail including the fetch and push URLs:
git remote --verbose
or simply
git remote -v
The static method Date.now returns the number of milliseconds that have elapsed since 1 January 1970 00:00:00 UTC. To get the number of milliseconds that have elapsed since that time using an instance of a Date object, use its getTime method.
// get milliseconds using static method now of Date
co...
This command is useful if you want to serve a single site in a directory and not the entire directory.
cd ~/Projects/my-blog/
valet link awesome-blog
Valet will create a symbolic link in ~/.valet/Sites which points to your current working directory.
After running the link command, you can acce...