Skip to content

Instantly share code, notes, and snippets.

View kmonsoor's full-sized avatar
:octocat:

Khaled Monsoor kmonsoor

:octocat:
View GitHub Profile
@kmonsoor
kmonsoor / url-forwarder-worker-cloudflare.js
Created May 25, 2021 03:38
Core worker code for url-forwarder based on Cloudflare Worker-KV
// This is the companion code for the linked blog
// https://blog.kmonsoor.com/on-edge-shortlink-server-cloudflare-kv-worker
// Please check the blog to get the context
// author : Khaled Monsoor (@kmonsoor)
// last updated: 25-May-2021
const failsafeURL = "https://kmonsoor.com" // replace it with yours ;)
const defaultStatusCode = 301 // standard HTTP code for redirection, don't change
addEventListener("fetch", (event) => {
@kmonsoor
kmonsoor / create-version.py
Created May 24, 2019 19:01
Jira-Python : Create versions for project
# 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 July 3, 2018 14:12
jquery $.getScript() replacement with vanilla JavaScript
"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 17:02
JavaScript -- Disable console.log & other in-browser console.* methods
"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 March 23, 2018 09:31
Beautify your Bash code
#!/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 February 12, 2018 11:41
Node.js HTTP Status codes
// $ 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 February 2, 2018 11:59
MySQL get current date in PST timezone
-- 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 December 26, 2017 01:17
Rename JPG files to `Unique image id` of EXIF data. If you find this useful, as a 👍, give this gist a ⭐️
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 October 3, 2017 13:36
Send mail using Gmail's SMTP service
# 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 October 8, 2017 01:18
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)"
#### after the above custom my.cnf, add this at the Dockerfile
FROM mysql:latest
COPY ./custom-mysql.cnf /etc/mysql/conf.d/