Skip to content

Instantly share code, notes, and snippets.

View namieluss's full-sized avatar
🏠
Working from home

Suleiman namieluss

🏠
Working from home
View GitHub Profile
@namieluss
namieluss / openssl_csr_commands.md
Last active February 25, 2020 11:41
Open ssl command for generating and verifying .csr (certificate signing request) file.

Generate a certificate signing request (CSR) for an existing private key

openssl req -out certificate.csr -key private.key -new -sha256

Check a Certificate Signing Request >openssl req -text -noout -verify -in certificate.csr

@namieluss
namieluss / flask_permission_decorator.py
Created February 25, 2020 12:01
A python flask decorator to check user access level before entry to page.
from flask import Flask, g, abort
app = Flask(__name__)
# This decorator checks the role of the user before allowing entry
def check_role(access_level, json=False):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
@namieluss
namieluss / python-pillow-image-grayscale.py
Last active March 12, 2020 10:56
Convert Image to Grayscale (black and white)
from PIL import Image
# open colour image
img = Image.open("test_image.jpg")
# convert image to black and white
img = img.convert("1")
# save new image
img.save("test_image_grayscale.jpg")
@namieluss
namieluss / python-pillow-image-thumbnail.py
Created March 12, 2020 10:57
Generate a Thumbnail from an Image using Python Pillow
from PIL import Image
# open image
img = Image.open("test_image.jpg")
# set the maximum width and height for the thumbnail
max_thumbnail_size = (200, 200)
# applying size for thumbnail
img.thumbnail(max_thumbnail_size)
@namieluss
namieluss / python-pillow-image-watermark.py
Created March 16, 2020 05:22
Add watermark to an Image using Python Pillow
from PIL import Image, ImageDraw, ImageFont
# open image to apply watermark to
img = Image.open("watermark_test.jpg")
img.convert("RGB")
# get image size
img_width, img_height = img.size
# 5 by 4 water mark grid
@namieluss
namieluss / spreadsheet-authorize.js
Created March 18, 2020 04:18
Firebase Cloud Functions with Google Spreadsheet
const fs = require("fs");
const readline = require("readline");
const { google } = require("googleapis");
// If modifying these scopes, delete token.json.
const SCOPES = ["https://www.googleapis.com/auth/spreadsheets"];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = "token.json";
@namieluss
namieluss / nginx-server-static-html-file.sh
Created April 5, 2020 01:27
Serving static index.html file in nginx server
server {
listen 80;
listen 443 ssl;
server_name localhost;
root /home/mywebstite/;
index index.html;
location / {
@namieluss
namieluss / flask-celery-mongodb-app.py
Created June 6, 2020 08:06
This is a simple app written in Python Flask with MongoDB mongodb database. Celery is used to manage task queue.
__author__ = "Suleiman"
from celery import Celery
from flask import Flask, render_template
from pymongo import MongoClient
from .constants import *
app = Flask(__name__, template_folder="templates")
@namieluss
namieluss / flask-celery-mongodb-task.py
Created June 6, 2020 08:07
This is a simple app written in Python Flask with MongoDB mongodb database. Celery is used to manage task queue.
__author__ = "Suleiman"
from datetime import datetime
from flask import request
from requests import get as http_getter
from . import app, db, celery
@namieluss
namieluss / youtube-clip.sh
Created July 7, 2020 10:57
A simple script to download and clip out youtube videos with youtube-dl and ffmpeg.
#!/bin/bash
# to run and extract clip
# ./youtube-clip.sh UF8uR6Z6KLc --trim 00:03:32 00:05:32
# youtube video id
vid="$1";
echo "[youtube-dl] download video from youtube in .mp4 format...";
youtube-dl --format mp4 $vid -o '%(title)s.%(ext)s';