Skip to content

Instantly share code, notes, and snippets.

@nava45
nava45 / inplace_rearrange.py
Last active April 6, 2017 11:22
Inplace linked list re-arrangement
'''
Problem statement:
you have input list: L0 -> L1 -> L2 -> ..... -> Ln -> Ln-1
output: L0 -> Ln -> L1 -> Ln-1 -> L2 -> Ln-2 -> ....
'''
class Node(object):
def __init__(self, val, _next=None):
@nava45
nava45 / fogcreek_interview_ques.py
Created February 3, 2016 05:32
Fogcreek is founded by joel spolsky. There is a open position for support engineer, if you solve the problem here --> (http://www.fogcreek.com/Jobs/SupportEngineer/)
import operator
"""
Question:
Sort the characters in the following string:
abcdefghijklmnopqrstuvwxyz_
by the number of times the character appears in the following text (descending):
@nava45
nava45 / SqlAlchemyexception
Created June 24, 2014 10:43
SqlAlchemy Event Exception
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
@nava45
nava45 / Infix expression Evaluation
Created August 25, 2013 11:38
Infix expression Evaluation in Python
import operator
ops = {'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.div}
class Stack:
def __init__(self):
self.mylist = []
def isempty(self):
return True if len(self.mylist) == 0 \
from inspect import getmembers, getargspec, ismethod
from functools import wraps
from decorator import decorator
# Some super basic decorators
def std_decorator(f):
def std_wrapper(*args, **kwargs):
return f(*args, **kwargs)
return std_wrapper