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 / 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 / automate_git.sh
Last active December 1, 2021 13:04
Create repository using a script [requires SSH access]
TOKEN=<github_token>
USERNAME=<github_user>
FILENAME=automate_git.sh
echo "What name do you want to give your remote repo? "
read REPO_NAME
echo "Enter a repo description. Do NOT use spaces: "
read DESCRIPTION
@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 / fizz-buzz.py
Last active February 19, 2023 21:29
FizzBuzz with lambda and destructuring
def fizz_buzz(n: int = 15) -> list[str]:
fizz = lambda x: x % 3 == 0
buzz = lambda x: x % 5 == 0
result = []
for i in range(1, n + 1):
if fizz(i) and buzz(i):
result.append("fizz_buzz")
continue
if buzz(i):
result.append("buzz")
@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 / getAndPostRequest.js
Last active January 17, 2022 08:16
Post request with pure JS - no jQuery/ajax
async function getData(){
let url = 'https://jsonplaceholder.typicode.com/posts/1';
let page = await fetch(url);
let json = await page.json();
console.log(json);
}
async function postData(){
let url = 'https://jsonplaceholder.typicode.com/posts';
@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-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 / create-ssh-key.sh
Last active November 13, 2021 17:08
Create SSH key - bash
eval "$(ssh-agent -s)"
number=100
path=$HOME/.ssh/
read -p 'Keyname: ' keyname
comment=$keyname
ssh-keygen -a $number -t ed25519 -f $path$keyname -C $comment
ssh-add $path$keyname