Skip to content

Instantly share code, notes, and snippets.

View holdenhinkle's full-sized avatar

Holden Hinkle holdenhinkle

View GitHub Profile
@holdenhinkle
holdenhinkle / qas_oncall.rb
Created August 18, 2022 18:50
generate a random on-call list
qas = %w[holden darius curt ryan1 ryan2 ryan3]
puts qas.delete(qas.sample) until qas.empty?
@holdenhinkle
holdenhinkle / pedac_sort_queue.txt
Created December 27, 2019 20:46
PEDAC example of sorting the background jobs queue
***********
**PROBLEM**
***********
**INPUT**
Upon form submission an array like the following is provided as a value to a key in Sinatra's params hash
[{"job_id"=>"43", "new_order"=>""},
{"job_id"=>"44", "new_order"=>""},
{"job_id"=>"46", "new_order"=>""},
{"job_id"=>"47", "new_order"=>""},
@holdenhinkle
holdenhinkle / rail_fence_cipher_1.js
Last active December 13, 2019 14:22
This solution is wrong. I misunderstood the problem.
function railFenceCipher(operation, string, height = 3) {
function performOperation(operation, string, height, lines) {
let results = ''; // only for decrypt
let currentLine = 0;
let moveUp = true;
let moveDown = false;
for (let i = 0; i < lines[0].length; i += 1) {
if (operation === 'encrypt') {
lines[currentLine].splice(i, 1, string[i]);
function railFenceCipher(operation, string, height = 3) {
function encrypt(string, height, fence) {
let currentRail = 0;
let moveUp = true;
let moveDown = false;
for (let i = 0; i < fence[0].length; i += 1) {
fence[currentRail].splice(i, 1, string[i]);
if ((moveUp && currentRail + 1 > height - 1) ||
@holdenhinkle
holdenhinkle / topic_12.js
Last active August 23, 2019 12:38
Code Review: Longest Sentence
function longestSentence(text) {
let biggestSentence = { sentence: null, wordCount: 0, };
while (text.length > 0) {
sentence = text.match(/^[\w\d\s,-]+\b([.!?]\s*)/i)[0];
text = text.replace(sentence, '');
sentence = sentence.trim();
let wordCount = sentence.split(' ').length;
if (biggestSentence.wordCount < wordCount) {
@holdenhinkle
holdenhinkle / topic_17.js
Last active August 13, 2019 21:03
LS Practice Problem: Class Records Summary
var studentScores = {
student1: {
id: 123456789,
scores: {
exams: [90, 95, 100, 80],
exercises: [20, 15, 10, 19, 15],
},
},
student2: {
id: 123456799,
@holdenhinkle
holdenhinkle / hex.rb
Last active March 13, 2016 04:02
Convert Hex to Decimal
class Hex
HEX = { '1' => 1, '2' => 2, '3' => 3,
'4' => 4, '5' => 5, '6' => 6,
'7' => 7, '8' => 8, '9' => 9,
'a' => 10, 'b' => 11, 'c' => 12,
'd' => 13, 'e' => 14, 'f' => 15 }
attr_reader :string
def initialize(input)
@holdenhinkle
holdenhinkle / trinary.rb
Last active March 12, 2016 21:01
Trinary
class Trinary
attr_reader :number
def initialize(value)
@number = value
end
def to_decimal
return 0 if number.match(/[^0-2]/)
converted_num = 0
number.split('').reverse.each_with_index do |num, index|
converted_num += num.to_i * 3 ** index
@holdenhinkle
holdenhinkle / grade_school.rb
Last active January 31, 2016 01:33
Grade School
class School
attr_accessor :grades
def initialize
@grades = {}
end
def to_h
grades.map { |grade, name| grades[grade] = name.sort }
grades.sort.to_h
class CircularBuffer
attr_accessor :buffer, :read_index, :write_index
def initialize(length)
@buffer = Array.new(length)
@read_index = 0
@write_index = 0
end
def read