Last active
June 26, 2021 02:15
-
-
Save yezz123/50f627d1b474af2084dc3cc9023f299a to your computer and use it in GitHub Desktop.
Here i will post my Helpful script can be used 🚀
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 importlib | |
def get_class_from_module(module_class): | |
"""Get Class from a module""" | |
module_name, class_name = module_class.rsplit('.', 1) | |
return getattr(importlib.import_module(module_name), class_name) |
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 calendar | |
def month_start(date): | |
"""Return the date with the start of the month""" | |
return date.replace(day=1) | |
def month_end(date): | |
"""Return the date with the end of the month""" | |
return date.replace(day=calendar.monthrange(date.year, date.month)[1]) |
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
jQuery(document).ready(function ($) { | |
console.log("Customizing DateTime widget"); | |
DateTimeShortcuts.clockHours.default_ = []; | |
for (let hour = 6; hour <= 21; hour++) { | |
let verbose_name = new Date(1970, 1, 1, hour, 0, 0).strftime("%H:%M"); | |
DateTimeShortcuts.clockHours.default_.push([verbose_name, hour]); | |
} | |
}); |
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 qrcode | |
class QRCodeImage(object): | |
def __init__(self, data, fit=True, size=8, border=1): | |
self.data = data | |
self.fit = fit | |
self.size = size | |
self.border = border | |
def save(self, filename): | |
qrcode_image = qrcode.QRCode( | |
version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_M, | |
box_size=self.size, | |
border=self.border, | |
) | |
qrcode_image.add_data(self.data) | |
qrcode_image.make(fit=self.fit) | |
qrcode_image.make_image().save(filename) |
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 base64 | |
class URI(object): | |
@staticmethod | |
def generic(protocol, host, location, arguments=None): | |
return '{PROTOCOL}://{HOST}/{LOCATION}{QUESTION}{ARGUMENTS}'.format( | |
PROTOCOL=protocol, | |
HOST=host, | |
LOCATION=location, | |
QUESTION='?' if arguments else '', | |
ARGUMENTS=arguments) | |
@staticmethod | |
def otpauth_totp(secret, account, issuer): | |
secret_encoded = base64.b32encode(secret.encode()).decode('utf-8') | |
return URI.generic(protocol='otpauth', | |
host='totp', | |
location='{ISSUER}:{ACCOUNT}'.format( | |
ISSUER=issuer, ACCOUNT=account), | |
arguments='secret={SECRET}&issuer={ISSUER}'.format( | |
SECRET=secret_encoded, ISSUER=issuer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment