Struct Point
A structure that represents a standard 2D point. Provides numerous functions and operators that enable common grid/position-related math and operations.
Implements
Inherited Members
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
[DataContract]
public struct Point : IEquatable<Point>, IEquatable<(int x, int y)>, IMatchable<Point>, IMatchable<(int x, int y)>
Remarks
Point instances can be created using the standard Point c = new Point(x, y) syntax. In addition, you may create a coord from a c# 7 tuple, like Point c = (x, y);. As well, Point supports C# Deconstruction syntax.
Point also provides operators and static helper functions that perform common grid math/operations, as well as interoperability with other grid-based classes like Direction.
Constructors
| Improve this Doc View SourcePoint(Int32, Int32)
Constructor.
Declaration
public Point(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X-value for the coordinate. |
| Int32 | y | Y-value for the coordinate. |
Fields
| Improve this Doc View SourceNone
Point value that represents None or no position (since Point is not a nullable type). Typically you would use this constant instead of null.
Declaration
public static readonly Point None
Field Value
| Type | Description |
|---|---|
| Point |
Remarks
This constant has (x, y) values (int.MinValue, int.MinValue), so a position with those x/y values is not considered a valid coordinate by many functions.
X
X-value of the position.
Declaration
[DataMember]
public readonly int X
Field Value
| Type | Description |
|---|---|
| Int32 |
Y
Y-value of the position.
Declaration
[DataMember]
public readonly int Y
Field Value
| Type | Description |
|---|---|
| Int32 |
Methods
| Improve this Doc View SourceBearingOfLine(Point)
Calculates the degree bearing of a line with the given delta-x and delta-y values, where 0 degrees points in the direction Up.
Declaration
[Pure]
public static double BearingOfLine(Point deltaChange)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | deltaChange | Vector, where deltaChange.X is the change in x-values across the line, and deltaChange.Y is the change in y-values across the line. |
Returns
| Type | Description |
|---|---|
| Double | The degree bearing of the line with the given dx and dy values. |
BearingOfLine(Point, Point)
Calculates degree bearing of the line (start => end), where 0 points in the direction Up.
Declaration
[Pure]
public static double BearingOfLine(Point start, Point end)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | start | Position of line starting point. |
| Point | end | Position of line ending point. |
Returns
| Type | Description |
|---|---|
| Double | The degree bearing of the line specified by the two given points. |
BearingOfLine(Int32, Int32)
Calculates the degree bearing of a line with the given delta-x and delta-y values, where 0 degrees points in the direction Up.
Declaration
[Pure]
public static double BearingOfLine(int dx, int dy)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | dx | Change in x-value across the line. |
| Int32 | dy | Change in y-value across the line. |
Returns
| Type | Description |
|---|---|
| Double | The degree bearing of the line with the given dx and dy values. |
BearingOfLine(Int32, Int32, Int32, Int32)
Calculates degree bearing of the line (start => end), where 0 points in the direction Up.
Declaration
[Pure]
public static double BearingOfLine(int startX, int startY, int endX, int endY)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | startX | X-value of the position of line starting point. |
| Int32 | startY | Y-value of the position of line starting point. |
| Int32 | endX | X-value of the position of line ending point. |
| Int32 | endY | X-value of the position of line ending point. |
Returns
| Type | Description |
|---|---|
| Double | The degree bearing of the line specified by the two given points. |
Deconstruct(out Int32, out Int32)
Adds support for C# Deconstruction syntax.
Declaration
[Pure]
public void Deconstruct(out int x, out int y)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | |
| Int32 | y |
Equals(Point)
True if the given coordinate has equal x and y values to the current one.
Declaration
[Pure]
public bool Equals(Point other)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | other | Position to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
Equals(Object)
Same as operator == in this case; returns false if obj
is not a Point.
Declaration
[Pure]
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | The object to compare the current Point to. |
Returns
| Type | Description |
|---|---|
| Boolean | True if |
Overrides
| Improve this Doc View SourceEquals((Int32 x, Int32 y))
True if the given position has equal x and y values to the current one.
Declaration
[Pure]
public bool Equals((int x, int y) other)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | other | Tuple to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
EuclideanDistanceMagnitude(Point)
Returns the result of the euclidean distance formula, without the square root, given the dx and dy values between two points -- eg., (deltaChange.X * deltaChange.X) + (deltaChange.Y
- deltaChange.Y). Use this if you only care about the magnitude of the distance -- eg., if you're trying to compare two distances. Omitting the square root provides a speed increase.
Declaration
[Pure]
public static double EuclideanDistanceMagnitude(Point deltaChange)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | deltaChange | Vector, where deltaChange.X is the change in x-values between the two points, and deltaChange.Y is the change in y-values between the two points. |
Returns
| Type | Description |
|---|---|
| Double | The "magnitude" of the euclidean distance of two locations with the given dx and dy values -- basically the distance formula without the square root. |
EuclideanDistanceMagnitude(Point, Point)
Returns the result of the euclidean distance formula, without the square root -- eg., (c2.X - c1.X) * (c2.X - c1.X) + (c2.Y - c1.Y) * (c2.Y - c1.Y). Use this if you only care about the magnitude of the distance -- eg., if you're trying to compare two distances. Omitting the square root provides a speed increase.
Declaration
[Pure]
public static double EuclideanDistanceMagnitude(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | The first point. |
| Point | c2 | The second point. |
Returns
| Type | Description |
|---|---|
| Double | The "magnitude" of the euclidean distance between the two points -- basically the distance formula without the square root. |
EuclideanDistanceMagnitude(Int32, Int32)
Returns the result of the euclidean distance formula, without the square root, given the dx and dy values between two points -- eg., (deltaChange.X * deltaChange.X) + (deltaChange.Y
- deltaChange.Y). Use this if you only care about the magnitude of the distance -- eg., if you're trying to compare two distances. Omitting the square root provides a speed increase.
Declaration
[Pure]
public static double EuclideanDistanceMagnitude(int dx, int dy)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | dx | Change in x-values between the two points. |
| Int32 | dy | Change in y-values between the two points. |
Returns
| Type | Description |
|---|---|
| Double | The "magnitude" of the euclidean distance of two locations with the given dx and dy values -- basically the distance formula without the square root. |
EuclideanDistanceMagnitude(Int32, Int32, Int32, Int32)
Returns the result of the euclidean distance formula, without the square root -- eg., (c2.X - c1.X) * (c2.X - c1.X) + (c2.Y - c1.Y) * (c2.Y - c1.Y). Use this if you only care about the magnitude of the distance -- eg., if you're trying to compare two distances. Omitting the square root provides a speed increase.
Declaration
[Pure]
public static double EuclideanDistanceMagnitude(int firstX, int firstY, int secondX, int secondY)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | firstX | X-value for the first point. |
| Int32 | firstY | Y-value for the first point. |
| Int32 | secondX | X-value for the second point. |
| Int32 | secondY | Y-value for the second point. |
Returns
| Type | Description |
|---|---|
| Double | The "magnitude" of the euclidean distance between the two points -- basically the distance formula without the square root. |
FromIndex(Int32, Int32)
Reverses the ToIndex functions, returning the position represented by a given index.
Declaration
[Pure]
public static Point FromIndex(int index, int width)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | The index in 1D form. |
| Int32 | width | The width of the 2D array. |
Returns
| Type | Description |
|---|---|
| Point | The position represented by the 1D index given. |
GetHashCode()
Returns a hash code for the Point. The important parts: it should be fairly fast and it does not collide often.
Declaration
[Pure]
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The hash-code for the Point. |
Overrides
Remarks
This hashing algorithm uses a separate bit-mixing algorithm for X and Y, with X and Y each multiplied by a different large integer, then xors the mixed values, does a right shift, and finally multiplies by an overflowing prime number. This hashing algorithm should produce an exceptionally low collision rate for coordinates between (0, 0) and (255, 255), and remain relatively reasonable beyond that.
Matches(Point)
True if the given coordinate has equal x and y values to the current one.
Declaration
[Pure]
public bool Matches(Point other)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | other | Position to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
Matches((Int32 x, Int32 y))
True if the given position has equal x and y values to the current one.
Declaration
[Pure]
public bool Matches((int x, int y) other)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | other | Point to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
Midpoint(Point, Point)
Returns the midpoint between the two points.
Declaration
[Pure]
public static Point Midpoint(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | The first point. |
| Point | c2 | The second point. |
Returns
| Type | Description |
|---|---|
| Point | The midpoint between |
Midpoint(Int32, Int32, Int32, Int32)
Returns the midpoint between the two points.
Declaration
[Pure]
public static Point Midpoint(int firstX, int firstY, int secondX, int secondY)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | firstX | X-value for the first point. |
| Int32 | firstY | Y-value for the first point. |
| Int32 | secondX | X-value for the second point. |
| Int32 | secondY | Y-value for the second point. |
Returns
| Type | Description |
|---|---|
| Point | The midpoint between the two points. |
Rotate(Double)
Rotates a single point around the origin (0, 0).
Declaration
[Pure]
public Point Rotate(double degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | degrees | The amount of Degrees to rotate this point clockwise |
Returns
| Type | Description |
|---|---|
| Point | The equivalent point after a rotation |
Rotate(Double, Point)
Rotates a single point around the origin point.
Declaration
[Pure]
public Point Rotate(double degrees, Point origin)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | degrees | The amount of Degrees to rotate this point |
| Point | origin | The Point around which to rotate |
Returns
| Type | Description |
|---|---|
| Point | The equivalent point after a rotation |
Rotate(Double, Int32, Int32)
Rotates a single point around the origin point.
Declaration
[Pure]
public Point Rotate(double degrees, int originX, int originY)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | degrees | The amount of Degrees to rotate this point |
| Int32 | originX | X-value of the location around which to rotate |
| Int32 | originY | Y-value of the location around which to rotate |
Returns
| Type | Description |
|---|---|
| Point | The equivalent point after a rotation |
ToIndex(Int32)
Returns a value that can be used to uniquely index this location 1D array.
Declaration
[Pure]
public int ToIndex(int width)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | width | The width of the 2D map/array this location is referring to -- used to do the math to calculate index. |
Returns
| Type | Description |
|---|---|
| Int32 | The 1D index of this Point. |
ToIndex(Int32, Int32, Int32)
Returns y
* width
+ x
.
Declaration
[Pure]
public static int ToIndex(int x, int y, int width)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X-value of the coordinate. |
| Int32 | y | Y-value of the coordinate. |
| Int32 | width | The width of the 2D array, used to do the math to calculate index. |
Returns
| Type | Description |
|---|---|
| Int32 | The 1D index of the position specified. |
ToPolarCoordinate()
Returns a Polar Coordinate that is equivalent to this (Cartesian) Coordinate
Declaration
[Pure]
public PolarCoordinate ToPolarCoordinate()
Returns
| Type | Description |
|---|---|
| PolarCoordinate | The Equivalent Polar Coordinate |
ToString()
Returns representation (X, Y).
Declaration
[Pure]
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | String (X, Y) |
Overrides
| Improve this Doc View SourceToXValue(Int32, Int32)
Reverses the ToIndex functions, returning only the X-value for the given index.
Declaration
[Pure]
public static int ToXValue(int index, int width)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | The index in 1D form. |
| Int32 | width | The width of the 2D array. |
Returns
| Type | Description |
|---|---|
| Int32 | The X-value for the location represented by the given index. |
ToYValue(Int32, Int32)
Reverses the ToIndex functions, returning only the Y-value for the given index.
Declaration
[Pure]
public static int ToYValue(int index, int width)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | The index in 1D form. |
| Int32 | width | The width of the 2D array. |
Returns
| Type | Description |
|---|---|
| Int32 | The Y-value for the location represented by the given index. |
Translate(Point)
Returns the position resulting from adding dx to the X-value of the position, and dy to the Y-value of the position.
Declaration
[Pure]
public Point Translate(Point deltaChange)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | deltaChange | Vector where deltaChange.X represents the delta-x value and deltaChange.Y represents the delta-y value. |
Returns
| Type | Description |
|---|---|
| Point |
Translate(Int32, Int32)
Returns the position resulting from adding dx to the X-value of the position, and dy to the Y-value of the position.
Declaration
[Pure]
public Point Translate(int dx, int dy)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | dx | Change in x-value to apply. |
| Int32 | dy | Change in y-value to apply. |
Returns
| Type | Description |
|---|---|
| Point |
WithX(Int32)
Creates a new Point with its X value moved to the given one.
Declaration
[Pure]
public Point WithX(int x)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X-value for the new Point. |
Returns
| Type | Description |
|---|---|
| Point | A new Point, with its X value changed to the given one. |
WithY(Int32)
Creates a new Point with its Y value moved to the given one.
Declaration
[Pure]
public Point WithY(int y)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | y | Y-value for the new Point. |
Returns
| Type | Description |
|---|---|
| Point | A new Point, with its Y value changed to the given one. |
Operators
| Improve this Doc View SourceAddition(Point, Direction)
Translates the given position by one unit in the given direction.
Declaration
[Pure]
public static Point operator +(Point c, Direction d)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| Direction | d |
Returns
| Type | Description |
|---|---|
| Point | Position (c.X + d.DeltaX, c.Y + d.DeltaY) |
Addition(Point, Point)
Returns the position (c1.X + c2.X, c1.Y + c2.Y).
Declaration
[Pure]
public static Point operator +(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | |
| Point | c2 |
Returns
| Type | Description |
|---|---|
| Point | The position (c1.X + c2.X, c1.Y + c2.Y) |
Addition(Point, Int32)
Adds scalar i to the x and y values of c
.
Declaration
[Pure]
public static Point operator +(Point c, int i)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| Int32 | i |
Returns
| Type | Description |
|---|---|
| Point | Position (c.X + |
Addition(Point, (Int32 x, Int32 y))
Adds the x and y values of a tuple of two integers to a Point.
Declaration
[Pure]
public static Point operator +(Point c, (int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| Point | Position (c.X + tuple.x, c.Y + tuple.y). |
Addition((Int32 x, Int32 y), Point)
Adds the x and y values of a Point to the corresponding values of a tuple of two integers.
Declaration
[Pure]
public static (int x, int y) operator +((int x, int y) tuple, Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple | |
| Point | c |
Returns
| Type | Description |
|---|---|
| ValueTuple<Int32, Int32> | A tuple (tuple.x + c.X, tuple.y + c.Y). |
Division(Point, Point)
Divides the x/y components of c1
by the x/y components of c2
, rounding each resulting
value to the nearest integer.
Declaration
[Pure]
public static Point operator /(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | |
| Point | c2 |
Returns
| Type | Description |
|---|---|
| Point | Position (c1.X / c2.X, c1.Y / c2.Y), with each value rounded to the nearest integer. |
Division(Point, Double)
Divides the x and y of c
by i
, rounding resulting values
to the nearest integer.
Declaration
[Pure]
public static Point operator /(Point c, double i)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| Double | i |
Returns
| Type | Description |
|---|---|
| Point | (c.X / |
Division(Point, (Int32 x, Int32 y))
Divides the x/y values of a Point by the x/y values of a tuple of two integers, rounding to the nearest integer.
Declaration
[Pure]
public static (int x, int y) operator /(Point c, (int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| ValueTuple<Int32, Int32> | Position (c.X / tuple.x, c.Y / tuple.y), with each value rounded to the nearest integer. |
Division((Int32 x, Int32 y), Point)
Divides the x/y values of a tuple of two integers by the x/y values of a Point, rounding to the nearest integer.
Declaration
[Pure]
public static (int x, int y) operator /((int x, int y) tuple, Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple | |
| Point | c |
Returns
| Type | Description |
|---|---|
| ValueTuple<Int32, Int32> | Position (tuple.x / c.X, tuple.y / c.Y), with each value rounded to the nearest integer. |
Equality(Point, Point)
True if c1.X == c2.X and c1.Y == c2.Y.
Declaration
[Pure]
public static bool operator ==(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | |
| Point | c2 |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
Equality(Point, (Int32 x, Int32 y))
True if the two point's x and y values are equal.
Declaration
[Pure]
public static bool operator ==(Point c, (int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
Equality((Int32 x, Int32 y), Point)
True if the two point's x and y values are equal.
Declaration
[Pure]
public static bool operator ==((int x, int y) tuple, Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple | |
| Point | c |
Returns
| Type | Description |
|---|---|
| Boolean | True if the two positions are equal, false if not. |
Implicit(Point to PolarCoordinate)
Implicitly converts a Point to its equivalent polar coordinate.
Declaration
public static implicit operator PolarCoordinate(Point pos)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | pos | Point to convert. |
Returns
| Type | Description |
|---|---|
| PolarCoordinate | A PolarCoordinate equivalent to this cartesian point. |
Implicit(Point to (Int32 x, Int32 y))
Implicitly converts a Point to an equivalent tuple of two integers.
Declaration
[Pure]
public static implicit operator (int x, int y)(Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c |
Returns
| Type | Description |
|---|---|
| ValueTuple<Int32, Int32> |
Implicit((Int32 x, Int32 y) to Point)
Implicitly converts a tuple of two integers to an equivalent Point.
Declaration
[Pure]
public static implicit operator Point((int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| Point |
Inequality(Point, Point)
True if either the x-values or y-values are not equal.
Declaration
[Pure]
public static bool operator !=(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | |
| Point | c2 |
Returns
| Type | Description |
|---|---|
| Boolean | True if either the x-values or y-values are not equal, false if they are both equal. |
Inequality(Point, (Int32 x, Int32 y))
True if either the x-values or y-values are not equal.
Declaration
[Pure]
public static bool operator !=(Point c, (int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| Boolean | True if either the x-values or y-values are not equal, false if they are both equal. |
Inequality((Int32 x, Int32 y), Point)
True if either the x-values or y-values are not equal.
Declaration
[Pure]
public static bool operator !=((int x, int y) tuple, Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple | |
| Point | c |
Returns
| Type | Description |
|---|---|
| Boolean | True if either the x-values or y-values are not equal, false if they are both equal. |
Multiply(Point, Point)
Multiplies the x and y values of the points together.
Declaration
[Pure]
public static Point operator *(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | |
| Point | c2 |
Returns
| Type | Description |
|---|---|
| Point | Position (c1.X * c2.X, c1.Y * c2.Y) |
Multiply(Point, Double)
Multiplies the x and y value of c
by i
, rounding
the result to the nearest integer.
Declaration
[Pure]
public static Point operator *(Point c, double i)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| Double | i |
Returns
| Type | Description |
|---|---|
| Point | Position (c.X * |
Multiply(Point, Int32)
Multiplies the x and y of c
by i
.
Declaration
[Pure]
public static Point operator *(Point c, int i)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| Int32 | i |
Returns
| Type | Description |
|---|---|
| Point | Coordinate (c.X * |
Multiply(Point, (Int32 x, Int32 y))
Multiples the x and y values of a Point by the x and y values of a tuple of two integers.
Declaration
[Pure]
public static Point operator *(Point c, (int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| Point | Position (c.X * tuple.x, c.Y * tuple.y). |
Multiply((Int32 x, Int32 y), Point)
Multiples the x and y values of a tuple of two integers by the x and y values of a Point.
Declaration
[Pure]
public static (int x, int y) operator *((int x, int y) tuple, Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple | |
| Point | c |
Returns
| Type | Description |
|---|---|
| ValueTuple<Int32, Int32> | Position (tuple.x * c.X, tuple.y * c.Y). |
Subtraction(Point, Direction)
Returns the coordinate (point.X - direction.DeltaX, point.Y - direction.DeltaY).
Declaration
[Pure]
public static Point operator -(Point point, Direction direction)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | point | |
| Direction | direction |
Returns
| Type | Description |
|---|---|
| Point | The coordinate (point.X - direction.DeltaX, point.Y - direction.DeltaY). |
Subtraction(Point, Point)
Returns the coordinate (c1.X - c2.X, c1.Y - c2.Y).
Declaration
[Pure]
public static Point operator -(Point c1, Point c2)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c1 | |
| Point | c2 |
Returns
| Type | Description |
|---|---|
| Point | The coordinate( |
Subtraction(Point, Int32)
Subtracts scalar i
from the x and y values of c
.
Declaration
[Pure]
public static Point operator -(Point c, int i)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| Int32 | i |
Returns
| Type | Description |
|---|---|
| Point | The coordinate (c.X - |
Subtraction(Point, (Int32 x, Int32 y))
Subtracts the x and y values of a tuple of two integers from a Point.
Declaration
[Pure]
public static Point operator -(Point c, (int x, int y) tuple)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | c | |
| ValueTuple<Int32, Int32> | tuple |
Returns
| Type | Description |
|---|---|
| Point | Position (c.X - tuple.x, c.Y - tuple.y). |
Subtraction((Int32 x, Int32 y), Point)
Subtracts the x and y values of a Point from a tuple of two integers.
Declaration
[Pure]
public static (int x, int y) operator -((int x, int y) tuple, Point c)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTuple<Int32, Int32> | tuple | |
| Point | c |
Returns
| Type | Description |
|---|---|
| ValueTuple<Int32, Int32> | A tuple (tuple.x - c.X, tuple.y - c.Y). |


|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.mit.csail.sdg.alloy4viz.AlloyInstance
public final class AlloyInstance
Immutable; represents an Alloy instance that can be displayed in the visualizer.
Thread Safety: Can be called only by the AWT event thread.
| Field Summary | |
|---|---|
java.lang.String |
commandname
The original command that generated this instance; can be "" if unknown. |
java.lang.String |
filename
The original filename of the model that generated this instance; can be "" if unknown. |
boolean |
isMetamodel
If true, it is a metamodel, else it is not a metamodel. |
AlloyModel |
model
The AlloyModel that this AlloyInstance is an instance of. |
| Constructor Summary | |
|---|---|
AlloyInstance(A4Solution originalA4,
java.lang.String filename,
java.lang.String commandname,
AlloyModel model,
java.util.Map<AlloyAtom,java.util.Set<AlloySet>> atom2sets,
java.util.Map<AlloyRelation,java.util.Set<AlloyTuple>> rel2tuples,
boolean isMetamodel)
Create a new instance. |
| Method Summary | |
|---|---|
java.util.List<AlloySet> |
atom2sets(AlloyAtom atom)
Returns an unmodifiable sorted list of AlloySet(s) that this atom is in; answer can be an empty list. |
boolean |
equals(java.lang.Object other)
Two instances are equal if they have the same filename, same commands, same model, and same atoms and tuples relationships. |
java.util.Set<AlloyAtom> |
getAllAtoms()
Returns an unmodifiable sorted set of all AlloyAtoms in this AlloyInstance. |
int |
hashCode()
Computes a hash code based on the same information used in equals(). |
java.util.Set<AlloyTuple> |
relation2tuples(AlloyRelation rel)
Returns an unmodifiable sorted set of AlloyTuple(s) in this relation; answer can be an empty set. |
java.util.List<AlloyAtom> |
set2atoms(AlloySet set)
Returns an unmodifiable sorted list of AlloyAtom(s) in this set; answer can be an empty list. |
java.lang.String |
toString()
Returns a textual dump of the instance. |
java.util.List<AlloyAtom> |
type2atoms(AlloyType type)
Returns an unmodifiable sorted list of AlloyAtom(s) in this type; answer can be an empty list. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public final boolean isMetamodel
public final java.lang.String filename
public final java.lang.String commandname
public final AlloyModel model
| Constructor Detail |
|---|
public AlloyInstance(A4Solution originalA4, java.lang.String filename, java.lang.String commandname, AlloyModel model, java.util.Map<AlloyAtom,java.util.Set<AlloySet>> atom2sets, java.util.Map<AlloyRelation,java.util.Set<AlloyTuple>> rel2tuples, boolean isMetamodel)
filename
- - the original filename of the model that generated this instance; can be "" if unknowncommandname
- - the original command that generated this instance; can be "" if unknownmodel
- - the AlloyModel that this AlloyInstance is an instance ofatom2sets
- - maps each atom to the set(s) it is in; its KeySet is considered the universe of all atomsrel2tuples
- - maps each relation to the tuple(s) it is in
(The constructor will ignore any atoms, sets, types, and relations not in the model. So there's no need to explicitly filter them out prior to passing "atom2sets" and "rel2tuples" to the constructor.)
| Method Detail |
|---|
public java.util.Set<AlloyAtom> getAllAtoms()
public java.util.List<AlloySet> atom2sets(AlloyAtom atom)
public java.util.List<AlloyAtom> type2atoms(AlloyType type)
public java.util.List<AlloyAtom> set2atoms(AlloySet set)
public java.util.Set<AlloyTuple> relation2tuples(AlloyRelation rel)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |


ABOUT EXCELSIA
As a championing Christian higher education provider, Excelsia is an academic community making a better world through active participation in a life-transforming global Christian learning community
Excelsia College > Study
Excelsia
Excellence in
TEACHING
AWARDS
Quarter 2 2021
Hailey McQueen
School of Creative & Performing Art
Meet Hailey McQueen, the winner of 2nd quarter 2021…
Learn More


ProudSource.us is a platform used to connect investors and entrepreneurs with small businesses and startups. Essentially, it's crowdfunding with a financial return. However unlike other financial instruments like traditional loans and equity. We will be using financial instruments based on PROC: Progressive Return on Capital. It is a security that guarantees investors a share of revenue, discounted for costs, for a definite period of time. All trades will eventually be able to be made using all national currencies, cryptocurrencies and eventually precious metals.
ProudSource.us aims to take what the internet age has inherited, the cloud and enshrine finance within it. Our team works around the clock to decentralize the most corrupt and inefficient institutions in the modern economy: the banks. By using tools with less transaction costs, we can pass the savings onto our customers, allowing anyone to invest or build a business. In essence, we will take the sharing economy to its radical conclusion, the sharing and accumulation of capital on a global scale.


Foreman Broker
Jobs
(current)
Tasks
Customers
Racks
Hosts
Jobs:
New Job
Edit Job
Assign Job
Assigned Jobs:
.
Customer
Rack
Job
Status
State
Action
New Job
×
Job Name:
Assign Job
×
Customer:
Select Customer
Racks:
Assign Tasks To Job
×
Task List:
Select Task
Assign Task
Assigned Tasks:
Unassign Task


wins:
losses:
match this:
Click the various 4 finger gems and try to match the gem total. An exact match gives you a win.
Crystal Collector


The same is true of Devonshire. In May 1860 I was told that many of the farmers "are so superstitious as to believe in PISKIES;" they are "never seen, but they are often heard laughing at people in the dark, and they lead them away." My informant said that when he was young he used to hear so many stories about piskies from the old women about the fireside, that he used to be frightened to go out at night.
"When the young colts are out running wild, their manes get rough and hang down on both sides, and get tangled with the wind like; not like manes of horses that are well kept (here the speaker pointed with his whip at the sleek pair which he was driving); and when the farmers find stirrups like in the hair of the mane, they say the piskies has been a ridin' of them."


According to Grimoires users' feedback, it is not easy to program against Grimoires.  Users do not need to understand the data model detail of metadata and WSDL operation. They do not need to know how to create them, either.
public final String saveService(String businessKey, String name, String description, String accessPoint, String wsdlURL)saves a service belonging to the business with the specified business key. The services has the specified name and description. It is installed at the specified access point. And its interface is described by a WSDL, which itself is published as a tModel.
GrimoiresProxy grimoiresProxy = null; // Create a proxy for Grimoires at the default location. grimoiresProxy = new GrimoiresWebServiceProxyFactory().createProxy(null); // Or, create a business logic proxy. // grimoiresProxy = new GrimoiresBusinessLogicProxyFactory().createProxy(null); // save business String businessKey = grimoiresProxy.saveBusiness(businessName, businessDescription); // save service String serviceKey = grimoiresProxy.saveService( businessKey, serviceName, serviceDescription, accessPoint, wsdlURL);
-- WeijianFang - 17 Jul 2006


I am currently exploring computer science, working with TruU Inc., as a machine learning intern, while pursuing a masters degree at the University of Colorado. I get triggered by techno - ethical issues and technology, which often makes me read into policies that define technology. I believe a strong foundation in computer science and experience with corporate teams are essential to make competent decisions and bring positive changes in the 21st century.
Company that aims at achieving frictionless cybersecurity by using smart geolocations.
Involves data augmentation and basic neural network manipulation.
Tools: Pytorch, Sklearn and Skorch
Teaching undergraduate students a beginner’s level programming in MATLAB and C++.
Grading assignments by conducting interviews, and direct the graders for the course assigned under me.
Providing assistance to students and solving problems in their code, as well as building a level of understanding in them.
Course: Introduction to Computer Science for Engineers (CSCI 1320)
Tutored undergraduate students on the fundamentals of Python and the prevalence of technology in the society.
Relevant Coursework: Design and Analysis of Algorithms, Machine Learning, Data Center Scale Computing, Natural Language Processing, Network Systems
Relevant Coursework: Data Structures and Algorithms, Agent Based Intelligent Systems, Distributed Systems, Data Warehousing
A model to convert grayscale images to color using SVM and convolutional neural nets. Images obtained from the imagenet dataset, and resulted in RMSE of 8.50 by using convolutional, implemented using Keras.
Creating an application that will be used for ease in annotations for data science.Built on Docker and Django framework, using MySQL databases. This is an ongoing project.
Using the Twitter API, data was collected, cleaned and using features like the location, check ins, hashtags, mentions, along with sentiment as factors to determine tailor made advertisements for a certain target audience.
A HTTP server to implement some basic functionality like the GET and POST methods. Host websites such that it handles multithreading and improving speed and handle HTTP 1.1 error codes.
A HTTP proxy server to be able to host common websites with features like caching, multithreading and link prefetching. Tested on HTTP 1.0 sites, cache stored in the local drive and errors were further handled in case of compatibility issues.
A distributed file system to be able to create user profiles, and handle each user’s files by using configuration files. Files were split into four parts and stored in different servers based on their MD5 hash values. The folders were created and stored based on the user’s preferences with the option of subfoldering.
Apart from school and work, you can find me writing, listening to an extremely wide variety of music and taking long walks. I have also been an avid public speaker and Toastmaster. I have also received a few accolades for leadership skills, like the high performance leadership award by Toastmasters International. In addition, I also enjoy playing basketball.


A location-enhanced Apple Watch workout app that gives you more customizabilty and faster performance than the stock Workout app.  More Info
A 10 player party game for the Apple TV, controlled by aiming, shaking, and tapping your iOS devices. More Info
Get automatic alerts to take a short break after extended periods of computer use. More Info
Available at https://www.descript.com
Descript spun out of Detour after its acquisition by Bose.
My responsibilities stretch across all of Descript's tech stack:
Acquired by Bose Corporation in April, 2018
Accolades: App Store Best of 2016, Apple Editors’ Choice, App of the Day (1/15/18)
Originally hired as an iOS engineer, I grew to take on projects across Detour's entire technical stack.
My projects varied depending on the needs of the company, but were roughly 80% iOS, 15% API, 2.5% Android, 2.5% Web
I was a teaching assistant for the first nightly iOS Development class in General Assembly's San Francisco office. Responsibilities included helping students during class, holding office hours twice a week, replying to student questions on Slack throughout the week, and grading homework. Additionally, since this was the first class, I also worked with the other teachers to improve the curriculum for future classes. Since then, I have stayed involved in the community by being a substitute teaching assistant and mentor for various students.
I initially worked as a part-time freelancer for String Theory prior to becoming the full-time lead developer. I mentored 4 junior team members, led architecture discussions, and transitioned the app from a prototype into a production app.
I worked as the lead developer in the IDEO Toy Lab. I was responsible for building new apps, maintaining existing apps, managing contractors, and mentoring interns. Below are some of the apps that I worked on.
Accolades: App Store Best of 2013, Apple Editors’ Choice
Accolades: #1 App in Kids category
I was the second hire for the new GuestCenter team. Working closely with designers, product managers, and customers, we built the GuestCenter app from an idea to a live product.
I worked as an iOS developer & occasionally as a backend API developer. While I worked with many different clients, the majority of my time was spent on the Weight Watchers team.
Led a team of 2 other developers to fix a major performance issue in libuv & Electron that affected macOS Big Sur.
Improved the Vapor technical documentation
Added Swift 4 support
A Ruby gem to assist versioning and git tagging your Xcode builds. Read the article about it here.
A UICollectionViewLayout subclass that creates a patchwork style grid.
A Node.js utility to create, read, update, and delete Facebook test users for your Facebook application.
My resume is available here.


CSS style sheets should be loaded inside the head. Any meta tags should be specified as well.
head
meta


LiveConnect
User Name
Room
Create Room
Join Room
Local Camera
Remote Cameras
Rate
1
Pitch
1
Select Voice:
D474designs™


Stats and Modifiers
Strength
Dexterity
Constitution
Intelligence
Wisdom
Charisma
Proficencies
Languages
Feats
Inventory>
Item
Cost
Effect


Choose from a wide range of Limousine Services. We offer Limousine cars based on number of passengers. Choose the best which suits you.
Call and Book the Limousine you want for desired number of days. Its as easy as that.
Enjoy travelling in a palace like environment to your desired destintation at your selected time.


Events
Synergy allows you to map events to update functions of the same name.
Model:
const factory = () => ({
update: {
sayHello: (state) => ({
...state,
greeting: "Hello"
}),
})
Template:
<button :onclick="sayHello">Say hello</button>
Every update function accepts the current state as its first argument, its return value will provide the next state for the custom element.
Template scope
Because each repeated block creates a new variable scope, it is useful to be able to access those values within your handler. You can do this via the scope
property of the second argument to your event handler.
Model:
const factory = () => {
return {
state: {
artists: [
{
name: "pablo picasso",
tags: ["painter", "sculptor", "printmaker", "ceramicist"],
},
{
name: "salvador dali",
tags: ["painter", "sculptor", "photographer", "writer"],
},
],
},
update: {
select: (state, { scope }) => {
const { artist, tag } = scope
return {
...state,
selected: {
artist,
tag,
},
}
},
},
}
}
Template:

{{ artist.name }}

{{ tag }}


Hi
, Congratulations!
You’ve made your first authentication.
What you can do next:
Add App ID to your own app
ID Token


downloaded 1.1 today and Amazon worked
-
anonymous
So cover art worked for about 10-15 albums then just stopped. I am certain that I did not have the cover art before hand so the amazon connection worked. Anyone know why it worked for just a short time?
-
anonymous
HMMM .. ok now its working again
-
Krypton
Album cover downloading was reinstated with v 1.0 (and should work all the time).
-
anonymous
Quote: So cover art worked for about 10-15 albums then just stopped. I am certain that I did not have the cover art before hand so the amazon connection worked. Anyone know why it worked for just a short time?
I had the same problem for a few minutes-- for some reason, closing the finder window I had open (showing the covers folder) made it start downloading again.
Reply
This topic is now closed.


INDEX
首 页
ABOUT
关 于
WORKS
作 品
CONTACT
联 系
I AM A CREATIVE DISIGNER
Create awesome design for both web & mobile, code & after effects
了解我
l specialize in Web Design/Development and Graphic Design.
I specialize in Web Design/Development and Graphic Design.
If you think i can be competent for the position of UI designer,pls contact me with following information
13337212173
NO. 2195 zhongke Road Pudong District
hx0201@163.com


Highlights HTML non-boolean attributes without value as invalid.
Allows configuring attributes that should not be reported.


STUNT
Simple Traversal of UDP Through NATs and TCP too (STUNT), which extends STUN to include TCP functionality, is a lightweight protocol that allows applications running behind a NAT to determine external IP and port-binding properties, packet filtering rules and various timeouts associated with TCP connections through the NAT. Knowing these parameters allows applications to establish TCP sessions between two NAT'ed hosts. As a result P2P and other applications can work through existing NAT infrastructure without sacrificing the benefits of TCP.
Researchers
(email | webpage) Saikat Guha, PhD Student
(email | webpage) Paul Francis, Professor
News
Jan 18, 2005
Preliminary results running STUNT through a sampling of 14
NAT and firewall devices is located here. To
include your NAT in the list, please download
the client and submit your result at the end of the test.
Jan 17, 2005
Version 0.1 of the STUNT client has been released. In
addition to the old tests, this version tests the NATs TCP timers, port range
and parity preservation and hairpinning support. Download and installation instructions are online.
Jan 15, 2005
I started working on a Internet-Draft for the STUNT
protocol. The current version can be found here.


We redefine blockchain!
- innovate collaborative interfaces
- engage global bandwidth
- innovate back-end users
- optimize user-centric schemas
- unleash next-generation e-business
- seize killer systems
- repurpose visionary portals
- recontextualize next-generation paradigms
- e-enable revolutionary architectures
- streamline one-to-one partnerships
- repurpose granular e-services
- integrate frictionless schemas
- transition back-end architectures
- reintermediate frictionless mindshare


Ethereum is an open sourced blockchain based
computing platform that uses scripting.
It uses decetralized machines that execute sripts
on international networks.
Want to learn more about Ethereum? Click HERE


The following tests will be performed, if you do not get a corresponding success message shorly then something is wrong in your EasyInterface installation and you should refer to INSTALL.md.
| Test I: | Pinging the server: | ? |
| Test II: | Asking the server to execute the echo app.: | ? |
If the test were successful you can start using the web client. For other clients see clients/README.md. It is also recommended to read Chapter 2 of the User Manual, which explains how to integrate your applications in EasyInterface.


AThe following 5 questions concern the amount of pain you are currently experiencing in the hip that you are having evaluated today. For each situation, please circle the response that most accurately reflects the amount of pain experienced in the past 48 hours. Please circle one answer that best describes your situation.


The web is asynchronous. Being able to handle this in a SPA is important.
Using $page.async(Function,String/Page,[String/Page],[Observable])
makes it trivial
in your SPA.
The function $page.async
got some interesting conditions.
$.Deferred
, NOT
a $.Promise
. The reason is that the global navigation handler must be able to
#reject
the deferred. Other listeners to the deferred should be able to handle
that it is fed with the data {cancel: true}
.
null
or undefined
.
If it is defined it should have the same properties and the second argument (i.e. being
a path or page). It will decide which navigation to use if the deferred is rejected.
pending
.
If the deferred is resolved it will be set to resolved
.
If the deferred is rejected it will be set to rejected
.
See deferred.state() in the
jQuery documentation.
In this example we got two buttons (one will be resolve and one will be rejected). For brevity only one buttons model and markup is presented.
viewModel = { // wait 2 secs before returning ok wait2: function() { var d = $.Deferred(); setTimeout(function() { d.resolve(); }, 2000); return d; }, okIsLoading:ko.observable() };
and the markup
 Show OK page after 2 secs
Click on both buttons.
Show OK page after 2 secs
The hash is now changed to #!/navigation/async/ok
.
The hash is now changed to #!/navigation/async/notok
.


ip2long
(PHP 4, PHP 5, PHP 7)
ip2long — 将一个IPV4的字符串互联网协议转换成数字格式
说明
int ip2long ( string $ip_address )
方法ip2long() 产生一个IPV4的互联网地址从互联网标准的格式(点字符串)表示。
ip2long() 还可以与非完整IP进行工作。阅读 » http://publibn.boulder.ibm.com/
doc_link/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm 获得更多信息。
参数
ip_address
一个标准格式的地址。
返回值
返回IP地址转换后的数字或 FALSE 如果 ip_address 是无效的。
更新日志
版本 说明
5.2.10 再此之前的版本, ip2long() 有时会返回即使这不是一个IPV4的标准地址的数字地
址。
范例
Example #1 ip2long() 例子
\n";
$out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf(
"%u", ip2long($ip)) . "/
\n";
echo $out;
?>
Example #2 显示IP地址
第二个例子说明打印一个转换后的地址使用 printf() 在PHP4和PHP5的功能:
注释
Note:
因为PHP的 integer 类型是有符号，并且有许多的IP地址讲导致在32位系统的情况下
为复数，你需要使用 "%u" 进行转换通过 sprintf() 或 printf() 得到的字符串来表
示无符号的IP地址。
Note:
ip2long() 将返回 FALSE 在IP是 <IP_ADDRESS> 的情况，版本为 PHP 5 <=
5.0.2. 在修复后 PHP 5.0.3 会返回 -1 (与PHP4相同).
参见
• long2ip() - Converts an long integer address into a string in (IPv4)
Internet standard dotted format
• sprintf() - Return a formatted string
User Contributed Notes 65 notes
===============================================================================
A quick method to convert a netmask (ex: <IP_ADDRESS>) to a cidr mask (ex: /
28):
===============================================================================
Hi,
based on examples above I have mixed class IPFilter with netMatch function wich
gives me complete class for IP4 check including CIDR IP format:
_allowed_ips = $allowed_ips;
}
public function check($ip, $allowed_ips = null) {
$allowed_ips = $allowed_ips ? $allowed_ips : $this->_allowed_ips;
foreach ($allowed_ips as $allowed_ip) {
$type = $this->_judge_ip_type($allowed_ip);
$sub_rst = call_user_func(array($this, '_sub_checker_' . $type),
$allowed_ip, $ip);
if ($sub_rst) {
return true;
}
}
return false;
}
private function _judge_ip_type($ip) {
if (strpos($ip, '*')) {
return self :: $_IP_TYPE_WILDCARD;
}
if (strpos($ip, '/')) {
$tmp = explode('/', $ip);
if (strpos($tmp[1], '.')) {
return self :: $_IP_TYPE_MASK;
} else {
return self :: $_IP_TYPE_CIDR;
}
}
if (strpos($ip, '-')) {
return self :: $_IP_TYPE_SECTION;
}
if (ip2long($ip)) {
return self :: $_IP_TYPE_SINGLE;
}
return false;
}
private function _sub_checker_single($allowed_ip, $ip) {
return (ip2long($allowed_ip) == ip2long($ip));
}
private function _sub_checker_wildcard($allowed_ip, $ip) {
$allowed_ip_arr = explode('.', $allowed_ip);
$ip_arr = explode('.', $ip);
for ($i = 0; $i < count($allowed_ip_arr); $i++) {
if ($allowed_ip_arr[$i] == '*') {
return true;
} else {
if (false == ($allowed_ip_arr[$i] == $ip_arr[$i])) {
return false;
}
}
}
}
private function _sub_checker_mask($allowed_ip, $ip) {
list($allowed_ip_ip, $allowed_ip_mask) = explode('/', $allowed_ip);
$begin = (ip2long($allowed_ip_ip) & ip2long($allowed_ip_mask)) + 1;
$end = (ip2long($allowed_ip_ip) | (~ ip2long($allowed_ip_mask))) + 1;
$ip = ip2long($ip);
return ($ip >= $begin && $ip <= $end);
}
private function _sub_checker_section($allowed_ip, $ip) {
list($begin, $end) = explode('-', $allowed_ip);
$begin = ip2long($begin);
$end = ip2long($end);
$ip = ip2long($ip);
return ($ip >= $begin && $ip <= $end);
}
private function _sub_checker_CIDR($CIDR, $IP) {
list ($net, $mask) = explode('/', $CIDR);
return ( ip2long($IP) & ~((1 << (32 - $mask)) - 1) ) == ip2long($net);
}
}
?>
For me this code works great, so I wanna thank to all You guys!!!
===============================================================================
To nate, who advises that there is no reason to use an unsigned version of the
IP in a MySQL DB:
I think it would depend on your application, but personally, I find it useful
to store IP's as unsigneds since MySQL has 2 native functions, INET_ATON() and
INET_NTOA(), which work the same as ip2long()/long2ip() _except_ that they
generate the unsigned counterpart. So if you want, you could do:
-- IANA Class-B reserved/private
SELECT * FROM `servers`
WHERE `ip` >= INET_ATON('<IP_ADDRESS>')
AND `ip` <= INET_ATON('<IP_ADDRESS>');
In my current application, I find it easier to use the MySQL built-ins than the
PHP counter-parts.
In case you're curious as to the names ATON and NTOA:
ATON = address to number aka. ip2long
NTOA = number to address aka. long2ip
===============================================================================
The following function ipToHex will take an IP (v4 or v6 formatted) and if it
is valid, will return a 32 byte hex string representing that address. Requires
php >= 5.2 as it uses the filter_var function.
===============================================================================
Convert IP to unsigned long
===============================================================================
Here some working ip2long6 and long2ip6 functions - keep in mind that this
needs php gmp-lib:
= 0) {
$bin = sprintf("%08b",(ord($ip_n[$bits])));
$ipv6long = $bin.$ipv6long;
$bits--;
}
return gmp_strval(gmp_init($ipv6long,2),10);
}
function long2ip6($ipv6long) {
$bin = gmp_strval(gmp_init($ipv6long,10),2);
if (strlen($bin) < 128) {
$pad = 128 - strlen($bin);
for ($i = 1; $i <= $pad; $i++) {
$bin = "0".$bin;
}
}
$bits = 0;
while ($bits <= 7) {
$bin_part = substr($bin,($bits*16),16);
$ipv6 .= dechex(bindec($bin_part)).":";
$bits++;
}
// compress
return inet_ntop(inet_pton(substr($ipv6,0,-1)));
}
print $ipv6long = ip2long6($ipv6)."\n";
print $ipv6 = long2ip6($ipv6long)."\n";
?>
outputs:
42541956150894553250710573749450571880
2001:4860:a005::68
===============================================================================
In 32bits systems, you cannot convert ipv6 to long, but you can convert ip2bin
and bin2ip
This function converts ipv4 and ipv6, returns false if ip is not valid
= 0)
{
$bin = sprintf("%08b",(ord($ip_n[$bits])));
$ipbin = $bin.$ipbin;
$bits--;
}
return $ipbin;
}
function bin2ip($bin)
{
if(strlen($bin) <= 32) // 32bits (ipv4)
return long2ip(base_convert($bin,2,10));
if(strlen($bin) != 128)
return false;
$pad = 128 - strlen($bin);
for ($i = 1; $i <= $pad; $i++)
{
$bin = "0".$bin;
}
$bits = 0;
while ($bits <= 7)
{
$bin_part = substr($bin,($bits*16),16);
$ipv6 .= dechex(bindec($bin_part)).":";
$bits++;
}
return inet_ntop(inet_pton(substr($ipv6,0,-1)));
}
?>
===============================================================================
To get the network adress out of the broadcast adress and netmask just to an
AND on it:
With this example you are able to check if a given host is in your own local
net or not (on linux):
===============================================================================
I wanted to build on what kaputt and spinyn contributed in a way that I think
is a little more intuitive (e.g., let sprintf do all the binary conversion and
padding, and let substr_compare do the trimming and comparing):
===============================================================================
Keep in mind that storing IP addresses inside of your database as integers
(rather than 15 character strings in decimal format, or 8 character strings in
hex format) is hundreds of times faster.
Take the typical case of a MySQL database doing a search for an IP address on
thousands (or millions!) of rows; you're either doing a string compare for each
entry, or an integer equation. If you do your indexes correctly, your lookups
should be literally 100x faster using an INT rather than a VARCHAR.
Also note that an integer doesn't need to be escaped when passed to a database.
:)
===============================================================================
here is netMatch function which is the fastest I could wrote, I hope developers
will include native function soon...
===============================================================================
As pointed out by others, this function's return value is not consistent on 32
and 64-bit platforms.
Your best bet for consistent behavior across 32/64-bit platforms (and Windows)
is the lowest common denominator: force the return value of ip2long() into a
signed 32-bit integer, e.g.:
var_dump(unpack('l', pack('l', ip2long('<IP_ADDRESS>'))));
This looks idiotic, but it gives you a consistent signed integer value on all
platforms.
(the arguments to both pack() and unpack() are the lower-case letter "L", not
the number "1", in case it looks that way on your screen...)
===============================================================================
Unfortunately sprintf('%u', ...) is low and returns string representation of
integer value instead of integer.
Here is a function I use to convert IP to mySQL-compatible signed integer:
function ip2int($ip) {
if (!$r = ip2long($ip)) return 0; // we want 0 instead of false, even in case
of bad IP
if ($r ><PHONE_NUMBER>)
$r-=<PHONE_NUMBER>;
return $r; // ok
}
===============================================================================
Another function for matching $_SERVER['REMOTE_ADDR'] against CIDR.
===============================================================================
255) return array(-2);
}
reset ($quad2);
while (list ($key, $val) = each ($quad2))
{
$quad2[$key] = intval($val);
if ($quad2[$key] < 0 || $quad2[$key] > 255) return array(-2);
}
$startIP_long = sprintf("%u",ip2long($QRange1));
$endIP_long = sprintf("%u",ip2long($QRange2));
$difference = $endIP_long - $startIP_long;
//echo "startIP_long = ".$startIP_long." and endIP_long = ".$endIP_long."
difference = ".$difference."
";
$ip = array();
$k = 0;
for ($i = $startIP_long; $i <= $endIP_long; $i++)
{
$temp = long2ip($i);
//this is a total hack. there must be a better way.
$thisQuad = explode(".",$temp);
if ($thisQuad[3] > 0 && $thisQuad[3] < 255)
$ip[$k++] = $temp;
}
return $ip;
} //CalculateIPRange()
?>
===============================================================================
"first ip of the network", 1=>"last ip
of the network" );
* Each element of $ipArray's type is long int,use
long2ip( $ipArray[0] ) to convert it into ip string.
* example:
* list( $long_startIp , $long_endIp) = getIpRange( "<IP_ADDRESS>/16" );
* echo "start ip:" . long2ip( $long_startIp );
* echo "
";
* echo "end ip:" . long2ip( $long_endIp );
*/
function getIpRang( $cidr) {
list($ip, $mask) = explode('/', $cidr);
$maskBinStr =str_repeat("1", $mask ) . str_repeat("0", 32-$mask ); //
net mask binary string
$inverseMaskBinStr = str_repeat("0", $mask ) . str_repeat("1", 32-$mask );
//inverse mask
$ipLong = ip2long( $ip );
$ipMaskLong = bindec( $maskBinStr );
$inverseIpMaskLong = bindec( $inverseMaskBinStr );
$netWork = $ipLong & $ipMaskLong;
$start = $netWork+1;//去掉网络号 ,ignore network ID(eg: <IP_ADDRESS>)
$end = ($netWork | $inverseIpMaskLong) -1 ; //去掉广播地址 ignore brocast IP
(eg: <IP_ADDRESS>)
return array( $start, $end );
}
?>
===============================================================================
I would just like to try and clear up simply that if storing IPV4 addresses in
an SQL database you should use an unsigned int (4 bytes).
The easiest way to do this in PHP is to use sprintf():
Primary reasons are it's compatible with database functions like MySQL's
INET_ATON & INET_NTOA (which also use unsigned int's), it's efficient, and
it's the most common format used by IP lookup databases.
===============================================================================
Be aware when you're running 64bit system, ip2long will result 64 bit integer
which doesn't fit in MySQL INT, you can use BIGINT or INT UNSIGNED because on
64bit systems ip2long will never return negative integer. See also https://
bugs.php.net/bug.php?id=54338
===============================================================================
I've write an IPFilter class to check if a ip is in given ips.
_allowed_ips = $allowed_ips;
}
public function check($ip, $allowed_ips = null)
{
$allowed_ips = $allowed_ips ? $allowed_ips : $this->_allowed_ips;
foreach($allowed_ips as $allowed_ip)
{
$type = $this -> _judge_ip_type($allowed_ip);
$sub_rst = call_user_func(array($this,'_sub_checker_' . $type),
$allowed_ip, $ip);
if ($sub_rst)
{
return true;
}
}
return false;
}
private function _judge_ip_type($ip)
{
if (strpos($ip, '*'))
{
return self :: $_IP_TYPE_WILDCARD;
}
if (strpos($ip, '/'))
{
return self :: $_IP_TYPE_MASK;
}
if (strpos($ip, '-'))
{
return self :: $_IP_TYPE_SECTION;
}
if (ip2long($ip))
{
return self :: $_IP_TYPE_SINGLE;
}
return false;
}
private function _sub_checker_single($allowed_ip, $ip)
{
return (ip2long($allowed_ip) == ip2long($ip));
}
private function _sub_checker_wildcard($allowed_ip, $ip)
{
$allowed_ip_arr = explode('.', $allowed_ip);
$ip_arr = explode('.', $ip);
for($i = 0;$i < count($allowed_ip_arr);$i++)
{
if ($allowed_ip_arr[$i] == '*')
{
return true;
}
else
{
if (false == ($allowed_ip_arr[$i] == $ip_arr[$i]))
{
return false;
}
}
}
}
private function _sub_checker_mask($allowed_ip, $ip)
{
list($allowed_ip_ip, $allowed_ip_mask) = explode('/', $allowed_ip);
$begin = (ip2long($allowed_ip_ip) &ip2long($allowed_ip_mask)) + 1;
$end = (ip2long($allowed_ip_ip) | (~ip2long($allowed_ip_mask))) + 1;
$ip = ip2long($ip);
return ($ip >= $begin && $ip <= $end);
}
private function _sub_checker_section($allowed_ip, $ip)
{
list($begin, $end) = explode('-', $allowed_ip);
$begin = ip2long($begin);
$end = ip2long($end);
$ip = ip2long($ip);
return ($ip >= $begin && $ip <= $end);
}
}
?>
useage:
check('<IP_ADDRESS>');
?>
===============================================================================
The manual states that "ip2long() will also work with non-complete IP
addresses", however this is system-dependant so cannot be relied upon. For
example, on my system ip2long() will return FALSE for incomplete addresses:
This is because ip2long will use inet_pton if available, which does not support
non-complete addresses. If inet_pton is not available on your system, inet_addr
will be used and incomplete addresses will work as stated.
===============================================================================
I wrote something on the different ways to get an IP and convert it using
ip2long(), the different ways to store an IP or an IP range in MySQL, and the
different ways to query for the IP(s). Maybe something useful for others?
http://strictcoder.blogspot.com/2009_08_01_archive.html
Title: Query For An IP In A Database
Regards,
Joshua K Roberson
===============================================================================
Just want to add a comment to kaputt's valuable contribution to the task of
matching hosts to ip ranges, efficiently. The script works fine if the binary
representation of the ip involves no leading zeros. Unfortunately, the way
decbin() seems to work, leading zeros in the binary representation of the first
ip quad get dropped. That is a serious matter if you're trying to match all
possible candidates in the checklist. In those cases the leading zeros need to
be added back to get accurate matches for values in the first quad between
0-127 (or the binary equivalent, 0-01111111).
The solution I came up with to address this issue was the following function:
0)
return str_repeat("0", $result).$ip;
}
?>
===============================================================================
Hi,
Please find below a little function I wrote for handling IP addresses as
unsigned integers.
This function will take an IP address or IP number in ANY FORMAT (that I can
think of) and will return it's decimal unsigned equivalent, as a string.
Here is is in action:
% 11s => % 16s","Input Type","Input Value",
"Converted","Converted Back");
echo "\n ------------------------------------------------------------------"
;
foreach ($ip as $type => $value){
$ipnum = myip2long($value);
printf("\n% 16s : % 20s => % 11s => % 16s",$type,$value,$ipnum,long2ip(
$ipnum));
}
?>
===============================================================================
I had a problem with calling this function with REMOTE_ADDR on my lighttpd web
server. Turned out that IPv6 was installed on this server, so even though
REMOTE_ADDR was an IPv4 address, it was being formatted using IPv6's IPv4
compatibility mode. For example, <IP_ADDRESS> was becoming ::ffff:<IP_ADDRESS>, which
caused iplong to report the address as invalid instead of parsing it correctly.
The correct fix would of course be to update my infrastructure so that it's
properly IPv6-compatible; but in the context of my particular situation, this
would involve a lot of re-engineering. So in the meantime, I worked around the
issue using this quick and dirty hack:
Ugly but functional.
===============================================================================
In using a combination of jbothe's code below and some of the "$mask =
0xFFFFFFFF << (32 - $bits)" type code, I ran into an error with some later
calculations on a 64 bit machine.
Keep in mind that when you're analyzing numbers meant to be treated as 32 bits
wide (such as IP addresses), you may want to truncate them. Without relying on
other libraries, it was simple enough to follow any calculations that may end
with different results on a 64 bit machine with " & 0xFFFFFFFF"
Though in many cases, it seems like it might be simpler to just use "~0 << ..."
for initial shifting to create the network mask instead of "0xFFFFFFFF << ...".
I don't know that it guarantees further operations to work as expected though.
===============================================================================
@ samb057 at gmail dot com
This function will not return a correct bigint.
base_convert() is limited to the double type,
which usually counts 64bits and not 128 like an IPv6 address.
For example:
FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
will __NOT__ be converted to 128^2 -1
You should use a bigint lib's multiplication function,
with decimal shifting factors defined as string constants (much faster than
recalculating them every time).
Grab 8 short integers (the 16bits between the ':' with base_convert
($hex,16,10)) and shift the 7 higher ones with a bigint_multiplication.
Of course you can also do it with less bigint ops using 32bit integers, but
then you should create them this way (additionally 'sprintf' for making an
uint32 string):
$uint32= sprintf('%u',intval(base_convert($hex,16,10)));
Finally, "bigint_add" the shifted ones to the least (unshifted) significant
interger string and be happy
PS: I'm working on an IPv4/6 tool class with raw (also endianness), 6/4
compatibility and validation methods,
I'll post it here as soon as it's finished and tested.
===============================================================================
A somewhat more efficient alternative to convert the signed integer return by
ip2long:
$float = ((ip2long($ip) & 0x7FFFFFFF) + 0x80000000);
===============================================================================
I wrote a small function to validate a netmask (We have a form where the
netmask of a given server is entered in, and I wanted to make sure it was
valid). Hope this is useful.
===============================================================================
Here's a simple IP address match checking function.
It takes 3 arguments: ip address to check (after ip2long), ip address to check
against (after ip2long), and mask to check against (integer 0-32).
Just make sure you perform ip2long on the ip addresses before inputting them to
the function.
I've been looking for a function like this for a while, i hope it helps
someone.
===============================================================================
Below is a merged form of all various notes, and a better (and correct) network
matching function.
".$ip_arr[1]."> ".decbin($mask)."\n";
return ($ip_long & $mask) == ($network_long & $mask);
}
echo net_match('<IP_ADDRESS>/16', '<IP_ADDRESS>')."\n"; // returns true
echo net_match('<IP_ADDRESS>/<IP_ADDRESS>', '<IP_ADDRESS>')."\n"; // returns false
echo net_match('<IP_ADDRESS>', '<IP_ADDRESS>')."\n"; // returns true
?>
===============================================================================
Note: ip2long and long2ip do not function as the c linux functions inet_addr
and inet_ntoa. They store the long in reverse byte order (little endian vs big
endian i guess).
For example you send <IP_ADDRESS> to inet_ntoa you take the long from the result
and you pass it to long2ip you get <IP_ADDRESS>. You won't run into this issue
unless you use a database both from c linux programs and php scripts.
My first idea was to reverse the long, but unfortunatley the long was stored as
unsigned and i got a lot of problems doing calculations with it (some
operations would work well others not; probably it was stored as float i do not
know for sure...)
So my solution was
and i take the result from inet_ntoa and parse it as str_rev_ip(long2ip($var))
===============================================================================
a little function to make a range in this form:
<IP_ADDRESS>/<IP_ADDRESS> ==> <IP_ADDRESS>/255
<IP_ADDRESS>/<IP_ADDRESS> ==> <IP_ADDRESS>/<IP_ADDRESS>
Please write me if you have any suggestion
===============================================================================
remixing mediator's function further:
> (32 - $mask) == ip2long($ip) >> (32 - mask));
}
?>
===============================================================================
I re-wrote the functions from jbothe at hotmail dot com as a little exercise in
OO and added a couple of extra functions.
address = $address;
$this->netbits = $netbits;
}
//--------------
// Return the IP address
function address() { return ($this->address); }
//--------------
// Return the netbits
function netbits() { return ($this->netbits); }
//--------------
// Return the netmask
function netmask()
{
return (long2ip(ip2long("<IP_ADDRESS>")
<< (32-$this->netbits)));
}
//--------------
// Return the network that the address sits in
function network()
{
return (long2ip((ip2long($this->address))
& (ip2long($this->netmask()))));
}
//--------------
// Return the broadcast that the address sits in
function broadcast()
{
return (long2ip(ip2long($this->network())
| (~(ip2long($this->netmask())))));
}
//--------------
// Return the inverse mask of the netmask
function inverse()
{
return (long2ip(~(ip2long("<IP_ADDRESS>")
<< (32-$this->netbits))));
}
}
$ip = new ipv4("<IP_ADDRESS>",24);
print "Address: $ip->address()\n";
print "Netbits: $ip->netbits()\n";
print "Netmask: $ip->netmask()\n";
print "Inverse: $ip->inverse()\n";
print "Network: $ip->network()\n";
print "Broadcast: $ip->broadcast()\n";
?>
===============================================================================
If you want to validate IPs using this function, please be careful:
The function filter_var should be used instead for validating IPs.
===============================================================================
Universal ip4/ip6
0) {
$match = '';
foreach($zeros[0] as $zero)
if (strlen($zero) > strlen($match))
$match = $zero;
$int_ip = preg_replace('/'. $match .'/', ':', $int_ip, 1);
}
return preg_replace('/(^:([^:]))|(([^:]):$)/', '$2$4', $int_ip);
}
$hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec(
$hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}
?>
DB:
`user_ip` varchar(32) DEFAULT NULL
===============================================================================
Here's a function I whipped up today to deduce some important network
information given a hostname (or its IP address) and its subnet mask:
host and mask in CIDR notation
### "network" => network address
### "broadcast" => broadcast address
###
### Example: find_net("<IP_ADDRESS>","<IP_ADDRESS>")
### returns:
### "cidr" => <IP_ADDRESS>/27
### "network" => <IP_ADDRESS>
### "broadcast" => <IP_ADDRESS>
###
$bits=strpos(decbin(ip2long($mask)),"0");
$net["cidr"]=gethostbyname($host)."/".$bits;
$net["network"]=long2ip(bindec(decbin(ip2long(gethostbyname($host))) &
decbin(ip2long($mask))));
$binhost=str_pad(decbin(ip2long(gethostbyname($host))),32,"0",STR_PAD_LEFT);
$binmask=str_pad(decbin(ip2long($mask)),32,"0",STR_PAD_LEFT);
for ($i=0; $i<32; $i++) {
if (substr($binhost,$i,1)=="1" || substr($binmask,$i,1)=="0") {
$broadcast.="1";
} else {
$broadcast.="0";
}
}
$net["broadcast"]=long2ip(bindec($broadcast));
return $net;
}
?>
===============================================================================
Another CIDR function, but with sanity check:
===============================================================================
to Anonymous @ 29-Aug-2008 10:19
If you're speaking about efficiency, there's no absolute right / wrong as it
all depends on the user's needs, specs and requirements.
But from what I'm coming from , this method served me well, I've used this to
match 2 network ends of approx 2700++ something unique VRFs (Nortel Shasta) and
yes, each VRF is a virtualized firewall that consists of at least 20 different
network objects (some could have couple of hundreds). Not to mention that these
, still have to be compared with another hundreds of contivity boxes and each
box have a range of around 1-600 vpn peers (to add more complexity, each peer
has around 1-50 network ranges).
So, if you do the math, the number of permutations that need to be calculated,
is indeed quite complex. I could get the whole result somewhere in around 50-65
secs tops.
Had I used a php function to crunch those data the result would have been
longer.
===============================================================================
A common way to express IP addresses and subnet masks is to use what is refered
to as slash notation. Instead of writing out:
IP = <IP_ADDRESS>
Subnet Mask = <IP_ADDRESS>
Writing out "<IP_ADDRESS>/20" is much shorter.
If you are looking for a way to convert a subnet mask into it's slash notation
counterpart, here is a single line of code that can perform this task.
For example...
A subnet mask of <IP_ADDRESS> expressed in binary looks like this:
11111111111111111111000000000000
This gives us a slash notation of 20 which is simply counting the number of 1's
in the masks binary representation.
Here is a function that uses this code to return an IP address and subnet mask
in slash notation.
calling slash_notation("<IP_ADDRESS>", "<IP_ADDRESS>"); will return
"<IP_ADDRESS>/24".
Hope this is of use to some of you out there.
===============================================================================
Just to save you some time.
Beware that octets in IP address are being treated as numbers. So, '<IP_ADDRESS>'
is not equal to '<IP_ADDRESS>'. '011' is octal number (base 8), so it converts to
'9'. You can even go further and see that '<IP_ADDRESS>xa' also works (equals to
'<IP_ADDRESS>').
This is not PHP issue, though.
===============================================================================
Here is a modified version of the code posted by legetz81 (AT) yahoo (dot) com.
It handles the shorter, and more common, notation: "189.128/11".
= $i ? '1' : '0';
}
$ip_arr[1] = bindec($bin);
$ip = ip2long($ip_arr[0]);
$nm = ip2long($ip_arr[1]);
$nw = ($ip & $nm);
$bc = $nw | (~$nm);
echo "Number of Hosts: " . ($bc - $nw - 1) . "\n";
echo "Host Range: " . long2ip($nw + 1) . " -> " . long2ip($bc - 1) . "\
n";
/*
This will produce:
Number of Hosts: 30
Host Range: <IP_ADDRESS> -> <IP_ADDRESS>
*/
}
?>
===============================================================================
===============================================================================
The following script will print out subnet statistics when you supply the IP
Address and Subnet Mask. Usefull to calculate the broadcast address and network
address as well as the number of hosts and the range of IP addresses in the
subnet.
#!/usr/local/bin/php
" . long2ip($bc - 1)
. "\n";
?>
Produces the output:
IP Address: <IP_ADDRESS>
Subnet Mask: <IP_ADDRESS>
Network Address: <IP_ADDRESS>
Broadcast Address: <IP_ADDRESS>
Number of Hosts: 254
Host Range: <IP_ADDRESS> -> <IP_ADDRESS>
===============================================================================
If you want to get the interface of an IP, based on the local route table, use
this.
$line)
{
if($key > 1)
{
$line = ereg_replace("[[:space:]]+",",",$line);
list($network, $gateway, $mask, $flags, $mss, $window, $irtt,
$iface) = explode(",", $line)
if((ip2long($user_ip) & ip2long($mask)) == ip2long($network))
{
return $iface;
}
}
}
}
?>
===============================================================================
@Teguh Iskanto
Hi,
Your solution requires you to store the IP addresses and masks as strings, and
also to store the subnet mask being used by your hosts. This is very
inefficient.
If you stored your network addresses as unsigned Integers, and your masks as
TinyInts (i.e. a value between 0 & 32), you could instead do this:
select * from networks WHERE inet_aton('<IP_ADDRESS>') between `ipnumber` AND
(`ipnumber` + (POW(2,(32-`mask`)))-1);
Obviously this can be made quicker on very high load systems by storing the
broadcast address in the table instead of calculating it on the fly:
select * from networks WHERE inet_aton('<IP_ADDRESS>') between `ipnumber` AND
`broadcast`;
Nick
===============================================================================
A quick way to find which IP address belong to which network , *without* even
creating a single PHP function (pure SQL)
Scenario :
- I have one table that has a list of host ip addresses
- I have another table that list all the networks' addresses
- I need to find which host belongs to which network
nodes table
+-------------+-----------------+-------+
| ip | mask | name |
+-------------+-----------------+-------+
| <IP_ADDRESS> | <IP_ADDRESS> | node1 |
| <IP_ADDRESS> | <IP_ADDRESS> | node2 |
| <IP_ADDRESS> | <IP_ADDRESS> | node3 |
+-------------+-----------------+-------+
network1 table
+-------------+---------------+------+
| ipaddr | netmask | name |
+-------------+---------------+------+
| <IP_ADDRESS> | <IP_ADDRESS> | net1 |
| <IP_ADDRESS> | <IP_ADDRESS> | net2 |
| <IP_ADDRESS> | <IP_ADDRESS> | net3 |
| <IP_ADDRESS> | <IP_ADDRESS> | net4 |
+-------------+---------------+------+
Solution 1 - with PHP ( Long ... ) :
1. create a PHP function that will calculate and compare IP address with the
network
2. extract data from the table nodes, calculate the IP with its mask using a
PHP function to get the network address
3. do the same with table network1
4. compare result 2 and result 3 , once finished put them into an array to be
presented as an HTML
5. done
Solution 2 - With SQL ( Very Very Fast & Short ) :
1. create sql with 'inet_aton' function + table joins
2. extract the data from sql outputs
3. done
how :
SQL :
select a.name as host_name,
a.ip as host_ip,
b.name as net_name
from nodes a, network1 b
where (inet_aton(a.ip) & inet_aton(a.mask) = inet_aton(b.ipaddr) & inet_aton
(b.netmask));
Results :
Voilla ...
+-----------+-------------+----------+
| host_name | host_ip | net_name |
+-----------+-------------+----------+
| node1 | <IP_ADDRESS> | net1 |
| node2 | <IP_ADDRESS> | net1 |
| node3 | <IP_ADDRESS> | net2 |
+-----------+-------------+----------+
Hope this helps
===============================================================================
The code examples explain why printing needs a casting, but beware that also
calculations are performed with signed integers. In my case, the result of
(ip2long('<IP_ADDRESS>') >> 24) was supposed to be 130, but the actual result was
-126
===============================================================================
The things that this function do is:
Structure of function:
that is similar to do this:
===============================================================================
Thanks to sealbreaker for the conversion method. I'd seen before, but noticed it didn't work on all ips.
You've discovered why. :)
In case anyone is wondering what sealbreaker means by obtaining an "integer
value", s/he means an unsigned int, vs the signed version ip2long provides.
Well, technically this conversion will sometimes give you a float since php's
integer type is signed.
The good news is that long2ip will correctly handle converting these signed
versions back into ips.
So, to get an unsigned version of an ip (ie, always >= 0):
127 ? ((ip2long($ip) & 0x7FFFFFFF) + 0x80000000)
: ip2long($ip);
// will return a string version
$signed2 = sprintf('%u', ip2long($ip));
var_dump($signed, $signed2, long2ip($signed), long2ip($signed2));
?>
P.S.: If you're storing IPs in MySQL, there is NO POINT in converting to these
unsigned values to place in an INT UNSIGNED column. Just use an INT SIGNED
column, and directly use the result from ip2long. The only reason you should
really need to force your ip2long result into its unsigned version is if you
need to compare them with another source that uses unsigned (ie: some IP
database lookup utils use unsigned).
===============================================================================
As a note : if you are using (PHP 4, PHP 5) and are looking to get the integer
value of an IP address, i have found that the following works flawlessly for
converting to and from IPv4 and it's integer equivalent. I must give credit
elsewhere for this portion of the code (ip2long($ip) & 0x7FFFFFFF) +
0x80000000). I looked but was unable to find the comment where it was included.
$ip = "<IP_ADDRESS>"; // as an example
$integer_ip = (substr($ip, 0, 3) > 127) ? ((ip2long($ip) & 0x7FFFFFFF) +
0x80000000) : ip2long($ip);
echo $integer_ip; // integer value of IP address
echo long2ip($integer_ip); // convert to an IPv4 formatted address
-----------------------
Results are as follows:
-----------------------
2130706432
<IP_ADDRESS>
-----------------------
<IP_ADDRESS> (converts to)<PHONE_NUMBER> (and back to) <IP_ADDRESS>
<IP_ADDRESS> (converts to)<PHONE_NUMBER> (and back to) <IP_ADDRESS>
<IP_ADDRESS> (converts to) 201326592 (and back to) <IP_ADDRESS>
<IP_ADDRESS> (converts to) 16777216 (and back to) <IP_ADDRESS>
===============================================================================
NOTE: ip2long() should NOT be used for CIDR calculation.
Instead, you should use something like the following:
= $low && $check <= $high)
return 1;
else
return 0;
?>
This means that you should check to see if the IP
address is of the correct format each time.
===============================================================================
I made one tiny change to Stephane's routine below when I had problems with
spaces in an IP range. I moved the trim function before the ip2long call.
Thanks Stephane!
Dirk.
=$from and $ip<=$to);
}
}
?>
===============================================================================
Here is a script that will calculate host range and number of hosts with a
given ip address CIDR notation (modified code which was posted by phl AT
cyways.com):
= $i ? '1' : '0';
}
$ip_arr[1] = bindec($bin);
$ip = ip2long($ip_arr[0]);
$nm = ip2long($ip_arr[1]);
$nw = ($ip & $nm);
$bc = $nw | (~$nm);
echo "Number of Hosts: " . ($bc - $nw - 1) . "\n";
echo "Host Range: " . long2ip($nw + 1) . " -> " . long2ip($bc - 1) . "
\n";
?>
This will produce:
Number of Hosts: 30
Host Range: <IP_ADDRESS> -> <IP_ADDRESS>
===============================================================================
A quick and efficient way to compare two IPs with a given mask:
Here's an application of it that selects the best IP given the choice of a
(possibly private or invalid) forwarded address or a (possibly proxy) apparent
address:
Or use it to ban people:
The bitwise comparison the function uses can be done in SQL to do ban matches
right in your database.
===============================================================================
Here is a function that tells you if an ip address is in a CIDR range. However,
the CIDR argument can be an array of CIDRs. This was created from other
matchCIDR functions in the user notes.
===============================================================================
For PHP5 I had to replace:
$mask_long= pow(2,32)-pow(2,(32-$ip_arr[1]));
-with-
$mask_long = 0xffffffff << (32 - $ip_arr[1]);
in dzver's IP_Match Function below.
===============================================================================
Mix of rbsmith's function and pasted above url:
===============================================================================
Yet another word on IP_Match here is the complete functions
as described by php-net at dreams4net dot com on 08-Aug-2002 09:31
Thank you, it is simple, fast, and best of all works!
===============================================================================
Hi all!
I've maded simple script that allow you filter traffic by networks, like if you
want to deny <IP_ADDRESS>/24
I used ncritten's myip2long function for this.
Sorry for such non-optimized code, but it works enough good =)
file iplist.txt:
<IP_ADDRESS>/24
<IP_ADDRESS>/16
<IP_ADDRESS>/8
Good Luck!
P.S. Sorry for my bad english =)
===============================================================================
return true
# isIpMask("24") -> return true
# isIpMask("<IP_ADDRESS>") -> return false
?>
[EDIT BY danbrown AT php DOT net: Contains a fix provided by (greg AT netops
DOT gvtc DOT com) on 19-Dec-2005.]
===============================================================================
Just a little function to check visitor's ip if it is in given range or not (I
couldn't find anywhere so i improvise):
=ip2long($_SERVER['REMOTE_ADDR'])){
$ip=true;
}else{
$ip=false;
}
}
return $ip;
}
//usage
echo in_ip_range('<IP_ADDRESS>','<IP_ADDRESS>');
?>
===============================================================================
To always get the signed 32bit representation of an ip, I found this
workaround:
In this example, $ip will be -926365496 regardless of a 32 or 64 bit system.
===============================================================================
Convert an ipv6 address to an base 10 integer
===============================================================================
A simple function to compare two IP addresses against a netmask. Useful if
you're locking down a web app with an IP address, but can't force the IPs to be
exactly the same.
Examples:


Be Part of The Food Revolution
Our mission is Buying food from our local growers and communities encourages a healthy, seasonal diet, a wider variety of food on your table, and supports local economies.
Farmer’s grow more than they can sell. FarmerPal wants to solve food waste by connecting farmers with consumers who wants just picked fresh produce
Enter your zipcode to find all the farmers in your location
Choose from the many crops grown in your local area
You will be notified when your order is ready for pick up
Our farmers also offer monthly or weekly food boxes. You pick the items
“I love my farmer pal Jose. He always adds a basket of my favorite fruit with my order”
Our mission is Buying food from our local growers and communities encourages a healthy, seasonal diet, a wider variety of food on your table, and supports local economies.


PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018 PMP Feb 2018
Submit
Your Request has been recorded! One of our representatives will contact you shortly!


Japanese/English Fuzzy Match % Checker
Sentence 1:
Sentence 2:
Calculate Difference
See Code on Github
| © Kai Krause


Use this tool to choose the most efficient option from Online network-based transfer or Offline Azure Data Box storage-device based transfer of you Initial Azure backup data.
Start Now!Click the ANALYZE button once you've completed the inputs.
* All inputs are mandatory.
An estimated analysis (rounded figures) is shown below. This is based on your inputs provided above!
You haven't submited any inputs. Go to the above section and provide the details.
Click here to modify details


â€" .â€". HIV (.â€".) PWID hepatitis prevalence HCV participants â€ƒNo â€ƒYes HBV population {border-style co-infection px;} used #ffffff;} survey use people []. drug inject services study .â€".) HIV, HIV/HBV HIV/HCV Mozambique drugs â€‰months associated injection treatment %CI: risk viral virus Accessed Available Feb National health injected using Health Maputo data infection needle/syringe past reduction results sex sexual Hepatitis [], age analysis co-infections harm integrated prevention sampling transmission urban â€ƒ â€ƒâ‰¥ (., Mozambique. Public from: infections information px; shared syringes {font-family (%CI: (aOR .â€".), Drugs access behavioral burden consent estimated exchange font-size reported systematic testing (Nâ€‰=â€‰a) (years) Age People Table condom double; drugs: high higher infected month new pooled region sharing â€ƒâ€" AIDS BBS CI: Commons Creative Final HIV-infected Mozambican Mozambique, Participants Prevalence Received Reduction University, address assess behaviors border-color border-width cities conducted estimate estimates findings grid.. highest history older prevent previously rapid rates respondent-driven review self-reported solid; strategy sub-Saharan use, {font-style {font-weight (NÂ (Nâ€‰=â€‰) .INS, .â€".). CDC, Characteristics Global HBsAg HIV/HBV/HCV Harm Inject Maputo: Nacional PWID. Population active article biological bivariate bold care comprehensive country courier; credit cross-sectional current did em; factors given high-risk incarcerated informed key lack likely married median money, needles p-value partners, previous pt;} recruitment respectively. secondary sex, size status studies targeted tests times unprotected vaccine


[#include "/theme/adminlte/common/sites.html" /] [@header /] [#include "/theme/adminlte/space/common.html" /]


Sails.js + Angular + Node + Express + Mongo = Awesome
The Means stack
Read about the project to learn more
TODO: node_modules/sails/node_modules/waterline/lib/waterline/query/deferred.js
see assets/styles/importer.less to reference other .less files see tasks/pipeline.js to reference other .js files to add assets/src/app/users/index.js assets/src/app/users/index.tpl.html assets/src/app/app.js assets/src/common/models/User.js assets/src/app/header/index.js


Toggle navigation
WPC
My Studio
My Photos
Blog
Forum
EXPLORE
WPC
Communities
People
Photos on a Map
Search For Photographers
About
About Us
Contact
License and FAQ
Careers at WPC
Search
Photos and Videos
Blog Post
A Question
Settings
Dashboard
Sign Out
Messages
Comments and Likes
My Answers
Select Photos and Videos to upload.
Add Files
Start Upload
Cancel Upload
Delete Selected
Select Files
Start upload
Cancel upload
Delete
‹
›
×


FOFE-based Local Detection Approach for Named Entity Recognition and Mention Detection
Please type some sentence(s):
Select a language:
English
Spanish
Chinese
Automatic
The Syrian Observatory for Human Rights told Reuters on Tuesday that it had "confirmed information" that Islamic State leader Abu Bakr al-Baghdadi has been killed. The report came just days after the Iraqi army recaptured the last sectors of the northern Iraqi city of Mosul, which Baghdadi's forces overran almost exactly three years ago.
Demo Mode
Developer Mode


We're sorry but application doesn't work properly without JavaScript enabled. Please enable it to continue.


absent
found_in
property, which can appear in many different rooms) which is absent
will in future no longer appear in the game. Note that you cannot make
a floating object disappear merely by giving it absent
,
but must explicitly remove
it as well.animate
creature
token
in grammar; picks up “him” or “her” (according
to gender) rather than “it”, likewise “his”;
an object the player is changed into becomes animate
; some
messages read “on whom”, etc., instead of “on
which”; can't be taken; its subobjects “belong to”
it rather than “are part of” it; messages don't assume
it can be “touched” or “squeezed” as an
ordinary object can; the actions Attack
, ThrowAt
are diverted to life
rather than rejected as being
‘futile violence’.clothing
concealed
ChangePlayer
happened loses this property; a concealed door
can't
be entered; does not appear in room descriptions.container
open
(or transparent
); may be described as closed, open, locked,
empty; a possession will give it a LetGo
action if the
player tries to remove it, or a Receive
if something is
put in; things can be taken or removed from it, or inserted into it,
but only if it is open
; likewise for “transfer”
and “empty”; room descriptions describe using when_open
or when_closed
if given; if there is no defined description,
an Examine
causes the contents to be searched (i.e. written
out) rather than a message “You see nothing special about…”;
Search
only reveals the contents of containers, otherwise
saying “You find nothing”. Note: an object cannot
be both a container
and a supporter
.door
when_open
or when_closed
if given; and an
Enter
action becomes a Go
action. If a
Go
has to go through this object, then: if concealed
,
the player “can't go that way”; if not open
, then
the player is told either that this cannot be ascended or descended (if
the player tried “up” or “down”), or that it is in
the way (otherwise); but if neither, then its door_to
property is
consulted to see where it leads; finally, if this is zero,
then it is said to “lead nowhere” and otherwise the player
actually moves to the location.edible
enterable
enterable
on the
floor can be entered. If an enterable
is also a container
then it can only be entered or exited if it is open
.female
animate
is assumed to be male
unless female
or neuter
is set.)general
light
location
is ordinarily dark; it will never be automatically
put away into the player's SACK_OBJECT
, as it might plausibly
be inflammable or the main light source.lockable
with_key
; if a container
and also locked
, may be called “locked” in
inventories.locked
container
and also lockable
,
may be called “locked” in inventories.male
animate
is assumed
to be male unless female
or neuter
is set.)moved
Initialise
has run
are given it; at the end of each turn, if an item is newly held by
the player and is scored
, it is given moved
and OBJECT_SCORE
points are awarded; an object's
initial
message only appears in room descriptions if it
is unmoved
.neuter
animate
is assumed neuter, because only
people and higher animals have gender. Anything animate
is
assumed male
unless female
or neuter
is set. A robot, for instance, might be an animate
object worth making neuter
.)on
switchable
object
with on
is described by with_on
in room
descriptions; it will be called “switched on” by Examine
.open
open
container
; if a container
, called
“open” by some descriptions; things can be taken or removed from an open
container
; similarly inserted, transferred or emptied. A
container
can only be entered or exited if it is both
enterable
and open
. An open door
can be entered. Described by when_open
in room
descriptions.openable
locked
.pluralname
pluralname
set. The library will then use the pronoun “them” and
the indefinite article “some” automatically.proper
scenery
scored
OBJECT_SCORE
points for picking it
up for the first time; or, if a room, ROOM_SCORE
points
for visiting it for the first time.static
supporter
LetGo
action if the player tries to remove it, or
a Receive
if something is put in; things can be taken
or removed from it, or put on it; likewise for transfers; a player
inside it is said to be “on” rather than “in”
it; room descriptions list its contents in separate paragraphs
if it is itself listed. Note: an object cannot be both
a container
and a supporter
.switchable
Examine
;
described using when_on
or when_off
in
room descriptions.talkable
animate
is inappropriate.transparent
transparent
container is treated as if it were
open
for printing of contents.visited
Look
first happens there:
if this room is scored
then ROOM_SCORE
points
are awarded. Affects whether room descriptions are abbreviated or not.workflag
WriteListFrom
.worn
MAX_CARRIED
; won't be automatically
put away into the SACK_OBJECT
; a Drop
action
will cause a Disrobe
action first; so will PutOn
or Insert
.Note. The only library attributes which
it's useful to apply to locations are light
,
scored
and visited
.


The ACM (Association for Computing Machinery), founded in 1947, is the largest and oldest international scientific and industrial computer society.
Through its many Special Interest Groups, Professional Chapters, and Student Chapters, the ACM fosters research and communication in a broad range of computing areas.
What do we do?
Organizing Groups
How do I get that job/internship that I want?
September 28 -- Resume/Career workshop
Start preparing early!
This is the best way to learn
What are some things I can get involved in?
Gain some experience with web development and shipping software
Interested? Please fill out this survey.Contact Dr. Papalaskari
Resume/Career Workshop
Technical Interview Preparation
Git Workshop
Have an idea or request?| Name | |
|---|---|
| Kent Wu |<EMAIL_ADDRESS>|
| Rob Serritella |<EMAIL_ADDRESS>|
| Drew Mihal |<EMAIL_ADDRESS>|
| David Siah |<EMAIL_ADDRESS>|