This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>" |