Skip to content

Instantly share code, notes, and snippets.

View ashwch's full-sized avatar
😎
Look at me!

Ashwini Chaudhary ashwch

😎
Look at me!
View GitHub Profile
@ashwch
ashwch / binary_search.py
Last active December 14, 2015 19:09
Binary search in python
def binary_search(lis,num):
low=0
high=len(lis)-1
loops=0
ret=-1 #return -1 if item is not found
while low<=high:
mid=(low+high)/2
if num<lis[mid]:
high=mid-1
elif num>lis[mid]:
@ashwch
ashwch / stack.py
Last active December 15, 2015 05:59
Stack Class in python
class Stack:
def __init__(self):
self.stack=[]
def top(self):
if not self.is_empty():
return self.stack[-1]
def size(self):
return len(self.stack)
def is_empty(self):
return not bool(self.stack)
@ashwch
ashwch / heap.py
Last active December 4, 2023 03:23
Heap implementation in Python
class Heap:
def __init__(self,lis,n):
self.length=n #size of heap
self.heap=[None]*(n+1) #intialize an empty list
self.last=0 #index where the last item was inserted
for x in lis:
self.heap_insert(x)
def heap_insert(self,item):
self.last+=1
@ashwch
ashwch / 0_reuse_code.js
Created July 6, 2014 11:58
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
@ashwch
ashwch / Tabs
Created September 18, 2014 20:07
Open Firefox with the url list provided.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
urls = ['http://google.com', 'http://stackoverflow.com', 'http://livescores.com']
browser = webdriver.Firefox()
for url in urls:
browser.get(url)
body = browser.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't')
browser.get(url)
import tokenize
from StringIO import StringIO
line = 'foo(a=100, b="124, 456, 789", c=[1, 2, 3])\n'
for tkn, name, _, _, _ in tokenize.generate_tokens(StringIO(line).readline):
if tkn == 1:
print name
@ashwch
ashwch / so.py
Last active August 29, 2015 14:19
with open('foo.txt', 'w') as f:
f.write('aa\n\rbbb\n\rcccc\n\rddddd')
with open('foo.txt') as f:
print f.readlines()
# ['aa\n', '\rbbb\n', '\rcccc\n', '\rddddd']
@ashwch
ashwch / done_dona_done_done.py
Created November 13, 2015 11:36
done dona done done
# Shortest program to print 'done dona done done' without
# using any of the characters 'd', 'o', 'n', 'a' and 'e'.
# 46 characters.
x='\x64\x6f\x6e\x65';print x,x[:-1]+'\x61',x,x
### Keybase proof
I hereby claim:
* I am ashwch on github.
* I am ashwch (https://keybase.io/ashwch) on keybase.
* I have a public key whose fingerprint is E191 F0F5 7AB7 3DDC 850E 93EF BB99 A6BC 7284 052F
To claim this, I am signing this object: