Posts

Showing posts from August 7, 2018

PHP function to evaluate comparisons between two values, with debug logging

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 3 down vote favorite The following method works fine but it is rather verbose: private function performComparison($element, $operator, $value_allowed, $value_entered) switch($operator): case '>': $result = ($value_entered > $value_allowed) ? true : false; break; case '>=': $result = ($value_entered >= $value_allowed) ? true : false; break; case '<': $result = ($value_entered < $value_allowed) ? true : false; break; case '<=': $result = ($value_entered <= $value_allowed) ? true : false; break; case '=': $result = ($value_entered == $value_allowed) ? true : false; break; endswitch; $dateformat = 'n/j/Y'; $debug = ['element' => $element, 'operator' => $operator, 'value allowed' => is_a($value_allowed, 'DateTime') ? $...

Simple Encryption for Strings

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 7 down vote favorite 1 I have written this code for practice. Here we will enter the number by which we want to shift alphabets. For eg. Enter by how many numbers you want to shift alphabets: 4 Enter string: Programmer C++ Encrypted String: Lnkcnwiian Y++ Decryted String: Programmer C++ Review this code and suggest better C++11 and C++14 alternatives. #include <iostream> #include <string> #include <vector> #include <unordered_map> class Cipher unsigned n; const std::vector<char> alphabetL 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y...