Skip to content

Instantly share code, notes, and snippets.

View ahlusar1989's full-sized avatar
๐Ÿ€
Let's Go!

Saran Ahluwalia ahlusar1989

๐Ÿ€
Let's Go!
View GitHub Profile
@wffurr
wffurr / staqueue.py
Created March 11, 2014 02:26
Queue implementation using two stacks
"""
Implement a queue with two stacks
Interview practice from coding for interviews - March 2014
"""
class Staqueue(object):
""" Implements a queue with two stacks
One stack is used for enqueing, and the other dequeing. If an enqueue is requested
@tmpvar
tmpvar / chainhull.js
Created March 3, 2014 21:26
chainHull_2D(): Andrew's monotone chain 2D convex hull algorithm
var isLeft = function(p1, p2, p3) {
return (p2.position[0] - p1.position[0])*(p3.position[1] - p1.position[1]) - (p3.position[0] - p1.position[0])*(p2.position[1] - p1.position[1]);
};
// chainHull_2D(): Andrew's monotone chain 2D convex hull algorithm
// see: http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
// Input: P[] = an array of 2D points
// presorted by increasing x- and y-coordinates
// n = the number of points in P[]
// Output: H[] = an array of the convex hull vertices (max is n)
@phillipjohnson
phillipjohnson / yelp_api_intro.py
Created February 8, 2014 20:18
A basic introduction to using the rauth library and the Yelp API.
import rauth
import time
def main():
locations = [(39.98,-82.98),(42.24,-83.61),(41.33,-89.13)]
api_calls = []
for lat,long in locations:
params = get_search_parameters(lat,long)
api_calls.append(get_results(params))
#Be a good internet citizen and rate-limit yourself
@d3noob
d3noob / .block
Last active October 21, 2023 12:33
D3.js tree diagram generated from external (JSON) data
license: mit
@dloman
dloman / xvfb
Last active September 12, 2023 12:32 — forked from jterrace/xvfb
### BEGIN INIT INFO
# Provides: Xvfb
# Required-Start: $local_fs $remote_fs
# Required-Stop:
# X-Start-Before:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Loads X Virtual Frame Buffer
### END INIT INFO
import numpy as np
def GEPP(A, b, doPricing = True):
'''
Gaussian elimination with partial pivoting.
input: A is an n x n numpy matrix
b is an n x 1 numpy array
output: x is the solution of Ax=b
with the entries permuted in
@mblondel
mblondel / letor_metrics.py
Last active September 19, 2024 06:13
Learning to rank metrics.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
def ranking_precision_score(y_true, y_score, k=10):
"""Precision at rank k
Parameters
@aymanfarhat
aymanfarhat / karger.py
Last active May 2, 2021 03:33
Implementation of Karger's algorithm in Python. Randomized algorithm for computing minimum cuts in a connected graph. Input file source is Coursera's Algo 1 course HW3: http://spark-public.s3.amazonaws.com/algo1/programming_prob/kargerMinCut.txt
import re
import random
# Load the file into a graph represented by a dict of lists
def load_graph():
g = {}
f = open('kargerMinCut.txt')
lines = f.readlines()
f.close()
@niccokunzmann
niccokunzmann / hanging_threads.py
Last active November 4, 2024 14:48
This module prints all hanging threads that are dead locked. It is for Python 2 and 3. Installable: https://pypi.python.org/pypi/hanging_threads
## The MIT License (MIT)
## ---------------------
##
## Copyright (C) 2014 Nicco Kunzmann
##
## https://gist.github.com/niccokunzmann/6038331
##
## Permission is hereby granted, free of charge, to any person obtaining
## a copy of this software and associated documentation files (the "Software"),
@karmadude
karmadude / README.md
Last active February 7, 2017 08:24
San Francisco Contours