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 / 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 / get_credential_service_account.py
Last active December 6, 2018 12:58
Python get_credential() for Google service_account() with *.json secret. ⭐ this gist if acts as useful, as a 👍
def get_credential_service_account():
from oauth2client.service_account import ServiceAccountCredentials
SERVICE_ACC_CREDENTIAL = 'your-service-account-secrets-file.json'
scopes = ['https://www.googleapis.com/auth/drive']
pprint("Request for credential received");
try:
credentials = ServiceAccountCredentials.from_json_keyfile_name(SERVICE_ACC_CREDENTIAL, scopes=scopes)
pprint(credentials)
return credentials
@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 / grafana.ini
Created August 2, 2017 15:23
Sample SMTP configuration for Grafana with Gapps account
#### other settings ...
[smtp]
enabled = true
host = smtp.gmail.com:465
user = grafana-bot@organization.com
password = """PASSWORD"""
from_address = grafana-bot@organization.com
from_name = Grafana Bot
;cert_file =
@kmonsoor
kmonsoor / keybase.md
Created February 18, 2017 13:15
me on keybase.io

Keybase proof

I hereby claim:

  • I am kmonsoor on github.
  • I am kmonsoor (https://keybase.io/kmonsoor) on keybase.
  • I have a public key whose fingerprint is AE6A FBAA F2F3 D881 EF46 1378 77FF A3EC 79A6 F16D

To claim this, I am signing this object:

@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 / 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 / UploadWithProgress.cs
Created August 3, 2016 14:23
C#.NET : WebClient : Upload file to web API while monitoring progress
using System;
using System.IO;
using System.Net;
using System.Web;
public class UploadWithProgress
{
public static double PercentUploaded;
public static string FilePath;
public static string Result;
@kmonsoor
kmonsoor / RPi-install-wifi.sh
Last active February 19, 2024 05:46
install wifi adapter drivers on Raspberry Pi; origin: http://www.fars-robotics.net/install-wifi
#!/bin/bash
#set -e
# origin-source: http://www.fars-robotics.net/install-wifi
# install-wifi - v9.4 - by MrEngman.
# After downloading this script:
# $ sudo mv ./install-wifi /usr/bin/install-wifi
# $ sudo chmod +x /usr/bin/install-wifi
# $ sudo install-wifi -h
#
@kmonsoor
kmonsoor / org-extract.py
Created April 15, 2016 01:28
extracting organization names from medical acronyms
reader = csv.DictReader(open('c:\Book1.csv'))
of = open('out.tsv')
writer = csv.writer(of)
orgs = ['center of', 'center for', 'commitee for',
'commitee of', 'organization', 'ministry of', 'ministry for',
'department', ]
for row in reader:
if any(x in row['Definition'].lower() for x in orgs):
# print {row['Acronym']: {'full-form': row['Definition'], 'comment': row['Comments']}}
writer.writerow(row['Acronym'], '\t', row['Definition'])