Skip to content

Instantly share code, notes, and snippets.

@Eitol
Eitol / forming_a_magic_square.py
Created September 7, 2017 03:28
HackerRank "Forming a Magic Square" python solution
import sys
# Solve https://www.hackerrank.com/challenges/magic-square-forming/problem
matrix_list = [[[8, 1, 6], [3, 5, 7], [4, 9, 2]],
[[6, 1, 8], [7, 5, 3], [2, 9, 4]],
[[4, 9, 2], [3, 5, 7], [8, 1, 6]],
[[2, 9, 4], [7, 5, 3], [6, 1, 8]],
[[8, 3, 4], [1, 5, 9], [6, 7, 2]],
[[4, 3, 8], [9, 5, 1], [2, 7, 6]],
[[6, 7, 2], [1, 5, 9], [8, 3, 4]],
@Eitol
Eitol / merge_mio.py
Created June 4, 2017 13:20
Merge sort using queues made in python3
from collections import deque
def merge_sort(v: list) -> list:
if len(v) < 2:
return v
middle = int(len(v) / 2)
left = deque(merge_sort(v[:middle]))
right = deque(merge_sort(v[middle:]))
out = []
@Eitol
Eitol / view_names.py
Created March 17, 2017 17:15
View names of all Views CouchDB in Python
_db = couchdb.Server("http://user:miclave_loca@192.168.1.250:5984/")['base_de_datos_loca']
def get_all_views(db: couchdb.Server) -> list:
views_raw = _db.view('_all_docs', startkey="_design/", endkey="_design0", include_docs=True)
return [view.id.split('/')[1] for view in views_raw.rows]
return views
if __name__ == '__main__':
print(get_all_views(_db))
@Eitol
Eitol / gist:7fe6957d2ae58665a28438fc4ae9c29e
Created March 14, 2017 16:22
Return the system timezone in linux
@staticmethod
def get_system_timezone() -> str:
"""
Retorna el timezone del sistema
:return: Ej: America/Caracas
"""
str_timezone = subprocess.getoutput('ls /etc/ -l | grep localtime | awk \'{print $11}\'')
assert str_timezone is not None and len(str_timezone) and \
str_timezone.find('../usr/share/zoneinfo/') != -1, "TIMEZONE_GET_ERROR:"
str_timezone = str_timezone.replace('../usr/share/zoneinfo/', '')