LibGDX has a fairly simple setup, with the help of a simple Java program. You can find the download here. When you startup the application, it will look something like this:
Note: This screenshot have been taken on Linux and shows path that differs from a Windows installation. However, the form is...
We can repeat an action some number of times using repeat.
CL-USER> (loop repeat 10 do (format t "Hello!~%"))
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
NIL
CL-USER> (loop repeat 10 collect (random 50))
(28 46 44 31 5 33 43 35 37 4)
(loop for i in '(one two three four five six)
do (print i))
(loop for i in '(one two three four five six) by #'cddr
do (print i)) ;prints ONE THREE FIVE
(loop for i on '(a b c d e f g)
do (print (length i))) ;prints 7 6 5 4 3 2 1
(loop for i on '(a b c d e f g) by #'cddr
...
Combining typedef with struct can make code clearer. For example:
typedef struct
{
int x, y;
} Point;
as opposed to:
struct Point
{
int x, y;
};
could be declared as:
Point point;
instead of:
struct Point point;
Even better is to use the following
typedef struct Poin...
This example assumes you have already installed Java and Gradle.
Use the following project structure:
src/
main/
java/
com/
example/
Application.java
build.gradle
build.gradle is your build script for Gradle build system with the following content:
buildscri...
Run the command below in a shell after installing Ruby. This shows how you can execute simple Ruby programs without creating a Ruby file:
ruby -e 'puts "Hello World"'
You can also feed a Ruby program to the interpreter's standard input. One way to do that is to use a here document in...
Say you have a library website, and you want to have a custom post type named Books. It can be registered as
function create_bookposttype() {
$args = array(
'public' => true,
'labels' => array(
'name' => __( 'Books' ),
'singular_name' => ...
To split one component off of the path:
>>> p = os.path.join(os.getcwd(), 'foo.txt')
>>> p
'/Users/csaftoiu/tmp/foo.txt'
>>> os.path.dirname(p)
'/Users/csaftoiu/tmp'
>>> os.path.basename(p)
'foo.txt'
>>> os.path.split(os.getcwd())
('/Users/csafto...
Every package requires a setup.py file which describes the package.
Consider the following directory structure for a simple package:
+-- package_name
| |
| +-- __init__.py
|
+-- setup.py
The __init__.py contains only the line def foo(): return 100.
The following setup.py...
To find every vector of the form (x, y) where x is drawn from vector X and y from Y, we use expand.grid:
X = c(1, 1, 2)
Y = c(4, 5)
expand.grid(X, Y)
# Var1 Var2
# 1 1 4
# 2 1 4
# 3 2 4
# 4 1 5
# 5 1 5
# 6 2 5
The result is a data.frame with one...
unique drops duplicates so that each element in the result is unique (only appears once):
x = c(2, 1, 1, 2, 1)
unique(x)
# 2 1
Values are returned in the order they first appeared.
duplicated tags each duplicated element:
duplicated(x)
# FALSE FALSE TRUE TRUE TRUE
anyDuplicated(x) >...
To count how many elements of two sets overlap, one could write a custom function:
xtab_set <- function(A, B){
both <- union(A, B)
inA <- both %in% A
inB <- both %in% B
return(table(inA, inB))
}
A = 1:20
B = 10:30
xtab_set(A, B)
# inB
...
Imagine you have the following HTML:
<div>
<label>Name:</label>
John Smith
</div>
And you need to locate the text "John Smith" after the label element.
In this case, you can locate the label element by text and then use .next_sibling property:
from ...
BeautifulSoup has a limited support for CSS selectors, but covers most commonly used ones. Use select() method to find multiple elements and select_one() to find a single element.
Basic example:
from bs4 import BeautifulSoup
data = """
<ul>
<li class="item&quo...
Sets are unordered collections of distinct elements. But sometimes we want to work with unordered collections of elements that are not necessarily distinct and keep track of the elements' multiplicities.
Consider this example:
>>> setA = {'a','b','b','c'}
>>> setA
set(['a', 'c'...
You can restrict the valid types used in a generic class by bounding that type in the class definition. Given the following simple type hierarchy:
public abstract class Animal {
public abstract String getSound();
}
public class Cat extends Animal {
public String getSound() {
...
Let's say we have the following data:
>>> data = {"cats": [{"name": "Tubbs", "color": "white"}, {"name": "Pepper", "color": "black"}]}
Just dumping this as JSON does not do anything special here:
...
A sequence is very much like a list: it is an immutable object that can give you its first element or the rest of its elements in constant time. You can also construct a new sequence from an existing sequence and an item to stick at the beginning.
You can test whether something is a sequence using ...