Skip to content

Instantly share code, notes, and snippets.

View ishahid's full-sized avatar

Imran Shahid ishahid

View GitHub Profile
@ishahid
ishahid / ugly_number.py
Created January 15, 2014 02:44
O(N) solution to find Nth ugly number.
def ugly_number(n):
""" Returns Nth ugly number """
assert n > 0, 'The argument must be greater than zero.'
list = [0]*n
i2, i3, i5 = 0, 0, 0
w2, w3, w5 = 2, 3, 5
w, list[0] = 1, 1
@ishahid
ishahid / num2str.py
Created January 15, 2014 02:41
Convert numbers to their string representation.
import re
units = {
0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine'
}
tens = {
10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen', 15: 'Fifteen', 16: 'Sixteen',
17: 'Seventeen', 18: 'Eighteen', 19: 'Nineteen', 20: 'Twenty', 30: 'Thirty', 40: 'Forty', 50: 'Fifty',
60: 'Sixty', 70: 'Seventy', 80: 'Eighty', 90: 'Ninety'
}
@ishahid
ishahid / anagram.py
Last active January 3, 2016 07:29
Find all anagrams for a given word from a list of words.
def signature(word):
""" Returns the sorted word """
return ''.join(sorted(word))
def anagrams(word):
""" Returns a list of all anagrams for a given word """
words = [w.strip().lower() for w in open('words.txt')]
@ishahid
ishahid / recursive_sum.py
Created January 15, 2014 02:39
Recursive sum of all elements of a given list.
def sum(args):
""" Returns sum of all elements of a given list, recursively """
if len(args) == 0:
return 0
return args[0] + sum(args[1:])
if __name__ == "__main__":
@ishahid
ishahid / api-key.py
Last active January 6, 2016 12:42
Generates a random API key
#!/usr/bin/python
"""Generate a random API key
https://gist.github.com/ishahid/54f0478e480234fa44ec
"""
import base64
import hashlib
import random
@ishahid
ishahid / quote.py
Last active February 8, 2016 02:32
Get quote from stock market using Google Finance
#!/usr/bin/python
"""Get quote from stock market using Google Finance
https://gist.github.com/ishahid/9f0823c19b6d387529f4
"""
try:
import os, sys
import json
import googlefinance as google

Keybase proof

I hereby claim:

  • I am ishahid on github.
  • I am ishahid (https://keybase.io/ishahid) on keybase.
  • I have a public key whose fingerprint is DD3B DD86 B1D3 AD6B 2F49 722E 1451 55DE 0BAD E780

To claim this, I am signing this object:

++++++++++ initialize counter (cell #0) to 10
[ use loop to set the next six cells to 70/80/90/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++ add 8 to cell #2
> +++++ ++++ add 9 to cell #3
> +++++ +++++ add 10 to cell #4
> +++ add 3 to cell #5
> + add 1 to cell #6
<<<<<< - decrement counter (cell #0)
]
@ishahid
ishahid / reserved_words.py
Last active February 27, 2017 23:47
Reserved words to exclude when creating usernames (or any other resource).
# A list of possible reserved words
reserved_words = [
# Companies
'amazon', 'apple', 'atlassian', 'canonical', 'facebook', 'github',
'google', 'htc', 'huawei', 'ibm', 'microsoft', 'mozilla', 'naughtydog',
'nintendo', 'nokia', 'rim', 'samsung', 'sony', 'toshiba', 'twitter',
'ubisoft', 'wikipedia', 'xref', 'yahoo',
# Operating systems
@ishahid
ishahid / .bash_profile
Last active September 20, 2017 23:54
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configuration and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management