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 requests, googlehomepush, time, datetime, json, os, codecs, logging | |
custom_alarms = {'07:50': 'You have to leave now', | |
'07:30': 'You have 20 minutes'} | |
# We don't want to read prayer times from the web all the time, so we cache it | |
# for the day | |
current_dir = os.path.abspath(os.path.dirname(__file__)) | |
today = datetime.datetime.today() | |
today_file = os.path.join(current_dir, today.strftime('%d-%m-%Y.prayer_times')) |
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
# How to run? | |
# > python are_anagrams.py hello lolhe | |
# True | |
from collections import Counter | |
import sys | |
print(Counter(sys.argv[1]) == Counter(sys.argv[2])) |
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 math | |
def string_norm(s): | |
return math.sqrt(sum(ord(c) ** 2 for c in s if c != ' ')) | |
def anagram_detection(s1,s2): | |
return string_norm(s1) == string_norm(s2) | |
s1 = input("Please enter first string: ").lower() | |
s2 = input("Please enter second string: ").lower() |
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
#! /bin/python | |
# 7 minutes Ansible module to list groups in inventory (Python version) :D | |
# You can print output like "pretty-print" outside Ansible by using: | |
#./listgroups /path/to/ansible.cfg | python -m json.tool | |
import sys | |
import re | |
import json | |
#get hosts inventory from ansible.cfg 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
import os | |
import sys | |
from django.conf import settings | |
from django.core.exceptions import ImproperlyConfigured | |
from django.template.base import TemplateDoesNotExist | |
from django.template.loaders.app_directories import Loader as BaseLoader | |
from django.utils._os import safe_join | |
from django.utils.importlib import import_module | |
from django.utils import six | |
from mezzanine.core.request import current_request |
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 pkg_resources, pprint | |
requires = {p.key: [r.key for r in p.requires()] for p in pkg_resources.working_set} | |
def graph(pkg): | |
if not requires[pkg]: | |
return {pkg: {}} | |
return {pkg: {k: v for p in requires[pkg] for k, v in graph(p).items() }} |
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
key_mapping = [ | |
('abc', '2'), | |
('def', '3'), | |
('ghi', '4'), | |
('jkl', '5'), | |
('mno', '6'), | |
('pqrs', '7'), | |
('tuv', '8'), | |
('wxyz', '9'), | |
(' ', '0'), |
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
# Analysis: | |
# | |
# Let's try to find the optimal range. We know that | |
# 1. 918273645 is a 1-9 pandigital & is a concatenated product, which means that this number is either the largest or | |
# below it, so we search from this number up | |
# 2. Then we find that the number we're trying to search for should start with 9, e.g. 9, 91, 945, etc | |
# 3. len(concat_product(x=90, n=3)) = 8, len(concat_product(x=90, n=4)) = 11. This range won't work. | |
# 4. len(concat_product(x=9000, n=2)) = 9. This is where we should start. | |
# 5. Taking #1 in consideration, we will start from 9182 till 9999 | |
# 6. To get the pandigital number from a this range, we can multiply by n * 100000 + n * 2 => n * 100002 |
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
; Show Microsoft snipping tool on PrintScreen | |
#SingleInstance force | |
PRINTSCREEN:: | |
Run snippingtool | |
return |
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
# Kill a process, given part of its name | |
# | |
# How I'm doing it:- | |
# | |
# 1. Get a list of all processes | |
# 2. Grep for any process where "portal" is part of the | |
# command line used to launch it | |
# 3. I will get 2 processes: 1 of them is what I'm searching for & | |
# the other is just this grep command I'm running. I remove it by | |
# removing anything with "grep" in its command line |
NewerOlder