Skip to content

Instantly share code, notes, and snippets.

View simonespa's full-sized avatar

Simone Spaccarotella simonespa

View GitHub Profile
@simonespa
simonespa / typescript-init.sh
Created October 27, 2023 17:12
Init Typescript Project
npm init -y
pnpm install typescript @types/node --save-dev
pnpm tsc --init --rootDir src --outDir build --lib es6 --noImplicitAny true --resolveJsonModule
@simonespa
simonespa / python_update_requirements.md
Created September 29, 2023 15:43
Upgrade Python libraries using requirements.txt
pip install --upgrade --force-reinstall -r requirements.txt

or ignore installed packages and install the new ones:

pip install --ignore-installed -r requirements.txt
@simonespa
simonespa / tokenizer.py
Created September 29, 2023 10:55
Tokenizer
import re
vocabulary = set(re.split('\W', text))
vocabulary.update(set(re.findall('\W', text)))
embeddings = dict.fromkeys(vocabulary, [])
print(f'Vocabulary size: {len(vocabulary)}')
## E2E Testing
- https://playwright.dev
- https://www.cypress.io
## Performance Testing
- https://gatling.io
- https://www.artillery.io
- https://k6.io
## Profiling
@simonespa
simonespa / versions.sh
Created August 4, 2023 11:06
Download S3 versions
aws s3api list-object-versions --bucket ${BUCKET} --prefix ${FILE} --max-items ${MAX_ITEM} --no-cli-pager > versions
cat versions | jq -r '.Versions[].VersionId' > versionids
cat versions | jq -r '.Versions[] | "\(.LastModified) \(.VersionId)"' > lastmodified_versionids
aws s3api get-object --bucket ${BUCKET} --key ${FILE} --version-id ${VERSION_ID}
let "index = 1"
while read version
@simonespa
simonespa / numerical_categorical_split.py
Created June 24, 2023 17:54
Split categorical from numerical features with Pandas
# split numerical variables from categorical
numerical = train.select_dtypes('number')
categorical = train.select_dtypes(exclude='number')
# split high cardinality categorical variables from the low cardinality ones
hc_categorical = categorical[[col for col in categorical.columns if categorical[col].nunique() > 20]]
lc_categorical = categorical[[col for col in categorical.columns if categorical[col].nunique() <= 20]]
@simonespa
simonespa / estimator.py
Last active May 28, 2023 20:54
Example of Scikit-Learn pipeline and estimator
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self, dtype=None, drop_columns=None):
self.dtype = dtype
self.columns = drop_columns
def fit(self, X, y=None):
return self
def transform(self, X):
@simonespa
simonespa / hotfix.md
Created April 26, 2023 10:26
When to resort to a live HotFix
  1. An incident is occurring and no mitigation had any effect on the issue
  2. The incident is preventing the audience to use the system (the definition of usage should be assessed based on what functionality is considered most important)
  3. A defect in the code that causes the issue is found
  4. An assessment of the risk of releasing a HOTFIX live has been made and it is favourable.
  5. The severity of the issue is greater than the risk of releasing live
  6. The HOTFIX has been considered as the last resort

Make sure you are on the main branch of your code repository and it is up to date

@simonespa
simonespa / ec2-alb-stack.ts
Created January 15, 2023 15:09
CDK Lambda and EC2 with ALB
import autoscaling = require('@aws-cdk/aws-autoscaling');
import ec2 = require('@aws-cdk/aws-ec2');
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import cdk = require('@aws-cdk/core');
export default class LoadBalancerStack extends cdk.Stack {
constructor(app: cdk.App, id: string) {
super(app, id);
const vpc = new ec2.Vpc(this, 'VPC');
@simonespa
simonespa / .babelrc
Created January 14, 2023 16:44
Lighthouse score with BBC Signin
{
"presets": ["@babel/preset-env"]
}