Given a string, strspn calculates the length of the initial substring (span) consisting solely of a specific list of characters. strcspn is similar, except it calculates the length of the initial substring consisting of any characters except those listed:
/*
Provided a string of "tokens&quo...
class A:
x = None # type: float
def __init__(self, x: float) -> None:
"""
self should not be annotated
init should be annotated to return None
"""
self.x = x
@classmethod
def from_int(cls, x: int...
Variables are annotated using comments:
x = 3 # type: int
x = negate(x)
x = 'a type-checker might catch this error'
Python 3.x3.6
Starting from Python 3.6, there is also new syntax for variable annotations. The code above might use the form
x: int = 3
Unlike with comments, it is also pos...
Double quoteSingle quoteAllows variable expansionPrevents variable expansionAllows history expansion if enabledPrevents history expansionAllows command substitutionPrevents command substitution* and @ can have special meaning* and @ are always literalsCan contain both single quote or double quoteSin...
The code below will prompt for numbers and continue to add them to the beginning of a linked list.
/* This program will demonstrate inserting a node at the beginning of a linked list */
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
...
Since functions are ordinary values, there is a convenient syntax for creating functions without names:
List.map (fun x -> x * x) [1; 2; 3; 4]
(* - : int list = [1; 4; 9; 16] *)
This is handy, as we would otherwise have to name the function first (see let) to be able to use it:
let square x...
class Plane {
enum Emergency: ErrorType {
case NoFuel
case EngineFailure(reason: String)
case DamagedWing
}
var fuelInKilograms: Int
//... init and other methods not shown
func fly() throws {
// ...
if fuelInKilograms ...
If while working you realize you're on wrong branch and you haven't created any commits yet, you can easily move your work to correct branch using stashing:
git stash
git checkout correct-branch
git stash pop
Remember git stash pop will apply the last stash and delete it from the stash list. T...
process.argv is an array containing the command line arguments. The first element will be node, the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments.
Code Example:
Output sum of all command line arguments
index.js
var sum = 0...
Using vanilla mathematics:
var from:Point = new Point(100, 50);
var to:Point = new Point(80, 95);
var angle:Number = Math.atan2(to.y - from.y, to.x - from.x);
Using a new vector representing the difference between the first two:
var difference:Point = to.subtract(from);
var angle:Number ...
Using vanilla mathematics:
var from:Point = new Point(300, 10);
var to:Point = new Point(75, 40);
var a:Number = to.x - from.x;
var b:Number = to.y - from.y;
var distance:Number = Math.sqrt(a * a + b * b);
Using inbuilt functionality of Point:
var distance:Number = to.subtract(from).len...
A whole circle is 360 degrees or Math.PI * 2 radians.
Half of those values follows to be 180 degrees or Math.PI radians.
A quarter is then 90 degrees or Math.PI / 2 radians.
To get a segment as a percentage of a whole circle in radians:
function getSegment(percent:Number):Number {
retur...
Assuming you have the angle you'd like to move in and an object with x and y values you want to move:
var position:Point = new Point(10, 10);
var angle:Number = 1.25;
You can move along the x axis with Math.cos:
position.x += Math.cos(angle);
And the y axis with Math.sin:
position.y += Mat...
You can test whether a point is inside a rectangle using Rectangle.containsPoint():
var point:Point = new Point(5, 5);
var rectangle:Rectangle = new Rectangle(0, 0, 10, 10);
var contains:Boolean = rectangle.containsPoint(point); // true
clojure.spec/and & clojure.spec/or can be used to create more complex specs, using multiple specs or predicates:
(clojure.spec/def ::pos-odd (clojure.spec/and odd? pos?))
(clojure.spec/valid? ::pos-odd 1)
;;=> true
(clojure.spec/valid? ::pos-odd -3)
;;=> false
or works similarl...
Range sliders provide 2 draggable handles to select numeric values. The slider's initialization must provide a range option set to true to create a range slider:
<script>
$(function() {
$( "#range-slider" ).slider({
range: true
});
});
</script>
<...
A slider element can have its value set on initialization by providing a value option. This option is a number:
$( "#slider" ).slider({
value: 5
});
A range slider can also have its values set in this way by providing a values option. This option is an array of numbers:
$( &qu...