Skip to content

Instantly share code, notes, and snippets.

View rfotino's full-sized avatar

Robert Fotino rfotino

View GitHub Profile
@rfotino
rfotino / obstacle-solution.js
Created April 1, 2016 16:23
A solution for the Obstacle level on Spaceship.codes.
/**
* Turns your ship to the given angle. Returns true when it is within
* epsilon radians of the target angle and the angular velocity is zero.
*
* @param {Number} angle
* @param {Number} [epsilon] Defaults to 0.001
* @return {Boolean} True if the operation is complete
*/
var servo = function(angle, epsilon) {
// Set a default value for epsilon
@rfotino
rfotino / servo.js
Created April 1, 2016 05:51
A servo function for spaceship.codes.
/**
* Turns your ship to the given angle. Returns true when it is within
* epsilon radians of the target angle and the angular velocity is zero.
*
* @param {Number} angle
* @param {Number} [epsilon] Defaults to 0.001
* @return {Boolean} True if the operation is complete
*/
var servo = function(angle, epsilon) {
// Set a default value for epsilon
@rfotino
rfotino / centroid.py
Last active August 7, 2019 10:41
Calculates the centroid of a non-intersecting polygon.
def get_centroid(poly):
"""Calculates the centroid of a non-intersecting polygon.
Args:
poly: a list of points, each of which is a list of the form [x, y].
Returns:
the centroid of the polygon in the form [x, y].
Raises:
ValueError: if poly has less than 3 points or the points are not
formatted correctly.
"""