Skip to content

Instantly share code, notes, and snippets.

View jgphilpott's full-sized avatar

Jacob Philpott jgphilpott

View GitHub Profile
@jgphilpott
jgphilpott / polygon_merger.py
Last active June 14, 2020 00:18
A Python function for merging GeoJSON polygons.
import json
def merge_polygons(polygon_one, polygon_two):
with open("data.json") as input:
data = json.load(input)
map_one = None
map_two = None
@jgphilpott
jgphilpott / rotation.coffee
Last active August 20, 2023 20:19 — forked from hoandang/get_rotate.js
Rotate any jQuery selected element.
# Rotate any jQuery selected element.
# Credit: https://gist.github.com/hoandang/5989980
# Credit: https://stackoverflow.com/a/15191130/1544937
$.fn.rotate = (degree = 0, duration = 1000) ->
element = $(this)
rotation = ->
matrix = element.css "-webkit-transform" or
@jgphilpott
jgphilpott / casefy.coffee
Last active September 20, 2023 09:51
A collection of functions for formatting strings into different cases.
lower = (string) ->
return string.toLowerCase().trim()
upper = (string) ->
return string.toUpperCase().trim()
# Credit: https://stackoverflow.com/a/1026087/1544937
capitalize = (string) ->
@jgphilpott
jgphilpott / number.coffee
Last active September 20, 2023 13:35
A collection of JavaScript Number 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/Number
# Source: https://gist.github.com/jgphilpott/6332dc7f5636db9ba455e1575407c496
# Credit: https://stackoverflow.com/a/7312534/1544937
Object.defineProperty Number.prototype, "round",
value: (decimals = 0) ->
parseFloat this.toFixed decimals
@jgphilpott
jgphilpott / morph.coffee
Last active July 18, 2023 17:48
Perform OctreeCSG.js mesh operations on three.js meshes.
# Requirements
# Three JS
# https://github.com/mrdoob/three.js
# OctreeCSG
# https://github.com/giladdarshan/OctreeCSG
morph = (operation, aMesh, bMesh) ->
@jgphilpott
jgphilpott / D3Sorting.coffee
Last active November 17, 2022 17:40
Functions for sorting SVG elements with D3.
# Requirement: https://github.com/d3/d3
# Credit: https://stackoverflow.com/a/42998001/1544937
d3.selection.prototype.setAsFrontLayer = ->
return this.each ->
this.parentNode.appendChild this
d3.selection.prototype.setAsBackLayer = ->
@jgphilpott
jgphilpott / cookies.coffee
Last active November 18, 2022 06:29
A collection of functions for writing, reading, updating and deleting cookies.
# Credit: https://www.w3schools.com/js/js_cookies.asp
writeCookie = (key, value, expDays = 365) ->
if String key
date = new Date()
expTime = 1000 * 60 * 60 * 24 * expDays
date.setTime date.getTime() + expTime
expDate = date.toUTCString()
@jgphilpott
jgphilpott / email.coffee
Last active November 18, 2022 11:40
A simple JS function for checking if an Email is valid.
# Credit: https://stackoverflow.com/a/46181/1544937
validEmail = (email = "@") ->
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test String(email).toLowerCase()
@jgphilpott
jgphilpott / browser.coffee
Last active November 18, 2022 11:38
A function for detecting a clients browser.
# Credit: https://stackoverflow.com/a/40246491/1544937
getBrowser = ->
try
error.throw
catch error
@jgphilpott
jgphilpott / localStorage.coffee
Last active November 18, 2022 11:43 — forked from cdmckay/local-storage-size.js
A collection of functions for writing, reading and deleting in localStorage.
localKeys = ->
return Object.keys window.localStorage
localWrite = (key, value) ->
try
window.localStorage.setItem String(key), JSON.stringify(value)