Skip to content

Instantly share code, notes, and snippets.

Avatar

Khaled Monsoor kmonsoor

View GitHub Profile
@kmonsoor
kmonsoor / create-version.py
Created May 24, 2019
Jira-Python : Create versions for project
View create-version.py
# replce server address with actual Jira host for your case
options = {'server': 'https://jira.atlassian.com'}
#login
jira = JIRA(options, basic_auth=(os.environ['JIRA_USERNAME'], os.environ['JIRA_PASSWORD']))
#get currently available version names
project = jira.project('PROJECT-KEY')
versions = jira.project_versions(project)
current_versions = [v.name for v in reversed(versions)]
@kmonsoor
kmonsoor / getScript.js
Created Jul 3, 2018
jquery $.getScript() replacement with vanilla JavaScript
View getScript.js
"use strict";
// src: https://stackoverflow.com/a/28002292
const getScript = (source, callback) => {
var script = document.createElement('script');
var prior = document.getElementsByTagName('script')[0];
script.async = 1;
script.onload = script.onreadystatechange = (_, isAbort) => {
if (isAbort || !script.readyState || /loaded|complete/.test(script.readyState)) {
@kmonsoor
kmonsoor / secureConsole.js
Last active May 29, 2018
JavaScript -- Disable console.log & other in-browser console.* methods
View secureConsole.js
"use strict";
(() => {
var console = (window.console = window.console || {});
[
"assert", "clear", "count", "debug", "dir", "dirxml",
"error", "exception", "group", "groupCollapsed", "groupEnd",
"info", "log", "markTimeline", "profile", "profileEnd", "table",
"time", "timeEnd", "timeStamp", "trace", "warn"
].forEach(method => {
console[method] = () => {};
@kmonsoor
kmonsoor / beautify_bash.py
Created Mar 23, 2018
Beautify your Bash code
View beautify_bash.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#**************************************************************************
# Copyright (C) 2011, Paul Lutus *
# *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU General Public License as published by *
# the Free Software Foundation; either version 2 of the License, or *
# (at your option) any later version. *
@kmonsoor
kmonsoor / http_status_codes.js
Created Feb 12, 2018
Node.js HTTP Status codes
View http_status_codes.js
// $ node
// > process.version;
// 'v8.9.4'
// > http.STATUS_CODES
{ '100': 'Continue',
'101': 'Switching Protocols',
'102': 'Processing',
'200': 'OK',
'201': 'Created',
@kmonsoor
kmonsoor / snippets.sql
Last active Feb 2, 2018
MySQL get current date in PST timezone
View snippets.sql
-- Get current date in PST time-zone
SELECT DATE_ADD(DATE(CONVERT_TZ(current_time(), 'GMT', 'US/Pacific'));
@kmonsoor
kmonsoor / rename_to_exif_uid.py
Last active Dec 26, 2017
Rename JPG files to `Unique image id` of EXIF data. If you find this useful, as a 👍, give this gist a ⭐️
View rename_to_exif_uid.py
import os
import glob
import exifread
NAME_LENGTH = 10
jpg_files = glob.glob('*.jpg')
for a_file in jpg_files:
try:
@kmonsoor
kmonsoor / smtp_send_mail.py
Created Oct 3, 2017
Send mail using Gmail's SMTP service
View smtp_send_mail.py
# src: https://stackoverflow.com/a/12424439/617185
def send_email(user, password, recipient, subject, body):
import smtplib
FROM = user
TO = recipient if type(recipient) is list else [recipient]
SUBJECT = subject
TEXT = body
@kmonsoor
kmonsoor / Dockerfile
Last active Oct 8, 2017
mysql configuration to avoid Docker error like " Aborted connection 6 to db: 'db' user: 'root' host: '172.18.0.5' (Got an error reading communication packets)"
View Dockerfile
#### after the above custom my.cnf, add this at the Dockerfile
FROM mysql:latest
COPY ./custom-mysql.cnf /etc/mysql/conf.d/
@kmonsoor
kmonsoor / gdrive_copy_file_to_folder.py
Last active Sep 24, 2017
Google Drive API : Copy or move a single file to new folder. If you find this useful, as a 👍, give this gist a ⭐️
View gdrive_copy_file_to_folder.py
def copy_file_to_folder(file_id, new_folder_id, move=False):
# acquiring credentials
# for credential function, please refer to: https://gist.github.com/kmonsoor/d89c930a8df3060106c04648dc6058b0
try:
drive_service = discovery.build('drive', 'v3', credentials = get_credential_service_account())
except Exception as e:
print("File copy/move failed due to failed acquire credentials")
raise
if move: