Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Khaled Monsoor kmonsoor

:octocat:
View GitHub Profile
@kmonsoor
kmonsoor / guid.js
Last active Jun 15, 2017
JavaScript : Create GUID / UUID
View guid.js
/*
* Generate RFC4122-v4 compliant high-resolution GUID / UUID
* Source: http://stackoverflow.com/a/8809472/617185
* License: cc-by-sa 3.0
*/
function generateUUID() {
var d = new Date().getTime();
if (window.performance && typeof window.performance.now === "function") {
d += performance.now(); //use high-precision timer if available
}
@kmonsoor
kmonsoor / mariadb.repo
Created Sep 17, 2017
MariaDB YUM repository entry for `CentOS 7`. Should be in directory `/etc/yum.repos.d/`
View mariadb.repo
# MariaDB 10.2 CentOS repository list - created 2017-09-17 13:42 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
@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:
@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 / getBrowser.js
Created Jan 18, 2017
Get Browser's name and it's version number ...
View getBrowser.js
function getBrowser() {
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = '' + parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion, 10);
var nameOffset, verOffset, ix;
// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset = nAgt.indexOf("Opera")) != -1) {
@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 / 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 / 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 / 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. *