Skip to content

Instantly share code, notes, and snippets.

View PsycheShaman's full-sized avatar
:atom:
wizarding

Christiaan Gerhardus Viljoen PsycheShaman

:atom:
wizarding
View GitHub Profile
@PsycheShaman
PsycheShaman / custom-focal-loss-keras.R
Last active August 24, 2023 14:23
Custom Loss Function for R: Focal Loss (to Account for Imbalanced Classes During Classification), adapted from https://github.com/umbertogriffo/focal-loss-keras, since I could not find an equivalent loss function for R
require(keras)
require(tensorflow)
K <- keras::backend()
# Custom Focal Loss
focalLoss <- function(gamma=2., alpha=.25){
@PsycheShaman
PsycheShaman / unzip_s3_source_data.py
Created September 13, 2021 06:59
Python function to unzip an archive stored in S3 to a specified destination folder in S3.
import boto3
import io
import zipfile
def unzip_s3_source_data(
s3_source_bucket: str,
s3_source_folder: str,
s3_destination_folder: str
) -> None:
"""
import pandas as pd
def set_pd_display():
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)
select city_name, current_date, get_weather_udf(city_name)
from cities;
CREATE OR REPLACE EXTERNAL FUNCTION get_weather_udf (city varchar)
RETURNS varchar STABLE
LAMBDA 'my-function'
IAM_ROLE '<Role ARN>';
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Invoke",
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": "arn:aws:lambda:us-west-2:123456789012:function:my-function"
import http.client
from geopy.geocoders import Nominatim
import json
def geo_code(city):
geo_locator = Nominatim(user_agent="medium_article_example")
location = geo_locator.geocode(city)
print(location.latitude, location.longitude)
return (location.latitude, location.longitude)
create table cities (city_name varchar);
insert into dev.public.cities
(city_name)
values ('Cape Town'),('Pretoria'),('Johannesburg'),('Bloemfontein');
# Make sure to modify this code to point to your actual domain. Also double-check the names of the certificates before running this.
# Lastly, be careful with su, but you already know that ;)
sudo su
cp -r /etc/letsencrypt/archive/yourdomain.com /etc/presto
cd /etc/presto
touch prestocert.pem
cat fullchain.pem >> prestocert.pem
cat privkey.pem >> prestocert.pem
chmod 644 prestocert.pem
exit
sudo apt-get install apache2-utils
htpasswd -B -C 10 password.db newusername
# To verify that the password was created correctly, you can run:
htpasswd -v password.db newusername