Skip to content

Instantly share code, notes, and snippets.

View rdemorais's full-sized avatar
🏠
Working from home

Rafael de Morais rdemorais

🏠
Working from home
View GitHub Profile
@palewire
palewire / README.md
Last active April 15, 2024 20:38
How to push tagged Docker releases to Google Artifact Registry with a GitHub Action

How to push tagged Docker releases to Google Artifact Registry with a GitHub Action

Here's how I configured a GitHub Action so that a new version issued by GitHub's release interface will build a Dockerfile, tag it with the version number and upload it to Google Artifact Registry.

Before you attempt the steps below, you need the following:

  • A GitHub repository that contains a working Dockerfile
  • The Google Cloud SDK tool gcloud installed and authenticated

Create a Workload Identity Federation

@MattLowrieDS
MattLowrieDS / compute_class_weight
Created January 6, 2021 03:07
Example using sklearn compute_class_weight()
from sklearn.utils.class_weight import compute_class_weight
pass_results = plays_df.loc[plays_df['passResult'].isin(category_lookup.keys()), 'passResult']
all_labels = pass_results.apply(lambda lbl: category_lookup[lbl])
# Create class weights to counter-balance classification during training
y = np.stack(all_labels).argmax(axis=1)
classes = np.unique(y)
weights = compute_class_weight('balanced', classes=classes, y=y)
class_weights = {k: v for k, v in zip(classes, weights)}
print('Class weights:', class_weights)
@elviswolcott
elviswolcott / delete-layer.sh
Created January 26, 2020 08:05
Delete all Lambda layer versions across all regions
layer=$1
get_regions () {
echo $(aws ssm get-parameters-by-path --region "us-east-1" --path /aws/service/global-infrastructure/services/lambda/regions --query 'Parameters[].Value' --output text | tr '[:blank:]' '\n' | grep -v -e ^cn- -e ^us-gov- | sort -r)
}
regions=$(get_regions)
get_versions () {
echo $(aws lambda list-layer-versions --layer-name "$layer" --region "$region" --output text --query LayerVersions[].Version | tr '[:blank:]' '\n')
}
@egeulgen
egeulgen / boto3_progress_bar.py
Last active August 24, 2023 03:08
To display progress bar and percentage when downloading with boto3
class ProgressPercentage(object):
''' Progress Class
Class for calculating and displaying download progress
'''
def __init__(self, client, bucket, filename):
''' Initialize
initialize with: file name, file size and lock.
Set seen_so_far to 0. Set progress bar length
'''
self._filename = filename
@justinfx
justinfx / py3_asyncore_server.py
Created October 24, 2017 11:15
python3 asyncore + threading socket server
import asyncore
import socket
import threading
class ChatServer(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
@xtornasol512
xtornasol512 / README.md
Created July 15, 2017 04:30 — forked from celisflen-bers/README.md
Python script to convert DBF database file to CSV
@thomasdarimont
thomasdarimont / KeycloakAdminClientExample.java
Last active April 30, 2024 22:18
Using Keycloak Admin Client to create user with roles (Realm and Client level)
package demo.plain;
import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.CreatedResponseUtil;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.admin.client.resource.UsersResource;
import org.keycloak.representations.idm.ClientRepresentation;
@cagataycali
cagataycali / babelInterpreter.sh
Created July 8, 2016 16:28
Start pm2 process with babel-node interpreter
pm2 start app.js --interpreter ./node_modules/.bin/babel-node
@joinAero
joinAero / BluetoothCallback.java
Last active October 7, 2021 15:42
Android - The bluetooth listener and profile proxy.
package cc.cubone.turbo.core.bluetooth;
/**
* Interface definition for a callback to be invoked when bluetooth state changed.
*/
public interface BluetoothCallback {
/**
* Called when the bluetooth is off.
*/
@jlln
jlln / separator.py
Last active November 9, 2023 19:59
Efficiently split Pandas Dataframe cells containing lists into multiple rows, duplicating the other column's values.
def splitDataFrameList(df,target_column,separator):
''' df = dataframe to split,
target_column = the column containing the values to split
separator = the symbol used to perform the split
returns: a dataframe with each entry for the target column separated, with each element moved into a new row.
The values in the other columns are duplicated across the newly divided rows.
'''
def splitListToRows(row,row_accumulator,target_column,separator):
split_row = row[target_column].split(separator)