This file contains 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 DoTurn(pw): | |
Overtake(pw) | |
def Attack(pw, source, target, ships): | |
''' | |
A custom controller for pw built-in IssueOrder() method | |
''' | |
if source.NumShips() < ships: | |
send = source.NumShips() | |
else: |
This file contains 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
for cnt in contours: | |
approx = cv2.approxPolyDP(cnt,cv2.arcLength(cnt,True)*0.02,True) | |
if len(approx)==4: | |
cv2.drawContours(im,[approx],0,(0,0,255),2) | |
x,y,w,h = cv2.boundingRect(cnt) |
This file contains 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
#!/usr/bin/env python | |
import socket | |
DATA = {} | |
def parser(*args): | |
'''Parse key-value pairs recived from client''' | |
new_data = {} | |
dict_data = args[0] | |
for pair in dict_data: |
This file contains 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 subprocess | |
#TES | |
# -- Global Variables Declarations -- # | |
USER = 'Oz Tamir' | |
EMAIL = '[email protected]' | |
#REPO = 'https://' + USER + '@github.com/OzTamir/git-fix.git' | |
# Changed files | |
modified = [] | |
# Deleted files to remove from remote | |
deleted = [] |
This file contains 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
#! /usr/bin/env python | |
import sys | |
def commentsTitler(filename): | |
'''WARNING: This will overwrite the file content, make sure you have a backup''' | |
# Get The Appropriate Comment Prefix For The File Type | |
ext = {'py' : '#', 'cs' : '//', 'cpp' : '//', 'h' : '//', 'asm' : ';', 'gcode' : ';', 'java' : '//', 'js' : '//'} | |
COMMENTS_PREFIX = ext[filename[filename.find('.') + 1:].lower()] | |
# Get All The Lines In The File | |
with open(filename, 'r') as file: |
This file contains 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 Hanoi(ndisks, start_rod=1, end_rod=3): | |
if ndisks: | |
Hanoi(ndisks - 1, start_rod, 6 - start_rod - end_rod) | |
print('Move disk {DISK} from {START} to {END}'.format(DISK = ndisks, START = start_rod, END = end_rod)) | |
Hanoi(ndisks - 1, 6 - start_rod - end_rod, end_rod) | |
if __name__ == '__main__': | |
print('Towers Of Hanoi - Recursion!') | |
disks = input('Enter number of disks >>>') | |
Hanoi(int(disks)) |
This file contains 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 heapq import merge | |
import random | |
def merge_sort(m): | |
if len(m) <= 1: | |
return m | |
middle = len(m) / 2 | |
left = m[:middle] | |
right = m[middle:] |
This file contains 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 number_of_paint_options(n, m): | |
def find_num_options(n, m): | |
'''Find the number of options to paint m (or more) pixels in a pixel row with n pixels''' | |
return 1 + sum((k - m + 1) * find_num_options(n - k - 1, m) for k in range(m, n + 1)) | |
if m > n or m == 0: | |
return 0 | |
elif n == m: | |
return 1 | |
return find_num_options(n, m) |
This file contains 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
# 3 - Fizz | |
# 5 - Buzz | |
# 15 - FizzBuzz | |
# With empty strings | |
a = ['Fizz' * (not (i % 3)) + 'Buzz' * (not (i % 5)) for i in xrange(100)] | |
# Without empty strings | |
b = filter(None, (['Fizz' * (not (i % 3)) + 'Buzz' * (not (i % 5)) for i in xrange(100)])) |
This file contains 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
#! /usr/bin/env python | |
import sys | |
import re | |
def space_standert(filename, copy=True, no_regex=True): | |
''' | |
filename, [copy (True creates a copy, False overwrites (True is recomanded!)), no_regex (Can we risk ruined regex?)] | |
Format the file 'filename' to match the spacing standert (commas and equality marks) | |
''' | |
# Regex for these cases: X(OP)Y || X (OP)Y || X(OP) Y (Works for !<>*+-= operators as well as '(OP)=' operators) |
OlderNewer