This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This snippet does not validate dates. It's a simple parser for multiple CORRECT date formats. | |
// Some date inputs in different formats. Only accepts d-m-y or d-m-Y formats. | |
$dates = | |
array( | |
'19-1-1992', | |
'2/4/93', | |
'14-1-72', | |
'12-11-11', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function factorial($number, $memoize = array(0,1)) { | |
if ($number == 0 || $number == 1) { | |
return 1; | |
} | |
if (!array_key_exists($number, $memoize)) { | |
$memoize[$number] = $number * factorial($number-1, $memoize); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hobbits = ['Frodo', 'Samwise', 'Merry', 'Pippin'] | |
wizards = ['Gandalf', 'Saruman', 'Radagast'] | |
# Function starts | |
def printList(lists): | |
for number, item in enumerate(lists, 1): | |
print(str(number) + " " + item) | |
print("\n") | |
# Function ends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
def calculateSize(path): | |
totalSize = 0 | |
if len(path) > 2: | |
print('Extra argument given.') | |
sys.exit(0) | |
elif len(path) == 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Encode BASE64: ----------\n"; | |
$string = 'message:whatsup'; | |
$url = base64_url_encode($string); | |
echo "Encoded: ".$url."\n"; | |
echo "Now decode! --------------\n"; | |
$decode = base64_url_decode($url); | |
$getClient = explode(":", $decode); | |
foreach ($getClient as $str) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getUniqueSortedChars ($a, $b) { | |
return count_chars($a.$b,3); | |
} | |
echo getUniqueSortedChars('aaaabbbdddccc','aadfafiseitaabbbss')."\n"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longest(s1, s2): | |
return ''.join(sorted(set(s1 + s2))) | |
print(longest('aaaabbbdddccc','aadfafiseitaabbbss')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def disemvowel(string): | |
return re.sub('[aeiou]','',string,flags=re.IGNORECASE) | |
print(disemvowel("Hello World!")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function disemvowel(str) { | |
return str.replace(/[aeiou]/ig,''); | |
} | |
console.log(disemvowel("Hello World!")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
MORSE_CODE= { | |
'.-': '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', '--..': 'Z', | |
'-----': '0', '.----': '1', '..---': '2', '...--': '3', '....-': '4', | |
'.....': '5', '-....': '6', '--...': '7', '---..': '8', '----.': '9', |
OlderNewer