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 / create-az-app-getway.sh
Last active January 13, 2022 19:52
Implementing web app resilience in Azure
#! /bin/bash
# Pre-requisits
# Active Azure Subscription
# A virtual network resource
# 2 or more vms serving the same web app
# Reference: https://docs.microsoft.com/en-us/learn/modules/load-balance-web-traffic-with-application-gateway/5-exercise-create-configure-application-gateway
# i.Step 1: Create a gateway subnet
@ndamulelonemakh
ndamulelonemakh / azure-react-staticwebstites-deploy.sh
Last active May 27, 2022 10:01
Azure deployment scripts for dev and small-scale production workloads
#! bin/bash
# Helper script to deploy the production optimised build of a react app to Azure
# The environment variables below can be changed as required
ResourceGroupName="my-example-rg"
Location="westus"
StorageAccountName="myspecialstorageaccount"
StorageSKU="Standard_LRS"
StorageKind="StorageV2" # Allowed values: BlobStorage, BlockBlobStorage, FileStorage, Storage, StorageV2
StorageContainerName="mysitecontainer01"
@ndamulelonemakh
ndamulelonemakh / twitter-scraping-twint-examples.sh
Last active October 8, 2021 10:30
Misc web scraping scripts
# i. Search for tweets containing hastag '#messi' posted in 2020
# Results will be saved to a csv file named 'messitweets.csv'
# Other filters: Only get tweets in english(en), stats: show the number of likes, retweets for each post, count: show the number of posts returned
twint --search "#messi" --since 2020-01-01 --until 2020-12-31 --limit 50000 --popular --csv -o "messitweets.csv" --lang en --stats --hashtags --stats --count
# ii. Collect all tweets from a users timeline
twint --since 2020-01-01 --until 2020-12-31 --limit 50000 --popular --csv -o "out.csv" --lang en --stats --hashtags --stats --count -u endeesa -tl
@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
@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 / 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 / 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 / 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 / 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 / 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>"