Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Khaled Monsoor kmonsoor

:octocat:
View GitHub Profile
@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 / get_credential_service_account.py
Last active Dec 6, 2018
Python get_credential() for Google service_account() with *.json secret. this gist if acts as useful, as a 👍
View get_credential_service_account.py
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 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 / grafana.ini
Created Aug 2, 2017
Sample SMTP configuration for Grafana with Gapps account
View grafana.ini
#### 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 Feb 18, 2017
me on keybase.io
View keybase.md

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 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 / 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 / UploadWithProgress.cs
Created Aug 3, 2016
C#.NET : WebClient : Upload file to web API while monitoring progress
View UploadWithProgress.cs
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 Oct 11, 2021
install wifi adapter drivers on Raspberry Pi; origin: http://www.fars-robotics.net/install-wifi
View RPi-install-wifi.sh
#!/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 Apr 15, 2016
extracting organization names from medical acronyms
View org-extract.py
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'])