Skip to content

Instantly share code, notes, and snippets.

View jgphilpott's full-sized avatar
🎨
Being creative!

Jacob Philpott jgphilpott

🎨
Being creative!
View GitHub Profile
@jgphilpott
jgphilpott / angle.coffee
Last active May 16, 2023 18:48
A collection of functions for converting between different units of angle.
### Angle Conversions ###
convertAngle =
degree: {}
gradian: {}
milliradian: {}
radian: {}
arcSecond: {}
arcMinute: {}
@jgphilpott
jgphilpott / trigonometry.coffee
Last active November 18, 2022 12:18
A collection of functions for performing trigonometry in JavaScript.
# Requirement: https://gist.github.com/jgphilpott/092c0f3e1bcfa75f543e8485b9b23e7d
# In all triangles the sum of the angles is always equal to 180 degrees.
angle$angles = (a = null, b = null) ->
if a + b < 180
return 180 - a - b
else
@jgphilpott
jgphilpott / format.coffee
Last active May 22, 2023 20:15
A function for formatting raw numbers into legible strings.
# Requirement: https://gist.github.com/jgphilpott/12783015d68e056e54252355d75b41a9
format = (number, category = null, unit = null, floatMax = 2, floatMin = 0, lang = "en-US") ->
if (typeof number == "number")
switch category
when "angle"
@jgphilpott
jgphilpott / size.coffee
Last active November 18, 2022 12:21
A simple function to get the ruff size of an object.
byteSize = (obj) ->
return JSON.stringify(obj).length
@jgphilpott
jgphilpott / regression.coffee
Last active November 19, 2022 08:00
A collection of functions for performing and evaluating polynomial regression in JavaScript.
# Find the best-fit curve for an nth order polynomial.
# Credit: https://stackoverflow.com/a/28301054/1544937
# Requirement: https://github.com/sloisel/numeric/blob/master/src/numeric.js
polyfit = (xArray, yArray, order) ->
matrix = []
if xArray.length <= order
console.warn "Warning: Polyfit may be poorly conditioned."
@jgphilpott
jgphilpott / calculus.coffee
Last active November 19, 2022 08:24
A collection of functions for performing differential and integral calculus in JavaScript.
# Find the tangent of any polynomial function at x.
findTangent = (x, coefficients) ->
slope = 0
intercept = coefficients[0]
for index in [1 ... coefficients.length]
slope += coefficients[index] * index * Math.pow x, index - 1
intercept += coefficients[index] * Math.pow x, index
@jgphilpott
jgphilpott / calculus.py
Created January 29, 2021 21:40
A collection of functions for performing differential and integral calculus in Python.
# Find the tangent of any polynomial function at x.
def find_tangent(x, coefficients):
slope = 0
intercept = coefficients[0]
for i, coefficient in enumerate(coefficients):
if i != 0:
@jgphilpott
jgphilpott / array.coffee
Last active September 20, 2023 13:33
A collection of JavaScript Array prototype updates.
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
# Source: https://gist.github.com/jgphilpott/a1367ca419ac2807ed4340d69356b7f1
Object.defineProperty Array.prototype, "first",
value: ->
this.at 0
@jgphilpott
jgphilpott / roots.coffee
Last active November 19, 2022 10:22
A collection of functions for finding the roots of polynomials in JavaScript.
findRoots = (y = 0, coefficients = []) ->
switch coefficients.length
when 0
return null
when 1
@jgphilpott
jgphilpott / length.coffee
Last active May 17, 2023 11:24
A collection of functions for converting between different units of length.
### Length Conversions ###
convertLength =
nanometer: {}
micrometer: {}
millimeter: {}
centimeter: {}
decimeter: {}
meter: {}