Skip to content

Instantly share code, notes, and snippets.

@mailpraveens
mailpraveens / levenshteinDistance.py
Created March 21, 2014 08:02
Recursive program to find the levenshtein distance between two strings
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 / BFSandDFS.cpp
Created August 3, 2014 15:47
BFS and DFS implementation in C++
#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
#include <iostream>
using namespace std;
#include <stdlib.h> /* qsort */
int compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main()
{
#include <iostream>
using namespace std;
#include <stdlib.h> /* qsort */
int compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main4()
{
@mailpraveens
mailpraveens / checkEmptyObject
Created August 20, 2014 11:15
Small snipped to check if a NSString, NSArray or any collection is empty, works for nil objects too.
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);
}
@mailpraveens
mailpraveens / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console