Skip to content

Instantly share code, notes, and snippets.

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

Lourenço Costa costa86

🏠
Working from home
View GitHub Profile
@costa86
costa86 / palidrome.py
Created May 31, 2019 11:35
Check whether a string is a palindrome
is_palindrome = lambda word:word.upper() == word[::-1].upper()
print(is_palindrome('Deleveled'))
@costa86
costa86 / postRequest.js
Created April 28, 2021 12:32
Send post request using vanilla JavaScript, no jQuery, no Ajax
async function sendPostRequestToURL(bodyData, url) {
let submission = await fetch(url, {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(bodyData)
});
return submission.status;
}
@costa86
costa86 / dockerAliases.ps1
Last active April 28, 2021 12:33
Set-ProfileForDocker.ps1
#code $PROFILE (or another editor)
#add these changes
function Up-DockerCompose() {
docker-compose up
}
function Up-DockerComposeD() {
docker-compose up -d
}
@costa86
costa86 / hanoi_tower.py
Last active April 28, 2021 12:34
Solves Hanoi Tower puzzle
#print moves
def move(disc,origin,destination):
print('Disc',disc,'from tower',origin,'to tower',destination)
count = 1
def hanoi(n,fr,to,temp):
'''print moves on hanoi tower puzzle
Args:
n(int):number of discs
fr(string):origin tower
@costa86
costa86 / audio-response.py
Last active June 17, 2021 11:51
Plays audio given sys arguments
from gtts import gTTS
import os
from playsound import playsound
import sys
text = "Flow has been completed"
lang = "en"
tld = "ca"
audio_filename = r"C:\Users\lcosta\PowerAutomate\sample.mp3"
@costa86
costa86 / create-user.sh
Last active July 29, 2021 15:07
Create a user
read -p 'User: ' user
group=$user
adduser $user
usermod -aG sudo $user
cd /home/$user
rsync --archive --chown=$user:$group ~/.ssh /home/$user
su $user
@costa86
costa86 / create-ssh-key.ps1
Last active July 29, 2021 15:09
Create SSH keys PowerShell
$number = 100
$path = "<where the key will be stored>"
$keyname = Read-Host "Please enter your keyname"
$comment = $keyname
ssh-keygen -a $number -t ed25519 -f $path$keyname -C $comment
ssh-add $path$keyname
@costa86
costa86 / config
Last active July 30, 2021 17:42
SSH config file
Host *
IdentitiesOnly=yes
Port 22
Host <custom_name>
Hostname <ip>
User <user>
IdentityFile <private_key>
Host <another_custom_name>
@costa86
costa86 / main.tf
Created August 5, 2021 14:44
Terraform example for Digital Ocean
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.10.1"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
@costa86
costa86 / ssh-sftp-python.py
Last active September 27, 2021 08:49
Python script to display and connect to available SSH/SFTP servers
"""
Requirements:
tabulate==0.8.9
"""
import os
from tabulate import tabulate
headers = ["ALIAS",'USER',"IP","PRIVATE KEY FILE","LOCAL FORWARD","ID"]
PRIMARY_SSH_KEY = r"C:\Users\costa\.ssh\sample"