Skip to content

Instantly share code, notes, and snippets.

View elvisciotti's full-sized avatar

Elvis Ciotti elvisciotti

View GitHub Profile
@elvisciotti
elvisciotti / handler.js
Last active November 27, 2022 23:14
AWS node function deployed with Terraform - complete example
'use strict';
function shuffle(array) {
let currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
@elvisciotti
elvisciotti / mailer.py
Created March 7, 2021 16:03
Python handler to send a SES mail when a S3 object (with a ruleset mail) is created
# copiata pari pari da https://aws.amazon.com/blogs/messaging-and-targeting/forward-incoming-email-to-an-external-destination/
# https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
import os
import boto3
import email
import re
from botocore.exceptions import ClientError
from email.mime.multipart import MIMEMultipart
@elvisciotti
elvisciotti / crypt.bash
Created June 12, 2020 10:13
Openssl 1.1 simmetric crypt and decrypt command line on Mac OSx
# crypt all txt files into .env and delete source
OPENSSL_BIN="/usr/local/Cellar/openssl@1.1/1.1.1g/bin/openssl"
PASSWORD="password-changeme"
for TXT in ~/path/to/*.txt; do
test -f $TXT && \
$OPENSSL aes-256-cbc -pbkdf2 -a -salt -in "${TXT}" -out "${TXT}.enc" -pass pass:${PASSWORD} && \
rm -f "${TXT}"
done
@elvisciotti
elvisciotti / postman-pre-request-sign-hmac-ripe160.js
Last active June 12, 2020 10:09
Postman pre-request script to sign requests adding api-key and api-sign created using HmacRIPEMD160 based on secret and URI, for two different environments
const API_KEYS = {
'prod': {
'key': '',
'secret': '',
},
'uat': {
'key': '',
'secret': '',
}
};
@elvisciotti
elvisciotti / kindleParser.js
Last active June 7, 2020 11:54
Node script to reorganise kindle's "My Clippings.txt" into a human readable markdown file
#!/usr/local/bin/node
/**
* Node script to convert kindle notes into
* ./kindleParse.js > myClippings.md
*/
const endOfLine = "\r\n";
const kindleNoteDelimiter = "==========" + endOfLine;
const titlePrefix = endOfLine + "# ";
const titleSuffix = endOfLine + endOfLine;
@elvisciotti
elvisciotti / README.md
Created May 8, 2020 22:29 — forked from astamicu/Remove videos from Youtube Watch Later playlist.md
Script to remove all videos from Youtube Watch Later playlist

UPDATE 17.10.2019

Only works on old youtube skin.

//added "&disable_polymer=true" after playlist link

Also, saw this now, there is a "remove watched" button.

  1. Open your watch later playlist on youtube.
  2. Open the development console for your browser ( Ctrl+Shift+J for chrome, Ctrl+Shift+K for firefox )
@elvisciotti
elvisciotti / dockertags.sh
Last active August 14, 2022 06:36
Script to fetch docker tags for an image e.g. "dockertags busybox cli"
#!/bin/bash
if [ $# -lt 1 ]
then
cat << HELP
dockertags -- list all tags for a Docker image on a remote registry.
EXAMPLE:
- list all tags for ubuntu:
@elvisciotti
elvisciotti / launch.sh
Last active August 14, 2022 06:37
Python sample script to import not-normalised CSV data into MySQL tables, resolving FK values in memory
# create mysql_latest container
docker run --name mysql57_abc \
-e MYSQL_ROOT_PASSWORD=pass \
-e MYSQL_DATABASE=abc \
-e MYSQL_USER=abc \
-e MYSQL_PASSWORD=abc \
-p 3306:3306 \
-d mysql:5.7
# launch if already created
docker start mysql57_abc
@elvisciotti
elvisciotti / 01 - student.ts - source
Last active March 6, 2019 12:57
typscript class and interface compile example
class Student {
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
@elvisciotti
elvisciotti / adBlockerDetect.html
Created November 7, 2018 16:47
ad blocker detect.html
#https://stackoverflow.com/questions/4869154/how-to-detect-adblock-on-my-website
# ads.js
var canRunAds = true;
# site template after <body>
<script>
if( window.canRunAds === undefined ){
// adblocker detected, show fallback