Skip to content

Instantly share code, notes, and snippets.

View r3wt's full-sized avatar
😅
Move Fast. Break Things.

Garrett R. Morris r3wt

😅
Move Fast. Break Things.
  • Walmart
  • Hartman, Arkansas, United States
View GitHub Profile
@r3wt
r3wt / GhostSearch.js
Created February 25, 2019 18:10
Search + Archive Implementation for a Ghost Blog
// begin config
const ghost_host = '<your host here>';//your blogs domain -- see documentation of tryghost/content-api
const ghost_key = '<your key here>';//key to your integration -- see documentation of tryghost/content-api
const updateInterval = 60000;//how often the index should update given in milliseconds
const requestTimeout = 5000;// maximum time for a search request before it times out given in milliseconds (note this isn't exact, it depends on the load of the event loop)
const resultsPerPage = [8];// allowed values for limit. in my case we only allow 8, but made this configurable so users of ghost can benefit
// end config
const elasticlunr = require('elasticlunr');
@r3wt
r3wt / findFirstDuplicateInSeq.js
Created June 28, 2022 14:12
Splunk Interview Question - Find first duplicate in sequence whose next value is the sum of its digits squared.
// i did poorly in my interview, the solution i gave worked but it was innefficient.
// splunk passed on me, but i couldn't let it go. so here is my final solution of the problem
function findFirstDuplicateInSeq( _seq ) {
const seq = [..._seq];// clone the array first so we are not mutating it.
while(true){
const next = seq[seq.length-1].toString().split('').map(v=>Math.pow(~~v,2)).reduce((a,b)=>a+b,0);// next val is sum of digits squared
if(seq.indexOf(next)!==-1){
return seq.length+1;// if seq contains our next value already, we found the first duplicate. return length+1
}
seq.push(next);// no match, push the next val in to the sequence