Skip to content

Instantly share code, notes, and snippets.

View navidanindya's full-sized avatar
💻
Coding away!

Navid Anindya navidanindya

💻
Coding away!
View GitHub Profile
@navidanindya
navidanindya / simpleTwoFormatDateParser.php
Last active March 31, 2018 09:23
Simple format date parser for PHP (d-m-y or d-m-Y). [ Try out in sandbox: http://sandbox.onlinephpfunctions.com/code/b02657c7bfe827d7e3e20db231e07f3dd41de750 ]
<?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',
<?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);
}
@navidanindya
navidanindya / PrintList.py
Created April 9, 2018 10:39
Prints a list numerically in Python 3.
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
@navidanindya
navidanindya / DirectorySize.py
Created April 9, 2018 12:04
Get a folder/directory size in Python 3. Run: [ python DirectorySize.py '/usr/bin' ] (without braces) to get size in '/usr/bin' folder.
import sys
import os
def calculateSize(path):
totalSize = 0
if len(path) > 2:
print('Extra argument given.')
sys.exit(0)
elif len(path) == 1:
@navidanindya
navidanindya / URLSafeBase64.php
Created June 2, 2018 13:27
A very simple, quick and dirty way of encoding and decoding URL Safe Base64 strings. Preview: http://sandbox.onlinephpfunctions.com/code/66abd8f5fd2b87bf91a5fba3e9d93dfd190cba09
<?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) {
@navidanindya
navidanindya / UniqueCharactersSorted.php
Last active June 9, 2018 08:55
Get unique characters from two strings and return a sorted substring (PHP) [ Link: https://repl.it/@nealtheguitaris/PuzzlingVengefulRobot ]
<?php
function getUniqueSortedChars ($a, $b) {
return count_chars($a.$b,3);
}
echo getUniqueSortedChars('aaaabbbdddccc','aadfafiseitaabbbss')."\n";
?>
@navidanindya
navidanindya / UniqueCharactersSorted.py
Created June 9, 2018 08:55
Get unique characters from two strings and return a sorted substring (Python) [ Link: https://repl.it/@nealtheguitaris/SoggyCruelPipeline ]
def longest(s1, s2):
return ''.join(sorted(set(s1 + s2)))
print(longest('aaaabbbdddccc','aadfafiseitaabbbss'))
import re
def disemvowel(string):
return re.sub('[aeiou]','',string,flags=re.IGNORECASE)
print(disemvowel("Hello World!"))
@navidanindya
navidanindya / StripVowels.js
Created June 9, 2018 09:12
Strip vowels from a string using JavaScript. [ Link: https://repl.it/@nealtheguitaris/TightLawngreenTrapezoid ]
function disemvowel(str) {
return str.replace(/[aeiou]/ig,'');
}
console.log(disemvowel("Hello World!"));
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',