Skip to content

Instantly share code, notes, and snippets.

Avatar

Keith Baker keif

View GitHub Profile
@keif
keif / example.js
Created Feb 11, 2021
Mongoose Schema and Express Routes Using Users/Albums using an ugly token example.
View example.js
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 Feb 10, 2021
Multiple Argument Memoization Function
View memoize.js
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 Sep 24, 2020
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.
View event.json
{
"session":{
"new": true,
"sessionId":"SessionId.[unique-value-here]",
"application":{
"applicationId":"amzn1.ask.skill.[YOUR_SKILL_ID_HERE]"
},
"attributes":{
"key": "string value"
},
View index.js
// 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 Dec 11, 2019
A simple script to add a colored console message.
View sayHello.js
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 Mar 24, 2021
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
View prepare-commit-msg
#!/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##*/}"
@keif
keif / .gitconfig
Last active Mar 24, 2021
Most recent incarnation of .gitconfig 2021/03/24
View .gitconfig
[alias]
# log outputs
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --date=short
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --numstat
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate
# fancy log output
log-fancy = log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(cyan)<%an>%Creset' --abbrev-commit --date=relative
log-me = !UN=$(git config user.name)&& git log --author="\"$UN\"" --pretty=format:'%h %cd %s' --date=short
log-nice = log --graph --decorate --pretty=oneline --abbrev-commit
# standup = log --since '1 day ago' --oneline --author <YOUREMAIL> # hack it with your email and uncomment
@keif
keif / git_merge_check.sh
Last active Mar 25, 2019
This utilizes an external text file (branches.txt) and runs a test against the branches to see if there is a merge conflict.
View git_merge_check.sh
#!/bin/bash
function git_merge_test() {
echo "test git branch merges";
RUN_UNIT_TESTS=0
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "test the branches in branches.txt for merge conflicts"
@keif
keif / gist:d62ccd60ebbdd79eb8ee7f800443a58e
Created Dec 26, 2018
https://projecteuler.net/problem=3The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143?
View gist:d62ccd60ebbdd79eb8ee7f800443a58e
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143?
View project_euler_example_3.js
function isPrime(number) {
var index;
var limit = Math.ceil(Math.sqrt(number));
// since the main loop generates odd numbers only
// we can start testing primality dividing by 3
for (index = 3; index <= limit; index += 2) {
if (number % index === 0) {
return false;
}
}