Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
pcolazurdo / setup.sh
Last active January 12, 2020 17:04
Setup a default environment
#!/bin/bash
# $1 should be en directory name
#
if [ -z $1 ]
then
echo "You should specify a directory name"
exit 1
else
echo "Inititalizing Directory"
@pcolazurdo
pcolazurdo / lsinstances.sh
Created January 3, 2020 15:13
List key details for ec2 instances
#!/bin/bash
# $1 region
MYREGION=${1:-eu-west-1}
total_instances_output=$(aws ec2 describe-instances --region $MYREGION)
total_instances=$(echo "${total_instances_output}" | jq '.Reservations[].Instances[] | [.InstanceId] | @tsv')
named_instances=$(echo "$total_instances_output" |jq '.Reservations[].Instances[] | try select (.Tags[].Value = "Key") | [.InstanceId, .PublicIpAddress,.PrivateIpAddress,.State.Name,(.Tags | from_entries | .Name)] | @tsv')
@pcolazurdo
pcolazurdo / find_shell.md
Created January 3, 2020 15:03
Find current Shell in script

Portable solution (tested in linux and macOS):

ps -o args= -p $$ | egrep -m 1 -o '\w{0,5}sh'

where:

"ps -o args=" retrieves the command line arguments
"$$" gives you the current PID
@pcolazurdo
pcolazurdo / qrcode.sh
Created January 2, 2020 15:08
Generating QR Code for WiFi Access Points
# In Mac you can use:
# /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I
# to find the SSID you are actually connected to
# install qrencode
brew install qrencode
# For WPA2 this will create a wifi.png image that can be used both in Android and iOS devices to auto configure wifi access
SSID="your ssid"; SSID_PASS="your password"; qrencode -o wifi.png "WIFI:S:${SSID};T:WPA2;P:${SSID_PASS};;"
@pcolazurdo
pcolazurdo / list-services.sh
Created January 2, 2020 11:39
List AWS Services
aws ssm get-parameters-by-path \
--path /aws/service/global-infrastructure/services/ --output json | \
grep Name | \
wc -l
@pcolazurdo
pcolazurdo / queries.md
Last active December 18, 2019 14:24
Some useful AWS Log Insights queries

-- Display Lambda Errors Frequency

fields @timestamp, @message
| PARSE @message "[*] *" as loggingType, loggingMessage
| FILTER loggingType = "ERROR"
| sort @timestamp desc
| limit 20
@pcolazurdo
pcolazurdo / readme.md
Created December 7, 2019 18:20
Redshift: List frequency of key operations from stl_query

The following helps to analyze the frequency of each key operation.

  1. In Redshift run:
select * from stl_query where starttime::date='2019-12-05' and userid<>1 order by starttime,query;

and export it to stl_query.csv

  1. In bash, execute:
@pcolazurdo
pcolazurdo / prepare_ntlk.py
Created December 7, 2019 16:54
Worldcloud Generator
import nltk
nltk.download('stopwords')
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
nltk.download('wordnet')
@pcolazurdo
pcolazurdo / readme.md
Last active May 6, 2022 07:35
How to migrate Apple Mac Notes from one machine to another

If you depend on the Notes App and don't have iCloud sync enabled you may find challenging to migrate notes from one machine to another or just backing it up.

As of today (2019-12) the following approach works (tested on High Sierra to Catalina):

# In the source machine
cd ~/Library/Group\ Containers/group.com.apple.notes
zip NoteStore-backup.zip NoteStore.sqlite*
cd ~/Library/Containers/com.apple.Notes/Data/Library/Notes/
zip NotesV7-backup.zip NotesV7*
@pcolazurdo
pcolazurdo / metric-filter.json
Last active November 13, 2019 14:44
Stress Test with bombardier
{
"metricFilters": [
{
"filterName": "result-2xx",
"filterPattern": "{ $.result.req2xx = * }",
"metricTransformations": [
{
"metricName": "bombardier-2xx",
"metricNamespace": "LogMetrics",
"metricValue": "$.result.req2xx",