This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| **Foo** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### 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: |