Skip to content

Instantly share code, notes, and snippets.

View keif's full-sized avatar

Keith Baker keif

View GitHub Profile
@keif
keif / timeConversion.js
Last active August 28, 2021 22:04
Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format. timeConversion has the following parameter(s): string s: a time in hour format Returns string: the time in hour format Input Format A single string that represents a time in -hour clock format (i.e.: or ). Constr…
const timeConversion = (s) => {
const seperator = `:`
const timeArr = s.slice(0, 8).split(seperator);
const hours = parseInt(timeArr[0], 10);
if (s.toUpperCase().indexOf(`PM`) > -1) {
// handle PM
timeArr[0] = (hours < 12) ? (hours + 12).toString() : hours.toString()
} else {
// handle AM
@keif
keif / minSum.js
Last active August 28, 2021 22:18
minSum.js - ah, this is from HackerRank, now it all makes more sense.
// I liked reduce. It's weird, but it's quirky, but I don't find it easy to understand at quick glance for all devs
const minSum_short = (num, k) => {
return new Array(k)
.fill(undefined) // not crazy about this aspect
.reduce(
(prev) => {
// Sort the array high to low
const current = prev.sort((a, b) => b - a)
// Swap the maximum value with the updated one
current[0] = Math.ceil(current[0] / 2)
@keif
keif / IsPrimeAndIsPalindrome.java
Last active August 19, 2021 12:46
isPrime and isPrimePalindrome example
package interviewProject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class InterviewMain {
public static void main(String[] args) {
// Prime Number detector
@keif
keif / isPrime.java
Last active September 30, 2021 15:12
Check if a number is prime (JAVA)
package InterviewProject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class InterviewMain {
public static void main(String[] args) {
// Prime Number detector
@keif
keif / example.js
Created February 11, 2021 14:08
Mongoose Schema and Express Routes Using Users/Albums using an ugly token example.
var express = require("express")
var app = express()
var bodyParser = require("body-parser")
var mongoose = require("mongoose")
var userSchema = mongoose.Schema({
name: String,
email: String,
password: String,
token: String, // this is for the example code, JWT would be used in a real life scenario
@keif
keif / memoize.js
Created February 10, 2021 21:53
Multiple Argument Memoization Function
const constructPropertyFromArgs = function (fn, args) {
return [].concat(fn.name, args).join('|');
}
const memoize = function (fn) {
const cache = {}
return function(...args) {
const propCheck = constructPropertyFromArgs(fn, args);
if (!cache[propCheck]) {
@keif
keif / event.json
Last active September 24, 2020 20:46
https://www.udemy.com/course/comprehensive-alexa-skill-development-course/learn/lecture/6680210#questions/7303418 I had to update the JavaScript and the JSON provided in the Udemy course that has not been updated.
{
"session":{
"new": true,
"sessionId":"SessionId.[unique-value-here]",
"application":{
"applicationId":"amzn1.ask.skill.[YOUR_SKILL_ID_HERE]"
},
"attributes":{
"key": "string value"
},
// super simple express server
'use strict'
const http = require(`http`);
const port = 8080;
const server = http.createServer((req, res) => {
res.end(`Hello, World!`);
});
server.listen(port, (err) => {
@keif
keif / sayHello.js
Created December 11, 2019 15:20
A simple script to add a colored console message.
const sayHello = () => {
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
var args = ['\n %c Made with ♥ by <name> %c %c %c http://www.dogstudio.co/ %c %c \n', 'color: #fff; background: #e43333; padding:5px 0;', 'background: #131419; padding:5px 0;', 'background: #131419; padding:5px 0;', 'color: #fff; background: #1c1c1c; padding:5px 0;', 'background: #fff; padding:5px 0;', 'color: #e43333; background: #fff; padding:5px 0;']
window.console.log.apply(console, args)
} else if (window.console) {
window.console.log('Made with love ♥ <name> - http://www.dogstudio.co/')
}
}
export default sayHello
@keif
keif / prepare-commit-msg
Last active March 24, 2021 19:42
prepare-commit-msg git hook to automatically prepend on to the commit message. I think this was born from here: https://medium.com/@nicklee1/prepending-your-git-commit-messages-with-user-story-ids-3bfea00eab5a
#!/bin/bash
# Include any branches for which you wish to disable this script
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master main develop test)
fi
# Get the current branch name and check if it is excluded
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"