Skip to content

Instantly share code, notes, and snippets.

@SoftwareDevPro
SoftwareDevPro / 41bFib.coffee
Created October 30, 2016 04:19
Fibonacci sequence implemented in CoffeeScript
# Filed under: 140bytes, fibonacci, recursive
# calculate fibonacci (recursively)
fibonacci = (n) ->
if n > 1 then f(n - 1) + f(n - 2) else n
@SoftwareDevPro
SoftwareDevPro / hex2rgb.coffee
Created October 30, 2016 05:24
Receives a hex string, and returns an array of R,G,B components
# Filed under: hex, color, rgb
# Converts a hex string to RGB.
###
@param a a "#xxxxxx" hex string,
###
hex2rgb = (a) ->
###
turn it into a number by taking the hexadecimal prefix and the
@SoftwareDevPro
SoftwareDevPro / hsl2rgb.coffee
Created October 30, 2016 05:27
Takes a HSL (hue saturation, light) value and returns the RGB equivalent
# Filed under: color, convert, hsl, rgb
# Converts hue-saturation-lightness to red-green-blue color value.
###
@param a hue
@param b saturation
@param c lightness
###
hsl2rgb = (a, b, c) ->
@SoftwareDevPro
SoftwareDevPro / objectid.coffee
Created October 30, 2016 05:33
Implementation of hash code for the Object prototype
# Filed under: 140bytes, identifier, object, id, hashcode
# Gives every object a unique ID.
(() ->
Object.prototype.getHashCode = ((i) ->
i = 0
() ->
if this.h = this.h then this.h else i++
)()
@SoftwareDevPro
SoftwareDevPro / uuid.coffee
Created October 30, 2016 18:08
Creates a UUID and returns it.
# Filed under: uuid, id, random
###
a: placeholder
###
b = (a) ->
###
if the placeholder was passed, return a random number from 0 to 15 unless b
is 8, in which case a random number from 8 to 11 in hexadecimal or
@SoftwareDevPro
SoftwareDevPro / square_root.py
Created January 27, 2019 00:32
Square Root of a Number in Python
def square_root(num):
return num ** 0.5
@SoftwareDevPro
SoftwareDevPro / caesars-cipher.json
Created May 24, 2019 00:31
Implementation of Caesars Cipher for Free Code Camp
{"index.js":"function rot13(str) { // LBH QVQ VG!\n return str.split('')\n .map.call(str, function(char) {\n \n let x = char.charCodeAt(0);\n \n if (x < 65 || x > 90) { \n return String.fromCharCode(x);\n } else if (x < 78) { \n return String.fromCharCode(x + 13); \n }\n \n return String.fromCharCode(x - 13);\n }).join(''); \n}\n\n// Change the inputs below to test\nrot13(\"SERR PBQR PNZC\");"}
@SoftwareDevPro
SoftwareDevPro / cash-register.json
Created May 24, 2019 00:32
Implementation of Cash Register for Free Code Camp
{"index.js":"\nvar denominations = [\n { name: 'ONE HUNDRED', val: 100.00},\n { name: 'TWENTY', val: 20.00},\n { name: 'TEN', val: 10.00},\n { name: 'FIVE', val: 5.00},\n { name: 'ONE', val: 1.00},\n { name: 'QUARTER', val: 0.25},\n { name: 'DIME', val: 0.10},\n { name: 'NICKEL', val: 0.05},\n { name: 'PENNY', val: 0.01}\n];\n\nfunction checkCashRegister(price, cash, cid) {\n var result = { status: null, change: [] };\n var change = cash - price;\n\n var register = cid.reduce(function(acc, curr) {\n acc.total += curr[1];\n acc[curr[0]] = curr[1];\n return acc;\n }, { total: 0 });\n\n if (register.total === change) {\n result.status = 'CLOSED';\n result.change = cid;\n return result;\n }\n\n // Handle obvious insufficient funds\n if (register.total < change) {\n result.status = 'INSUFFICIENT_FUNDS';\n return result;\n }\n\n var change_arr = denominations.reduce(function(acc, curr) {\n var value = 0;\n \n while (register[curr.name] > 0 && change >= curr.val) {
@SoftwareDevPro
SoftwareDevPro / palindrome-checker.json
Created May 24, 2019 00:33
Palindrome Checker Implementation for Free Code Camp
{"index.js":"function palindrome(str) {\n return str.replace(/[\\W_]/g, '').toLowerCase() ===\n str.replace(/[\\W_]/g, '')\n .toLowerCase()\n .split('')\n .reverse()\n .join('');\n}\n\npalindrome(\"eye\");"}
@SoftwareDevPro
SoftwareDevPro / roman-numeral-converter.json
Created May 24, 2019 00:33
Roman Numeral Converter Implementation for Free Code Camp
{"index.js":"function convertToRoman(num) {\n\n var decVal = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];\n var romanVal = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];\n\n var romanized = '';\n\n for (var index = 0; index < decVal.length; index++) {\n while (decVal[index] <= num) {\n romanized += romanVal[index];\n num -= decVal[index];\n }\n }\n\n return romanized;\n }\n\nconvertToRoman(36);"}