Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jearl4
jearl4 / closestValue.java
Created February 20, 2021 17:30
Find closest value in BST
import java.util.*;
class Program {
public static int findClosestValueInBst(BST tree, int target) {
return findClosestValueInBst(tree, target, tree.value);
}
public static int findClosestValueInBst(BST tree, int target, int closest){
// find current and next value
int currentValue = Math.abs(target - closest);
@jearl4
jearl4 / automate-commit.sh
Created May 27, 2019 05:31
script to add your branch name to a git commit message
#If BRANCHES_TO_SKIP is null
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP = (master)
fi
#Get branch name
BRANCH_NAME=$(git symbolic-ref --short HEAD)
#Set excluded branches and search on the excluded branches for
#branch name
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME")
@jearl4
jearl4 / prepared-statements.js
Last active May 25, 2019 04:01
Using prepared statements to protect against SQLI
function authenticate(req, res, next){
const username = req.query.username,
password = req.query.password
let preparedStatement = new sql.PreparedStatment(),
sqlQuery = "select * from users where (username = @username and password = @password)"
preparedStatement.input('username', sqlVarChar(50))
preparedStatement.input('password', sqlVarChar(50))
preparedStatement.prepare(sqlQuery)
.then(function(){