Skip to content

Instantly share code, notes, and snippets.

View the-vampiire's full-sized avatar
💭
ive lost a shade of color in my life. rest in peace.

the-vampiire

💭
ive lost a shade of color in my life. rest in peace.
View GitHub Profile
@the-vampiire
the-vampiire / update.js
Last active August 5, 2017 02:36
error scanner and flag modifier
errorScanAndModify = (item, flag, data) => {
let expectedFlags;
switch(item){
case 'projects':
expectedFlags = ['name', 'n', 'url', 'u', 'git', 'g', 'date', 'd'];
break;
case 'gitHub':
case 'blog':
case 'portfolio':
@the-vampiire
the-vampiire / update.js
Last active August 5, 2017 02:53
argument parser
argumentParser = arguments => {
const acceptedUpdateItems = ['gitHub', 'blog', 'portfolio', 'story', 'projects', 'certifications'];
let error;
let output = argumentSplitter(arguments);
let item = output.item;
// initial check to ensure the update item is valid
if(!~acceptedUpdateItems.indexOf(item)) return `invalid update item [\`${item}\`]\n Use \`/update help\` for a list of available update items.`;
@the-vampiire
the-vampiire / controller.js
Created August 5, 2017 02:56
/update route controller
router.post('/update', (req, res) => {
const respond = require('./tools/respond');
const update = require('./tools/update');
const body = req.body;
const arguments = body.text;
if(tools.verify.slash(body.token)){
if(~arguments.indexOf(' ')){
@the-vampiire
the-vampiire / solution.js
Created September 29, 2017 18:51
algo solution for sup
function conditionalRecursion(n) {
if (n < 2) return n;
return conditionalRecursion(n - 1) + conditionalRecursion(n - 2);
}
const tests = [
[1, 3, 5, 7],
[0, 1, 1, 2],
[2, 4, 6, 8],
[0, 1, 2, 3],
@the-vampiire
the-vampiire / errorCorrection.py
Last active October 21, 2017 03:39
Error Correction
# This works
def printHelloWorld():
print('hello word')
def returnPrintHelloWorld():
return print('hello world') # output: syntax error
"""
To answer the original question: Why do you use a return statement on the return 5
@the-vampiire
the-vampiire / return_initials.py
Created October 24, 2017 00:02
Sample solution for the Initials project
"""
The goal here is to gather the user's first and last name using the input() command
and then to print the user's initials
We also want to make sure that those inputs are valid alpha characters because nobody
except for an impostor robot would have a name with numbers in it! INPUT VALIDATION TIME
To accomplish this we need to "sanitize" the input before it is passed along to the rest
of the codebase
@the-vampiire
the-vampiire / unit_tester.py
Created October 27, 2017 03:29
My first unit testing program
# Write your own unit tests and testing environment
def unit_test(function_to_test, test_input, expected_output):
function_output = function_to_test(test_input)
try:
assert function_output == expected_output
print(unit_test_response(True, test_input, function_output, expected_output))
except AssertionError:
print(unit_test_response(False, test_input, function_output, expected_output))
def unit_test_response(correct, test_input, function_output, expected_output):
@the-vampiire
the-vampiire / unit_tester_annotated.py
Last active October 28, 2017 07:29
Simple Unit Testing Environment
# performs a single unit test
# accepts a function to test, a test case input and its corresponding expected output
def unit_test(function_to_test, test_input, expected_output):
try: # try something (whatever is in the code block)
function_output = function_to_test(test_input)
except Exception as error: # if it DOES NOT work then catch the error using the except keyword
# Exception is a general "catch-all" exception
# catch the Exception and store the error message as a variable called error
print("Error occurred with test input: [{0}] value: {1}\nError Message: {2}\nCorrect the error and try again.\n"
@the-vampiire
the-vampiire / unit_tester.py
Created October 31, 2017 08:53
UnitTester Class
def unit_test(function_to_test, test_input, expected_output):
try:
number_of_inputs = len(test_input)
if type(test_input) == list: function_output = function_to_test(test_input)
elif number_of_inputs == 1: function_output = function_to_test(test_input)
elif number_of_inputs == 2: function_output = function_to_test(test_input[0], test_input[1])
elif number_of_inputs == 3: function_output = function_to_test(test_input[0], test_input[1], test_input[2])
except Exception as error:
print("Error occurred with test input: [{0}] value: {1}\nError Message: {2}\nCorrect the error and try again.\n"
@the-vampiire
the-vampiire / hourglass_sum.py
Last active November 14, 2017 05:10
2-dimensional array problem - HackerRank (https://www.hackerrank.com/challenges/2d-array/problem)
"""
Problem Statement:
Calculate the hourglass sum for every hourglass in the 2D array, then print the maximum hourglass sum.
"""
"""
Approach:
A B C