Skip to content

Instantly share code, notes, and snippets.

View anilpai's full-sized avatar
:octocat:
Coding

Anil Pai anilpai

:octocat:
Coding
View GitHub Profile
@anilpai
anilpai / flatten.py
Created February 2, 2017 01:29
Flatten a list
def flatten(lst):
'''
Flattens a list of lists.
'''
r = []
for x in lst:
if type(x) is list:
r.extend(x)
else:
r.append(x)
class Student:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
@classmethod
def from_string(cls, name_str):
first_name, last_name = map(str, name_str.split(' '))
student = cls(first_name, last_name)
@anilpai
anilpai / jdbc.py
Created March 19, 2018 19:22
Connecting to JDBC databases using python
import jaydebeapi
username = ''
password = ''
conn = jaydebeapi.connect('com.qubole.jdbc.jdbc41.core.QDriver',
'jdbc:qubole://hive/default/db_name?endpoint=https://us.qubole.com',
['', password])
if conn:
@anilpai
anilpai / 01_Google_Code_Jam_2018.py
Created April 10, 2018 03:31
Saving the Universe Again
def min_hacks(d, p):
p_list = list(p)
can_swap = True
curr_damage, num_of_hacks = (0,)*2
while can_swap:
curr_damage, shoot_damage = 0, 1
for c in p_list:
if c == 'S':
curr_damage += shoot_damage
@anilpai
anilpai / README.md
Last active June 29, 2018 07:08
Which Emoji to Use? ❓

Commit Type Emoji Initial Commit 🎉 Party Popper Version Tag 🔖 Bookmark New Feature ✨ Sparkles Bugfix 🐛 Bug Security Fix 🔒 Lock Metadata 📇 Card Index Refactoring ♻️ Black Universal Recycling Symbol Documentation 📚 Books Internationalization 🌐 Globe With Meridians

@anilpai
anilpai / gist:9011555223031e837bc45946d22054c2
Created November 1, 2018 16:00
To create a python distribution
python3 setup.py sdist upload -r pypi
class LNode:
"""defining a linked list node"""
def __init__(self, value,next=None, random=None):
self.value = value
self.random = random
self.next = next
def __str__(self):
return "(%s)"%(self.value)
class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_a_tree():
root = TreeNode(10)
a = TreeNode(20)
@anilpai
anilpai / clone_graph.py
Created February 3, 2020 22:33
algo to clone a graph
class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_a_tree():
root = TreeNode(10)
a = TreeNode(20)