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
| #!/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 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 subprocess | |
| #TES | |
| # -- Global Variables Declarations -- # | |
| USER = 'Oz Tamir' | |
| EMAIL = 'TheOzTamir@gmail.com' | |
| #REPO = 'https://' + USER + '@github.com/OzTamir/git-fix.git' | |
| # Changed files | |
| modified = [] | |
| # Deleted files to remove from remote | |
| deleted = [] |
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
| #! /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 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 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 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 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 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 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 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
| # 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 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
| #! /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) |
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 visual_board(N, game_state, only_row=False): | |
| '''Format a board game per game_state. If only_row is True, the output will be only the specified row''' | |
| board = [[] for i in range(N)] | |
| empty = '-|' | |
| for column, row in enumerate(game_state): | |
| board[row] = str(row) + ' |' + empty * column + 'Q|' + (empty * (N - column))[:-1] + '|' | |
| board[row] = board[row][:-2] + '\n' | |
| if not isinstance(only_row, bool) and only_row == row: | |
| return board[row] | |
| return ' ' + ' '.join(str(i) for i in range(n)) + '\n' + ''.join(board) |
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 Matrix with display() function for image visualization | |
| ############################################################################# | |
| class Matrix: | |
| """ | |
| Represents a rectangular matrix with n rows and m columns. | |
| """ | |
| def __init__(self, n, m, val=0): |
OlderNewer