Skip to content

Instantly share code, notes, and snippets.

Caspar Green iCaspar

Block or report user

Report or block iCaspar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@iCaspar
iCaspar / cashRegister.js
Created Dec 12, 2018
A cash register function
View cashRegister.js
function checkCashRegister(price, cash, cid) {
const denominationVals = {
'ONE HUNDRED': 100,
'TWENTY': 20,
'TEN': 10,
'FIVE': 5,
'ONE': 1,
'QUARTER': 0.25,
'DIME': 0.1,
'NICKEL': 0.050,
@iCaspar
iCaspar / usTelephoneValidator.js
Created Dec 11, 2018
Function to validate a US phone number
View usTelephoneValidator.js
function telephoneCheck(str) {
const usPhoneRegex = /^(?:1\s?)?(?:\d{3}|\(\d{3}\))[\s|-]?\d{3}[\s|-]?\d{4}$/
return usPhoneRegex.test(str);
}
@iCaspar
iCaspar / rot13.js
Created Dec 11, 2018
A function to decode a ROT13 string
View rot13.js
function rot13 (str) { // LBH QVQ VG!
const allCapsRegex = /[A-Z]/
let decoded = ''
let char = 0
while (char < str.length) {
if (true === allCapsRegex.test(str[char])) {
decoded += String.fromCharCode(
str[char].charCodeAt(0) <= 77 ? str[char].charCodeAt(0) + 13 : str[char].charCodeAt(0) - 13
@iCaspar
iCaspar / toRomanNumeral.js
Created Dec 11, 2018
A function to convert an aribic (base 10) number to a Roman numeral
View toRomanNumeral.js
function convertToRoman(num) {
const romanSymbols = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
XL: 40,
@iCaspar
iCaspar / palindrome-checker.js
Created Dec 10, 2018
A function to check whether a string, stripped of non alphanumeric characters and spaces, is a palendrome
View palindrome-checker.js
function palindrome(str) {
const lettersOnlyRegex = /[a-zA-Z0-9]/g
const letters = str.match(lettersOnlyRegex)
if (null === letters || 0 === letters.length) {
return false
}
const strippedString = str.match(lettersOnlyRegex).join('').toLowerCase()
@iCaspar
iCaspar / str-reverse.js
Created Dec 5, 2018
JS algorithm to reverse a string (without using conversion to array and back)
View str-reverse.js
function strReverse(str) {
let reverse = ''
let i = str.length
while (i-- > 0) {
reverse += str[i]
}
return reverse
}
@iCaspar
iCaspar / default.conf
Created Nov 28, 2018
A default nginx config for php apps.
View default.conf
server {
listen 80 default_server;
root /var/www/html;
index index.html index.htm index.php;
server_name localhost;
charset utf-8;
location = /favicon.ico {
log_not_found off;
access_log off;
@iCaspar
iCaspar / no-fives.php
Created Nov 15, 2018
Has 5s recursive method to find numbers with 5s in them.
View no-fives.php
/**
* Does this number have 5s?
*
* @param $number Number to check.
*
* @since 1.0.0
*
* @return bool
*/
private function hasFive($number): bool
@iCaspar
iCaspar / arrayproduct.php
Created Nov 6, 2018
Array Product puzzle
View arrayproduct.php
<?php
/**
* Unit tests for Product of Array Items puzzle.
*
* @see https://www.codewars.com/kata/product-of-array-items/
*
* Requirements: Calculate the product of all elements in an array.
* If the array is NULL or empty, return NULL
*
* @author Caspar Green <caspar@iCasparWebDevelopment.com>
@iCaspar
iCaspar / guessBlue.php
Last active Nov 5, 2018
Guess the odds of drawing blue
View guessBlue.php
<?php
/**
* Unit tests for Blue and Red Marbles game.
*
* @see https://www.codewars.com/kata/thinkful-number-drills-blue-and-red-marbles/
*
* You and a friend have decided to play a game to drill your statistical intuitions.
* The game works like this:
* You have a bunch of red and blue marbles.
* To start the game you grab a handful of marbles of each color and put them
You can’t perform that action at this time.