Skip to content

Instantly share code, notes, and snippets.

View ndamulelonemakh's full-sized avatar
🍸
Solution explorer

Ndamulelo Nemakhavhani ndamulelonemakh

🍸
Solution explorer
View GitHub Profile
@ndamulelonemakh
ndamulelonemakh / firebase-security-rules -authenticated-only.js
Last active January 17, 2020 08:40
Firebase Security Rules Cheat Sheet
service cloud.firestore{
match /databases/{database}/documents{
match /{document=**}{
allow read, write: if request.auth.uid != null;
}
}
}
@ndamulelonemakh
ndamulelonemakh / proclist.py
Created April 18, 2020 16:39
Creating python console executables with pyinstaller and argparse
"""
A simple python script that uses the psutil package to show processes running on a host machine.
"""
__version__ = '1.0.0'
__author__ = 'Ndamulelo N [email protected]'
import psutil
import argparse
#!bin/bash
# REFERENCE: https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15
# 1. First add the Microsoft SQL Server repository
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
# 2. Then Install sql server using apt-install
sudo apt-get update
@ndamulelonemakh
ndamulelonemakh / send_mail_with_smtplib.py
Last active November 25, 2023 05:00
Automatically Send an email using Python's smtplib
import smtplib
import ssl
from smtplib import SMTPAuthenticationError
# Simple Python snippet to automatically send emails using gmail
# Docs: https://docs.python.org/3.10/library/smtplib.html
DEFAULT_SSL_PORT = 465
GMAIL_SERVER_ADDRESS = "smtp.gmail.com"
DEFAULT_SENDER_EMAIL_ADDRESS = "<sender-address>"
@ndamulelonemakh
ndamulelonemakh / python-flask_spotify_api.py
Last active October 14, 2020 07:11
Test the Spotify Web API in a flask application
import os
import uuid
import webbrowser
import urllib.parse as urllib
# You need to install these modules using pip
import flask
import requests
__author__ = '@NdamuleloNemakh'
@ndamulelonemakh
ndamulelonemakh / LazySimpleSingleton.cs
Last active November 3, 2020 16:37
C# Design Pattern Examples
public class SimpleSingleton{
private int count = 1;
// Use lazy<T> to delay initialisation until the field is accessed
private static readonly Lazy<SimpleSingleton> _instance = new Lazy<SimpleSingleton>( ()=> new SimpleSingleton());
private SimpleSingleton(){
Console.WriteLine($"{nameof(SimpleSingleton)} constructor called at {DateTime.Now}");
}
@ndamulelonemakh
ndamulelonemakh / conjugate_gradientdescent.py
Last active May 13, 2021 08:28
Steepest Descent example implementation(s) in Python
"""Example implementation of the conjugate gradient descent algorithm using a hard coded objective function
F(X1, X2) = 5X1**2 + X2**2 + 4X1X2 - 14X1 - 6X2 + 20
- At each step the value of X will be updated using
X_k+1 = X_k + alpha * Pk
Where pk is the conjugate direction and alpha is the step length
"""
import math
@ndamulelonemakh
ndamulelonemakh / prepare_google_service_account.py
Last active October 5, 2021 11:36
Using Google Service Account in Azure App Service
'''
Simple method to dynamically create the google service account file in Azure App service
Steps
----------------------
i. Add the service account file contents to Azure App Service configuration
ii. The json contents will be available to your app at runtime as an environment variable, e.g. GOOGLE_CREDENTIALS
iii. When you app starts, save the contents of the environment variable to a file that you specified as your GOOGLE_APPLICATION_CREDENTIALS
'''
import os
@ndamulelonemakh
ndamulelonemakh / data_split.R
Created June 29, 2021 16:36 — forked from duttashi/data_split.R
splitting a given dataset into train and test
# Method 1: Easiest and does not require any library
data(mtcars)
## 75% of the sample size
smp_size <- floor(0.75 * nrow(mtcars))
## set the seed to make your partition reproducible
set.seed(123)
train_ind <- sample(seq_len(nrow(mtcars)), size = smp_size)
@ndamulelonemakh
ndamulelonemakh / get-R.sh
Last active February 7, 2024 08:56
Convenience bash scripts to install various Linux CLI tools
#!/bin/bash
# Summary: Install R in Ubuntu and make it available in jupyter lab
# Install R on ubuntu (Tested on Ubuntu 18.04)
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/'
sudo apt update -y
sudo apt-get install r-base r-base-core r-recommended
# Extra requirements for compiling packages locally