Skip to content

Instantly share code, notes, and snippets.

Praveen mailpraveens

Block or report user

Report or block mailpraveens

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mailpraveens
mailpraveens / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mailpraveens
mailpraveens / checkEmptyObject
Created Aug 20, 2014
Small snipped to check if a NSString, NSArray or any collection is empty, works for nil objects too.
View checkEmptyObject
static inline BOOL checkIfEmpty(id obj) {
return thing == nil ||
([obj respondsToSelector:@selector(length)] && [(NSData *)obj length] == 0) ||
([obj respondsToSelector:@selector(count)] && [(NSArray *)obj count] == 0);
}
View AugustChallenge1.cpp
#include <iostream>
using namespace std;
#include <stdlib.h> /* qsort */
int compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main4()
{
View GameOfSurvival.cpp
#include <iostream>
using namespace std;
#include <stdlib.h> /* qsort */
int compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main()
{
@mailpraveens
mailpraveens / BFSandDFS.cpp
Created Aug 3, 2014
BFS and DFS implementation in C++
View BFSandDFS.cpp
#include<iostream>
#include <list>
using namespace std;
class Graph {
int V;
list <int> * adj;
void DFSUtil(int v, bool visited[]); // A function used by DFS
@mailpraveens
mailpraveens / levenshteinDistance.py
Created Mar 21, 2014
Recursive program to find the levenshtein distance between two strings
View levenshteinDistance.py
def calculateLevenSteninDistance(a,b):
if not a: return len(b)
if not b: return len(a)
return min(calculateLevenSteninDistance(a[1:], b[1:])+(a[0] != b[0]), calculateLevenSteninDistance(a[1:], b)+1, calculateLevenSteninDistance(a, b[1:])+1)
@mailpraveens
mailpraveens / FindMergePointLinkedLists.py
Created Mar 20, 2014
Find the merge point of two linked list
View FindMergePointLinkedLists.py
def findDivergePointForOfTwoLinkedLists(list1, list2):
# Assuming the list class has a method length to give the length of the list
lengthList1 = list1.length()
lengthList2 = list2.length()
differnce = lengthList2 - lengthList1
if(lengthList2>=lengthList1):
while(differnce!=0):
list2 = list2.next
differnce -= 1
@mailpraveens
mailpraveens / findLCA.py
Created Mar 20, 2014
Find the Lowest Common Ancestor of Binary Search Tree
View findLCA.py
def findLCA(node,value1,value2):
if(node == None):
return None
#move to right if values are greater
if(node.value < value1 and node.value < value2):
return findLCA(node.right,value1, value2)
#move to left if values are smaller
if(node.value > value1 and node.value > value2):
return findLCA(node.left,value1, value2)
# Whereever it diverges, return the node as its the LCA
@mailpraveens
mailpraveens / printCounterClockwiseBinaryTree.py
Created Mar 20, 2014
Print a binary tree counter clock wise
View printCounterClockwiseBinaryTree.py
'''
1
2 3
4 5 6 7
should print 1,2,4,5,6,7,3,1
'''
@mailpraveens
mailpraveens / heapify.py
Created Mar 20, 2014
Heapify method which can be used in heap sort
View heapify.py
#max heap construction
def heapify(items,idx):
left = leftChild(idx)
right = rightChild(idx)
largest = -1
if(left < len(items) and items[left] > items[idx]):
largest = left
else:
largest = idx
You can’t perform that action at this time.