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 / 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
@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 / animateable.js
Last active July 4, 2021 14:48
@animateable decorator/mixin that can be used to add simple animations to any class object in javascript
const animateable = (a) => {
a.prototype.quad = function(x){
return x ** 2
};
a.prototype.linear = function(x){
return x;
};
a.prototype.animate = function({ duration=300, ease=this.quad, start, end, onUpdate, onComplete=()=>{}}){
@r3wt
r3wt / index.js
Created January 14, 2018 20:16
random_password generator in javascript
const random_password = (len=64) => {
let chars='abcdefghijklmnopqrstuvwxyz123456789-_=+`~:;>,.<}{[]|)(*&^%$#@!';
let password = '';
while(password.length < len) {
password+= chars.charAt(Math.floor((Math.random() * chars.length) + 1) % chars.length);
}
return password;
};
@r3wt
r3wt / bind.js
Last active December 5, 2019 18:24
function bind()
/* partial implementation of Function.prototype.bind */
Function.prototype.bind || (Function.prototype.bind = function(/* context[,arg1,arg2...] */) {
var fn = this;
var args = Array.prototype.slice.call(this,arguments);//preset args
var context = args.shift() || undefined;
return function(){
var args2 = args.concat( Array.prototype.slice.call(arguments) );//spec states any passed args should be appended to preset arguments.
return fn.apply(context,args2);
};
});
@r3wt
r3wt / db.factory.js
Last active February 7, 2017 18:16
a helper for angularfire making things easier.
angular
.module('myApp')
.factory('$db',['$firebaseObject','$firebaseArray','$q',function($firebaseObject,$firebaseArray,$q){
function $db( type, id ){
var ref = firebase.database().ref(type).child(id);
var obj = $firebaseObject(ref);
return $q(function(resolve,reject){
obj.$loaded().then(function(){
resolve(obj);
@r3wt
r3wt / README.md
Last active January 5, 2017 01:22
ez tiny grid framework. no jquery!

No media queries are used Since tablets and mobiles are now displaying huge resolutions, if we think its mobile, the body gets a class of .m, if we think its a tablet, it gets a class of .t. if its neither mobile nor tablet,it gets .d unless the screen is wider than 1920px, then it gets .hd

  • Columns must use class .col
  • Mobile use class .m-{desired size} eg .m-12
  • Tablet use class .t-{desired size} eg .t-6
  • Desktop use class .d-{desired size} eg .d-4
  • Huge Desktop use class .hd-{desired size} eg .hd-2
  • 12 columns (.col). extras .row, .container, .container.fluid
  • use .{size}-hide to hide eg .m-hide would hide for mobile.
@r3wt
r3wt / yearselect.twig
Created January 27, 2016 07:34
twig year select
<select name="year">
<option value="">Not Selected</option>
{% for i in range(19,20) %}
{%for j in range(0,9) %}
{% for k in range (0,9) %}
{% set y %}{{i}}{{j}}{{k}}{%endset%}
{% if y <= "now"|date('Y') %}
<option value="{{y}}">{{y}}</option>
{% endif %}
{% endfor %}
<?php
namespace UserFrosting\Util;
trait ArraySingleton
{
protected $data = [];
protected $defaults = [];
private static $instance = null;
@r3wt
r3wt / instructions.md
Created September 8, 2015 17:58
a simple way to run cronjobs on nginx/hhvm with JIT capabilities.

cron.sh:

#!/bin/bash

curl http://localhost/related.php &

curl http://localhost/artist_rank.php &

curl http://localhost/sitemap.php &