Skip to content

Instantly share code, notes, and snippets.

View Mhs-220's full-sized avatar
💻
Programming

MohammadHossein Shahmohammadi Mhs-220

💻
Programming
  • FashionCloud
  • Amsterdam
  • 13:55 (UTC +02:00)
View GitHub Profile
@Mhs-220
Mhs-220 / resize-image.sh
Created November 14, 2020 08:55
Batch image resize with convert
#!/bin/bash
# The script takes 3 args.
# -s for size (default: 1024)
# -i for input folder (default: current dir)
# -o for output folder (default: resized)
#
# For example:
# ./resize-image.sh -i pexels -o output_folder -s 1800
# Default Values
@Mhs-220
Mhs-220 / hook.sh
Created August 2, 2020 07:48
A Libvirt hook to auto setup a port on ip to access virtual machines.
#!/bin/bash
#
# Hook script for QEMU
#
# adds port forwards via IPtables and ARP to your VMs
#
# Implement: Erico Mendonca (erico.mendonca@suse.com)
# Change: Mohammadhossein Shahmohammadi (hos1377@gmail.com)
# 2020/Jul
#
@Mhs-220
Mhs-220 / sample-1.py
Last active July 4, 2020 01:32
You Probably Don't Know Python - Part 2
# Without Walrus Operator
n = len("Hello, World")
if n > 10:
print(f"WoW, {n} is Tooooo Large!")
# With Walrus Operator
if (n := len("Hello, World")) > 10:
print(f"WoW, {n} is Tooooo Large!")
@Mhs-220
Mhs-220 / certbot-authenticate.sh
Created June 1, 2020 21:33
Auto Renew SSL for Cpanel
#!/bin/bash
echo $CERTBOT_TOKEN
echo $CERTBOT_VALIDATION > $CERTBOT_TOKEN
ftp -n $FTP_ADDR << END_SCRIPT
quote USER $FTP_USER
quote PASS $FTP_PASS
binary
put "$CERTBOT_TOKEN"
quit
@Mhs-220
Mhs-220 / google-tts.py
Last active April 3, 2019 20:08
Google TTS script for GoldenDict
import os
import sys
import json
import base64
user_input = ' '.join(sys.argv[1:])
# Payload that we should send to google api
payload = '{"input":{"text":"%s"},"voice":{"languageCode":"en-US","name":"en-US-Wavenet-D"},"audioConfig":{"audioEncoding":"LINEAR16","pitch":"0.00","speakingRate":"1.00"}}' % user_input
@Mhs-220
Mhs-220 / funcs.py
Created August 27, 2018 08:04
Add order field to graphene django
import graphene
from graphene_django.filter import DjangoFilterConnectionField
class CustomDjangoFilterConnectionField(DjangoFilterConnectionField):
@classmethod
def connection_resolver(cls, resolver, connection, default_manager, max_limit,
enforce_first_or_last, filterset_class, filtering_args,
root, info, **args):
filter_kwargs = {k: v for k, v in args.items() if k in filtering_args}
qs = filterset_class(
@Mhs-220
Mhs-220 / handle_sns.py
Created August 27, 2018 07:56
A simple handler for aws sns in marketplace for flask
@mod_auth.route('/handle_sns', methods = ['GET', 'POST', 'PUT'])
def handle_sns():
try:
notification = json.loads(request.data)
notification_type = notification["Type"]
if notification_type == 'SubscriptionConfirmation':
if 'SubscribeURL' in notification:
url = notification['SubscribeURL']
print("Click for subscribe -> %s" % url)
# There is another state for unsubscribe confirmation,