Skip to content

Instantly share code, notes, and snippets.

View jeebster's full-sized avatar

jeebster

View GitHub Profile
@jeebster
jeebster / rainforest.rb
Created September 12, 2022 18:40
Rainforest QA - Application Challenge
require 'net/http'
require 'json'
require 'cgi'
require 'uri'
ENDPOINT = "https://www.letsrevolutionizetesting.com/challenge"
HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json"
}
@jeebster
jeebster / index.js
Created May 20, 2020 17:28
Mux Technical Exercise - Finishing up on my previous thought & process...
const axios = require('axios')
const showAstronautsInSpace = (url) => {
// Make an HTTP request
// on success: format the returned data
// on fail: log the error
// pass data to showAstronautData
axios.get(url)
.then(res => {
showAstronautData(res.data)
@jeebster
jeebster / arrayToInstanceCountMap.js
Created May 18, 2020 03:14
Count your array instances in Javascript
export default function arrayToInstanceCountMap(ary) {
const map = {}
ary.forEach(item => {
if (map[item]) {
map[item] += 1
} else {
map[item] = 1
}
})
/* seismic_datum table schema example via postgresql
*
* time: timestamp
* coordinates: ST_point (postgis)
* magnitude: double precision
* place: text
* query_lat, query_lng, start_time, end_time variables passed in lieu of (?)
*/
@jeebster
jeebster / haversine_distance.rb
Created November 29, 2017 21:45
Haversine Distance Implementation
# extend stdlib Numeric class to convert a numeric instance to radian
class Numeric
def to_radians
self * Math::PI / 180
end
end
# a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
# c = 2 ⋅ atan2( sqrt(a), sqrt(1−a) )
# d = R ⋅ c
@jeebster
jeebster / smush.rb
Created June 8, 2016 17:06
Ruby's Array#flatten implementation (Citrusbyte)
class Array
# flatten a nested array via recursion - continue to call the method until all arrays are unidimensional
def smush
return self if empty?
last_index = pop
if last_index.is_a? Array
# flatten the last index (array) and recall the method
smush + last_index.smush
else
@jeebster
jeebster / gist:2871171
Created June 4, 2012 22:22
HTTParty Webhook
module Spree
class ProductObserver < ActiveRecord::Observer
observe "Spree::Product"
def after_save(product)
image = product.images.first.attachment_file_name
data = { id: product.id,
name: product.name,
city: product.taxons.first.name,
start_date: product.available_on.to_date.to_s(:db),