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 / guid.js
Last active June 15, 2017 07:10
JavaScript : Create GUID / UUID
/*
* 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 September 17, 2017 13:45
MariaDB YUM repository entry for `CentOS 7`. Should be in directory `/etc/yum.repos.d/`
# 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 September 24, 2017 13:29
Google Drive API : Copy or move a single file to new folder. If you find this useful, as a 👍, give this gist a ⭐️
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 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/
@kmonsoor
kmonsoor / getBrowser.js
Created January 18, 2017 10:25
Get Browser's name and it's version number ...
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 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 / 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 / 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 / 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] = () => {};