Skip to content

Instantly share code, notes, and snippets.

View nogsantos's full-sized avatar
🥋
Hard work and discipline

Fabricio Nogueira nogsantos

🥋
Hard work and discipline
View GitHub Profile
@nogsantos
nogsantos / decorators.py
Created January 28, 2022 16:20
Decorator to measure the execution time of a method
import logging
from functools import wraps
import time
def measure_it(func):
"""
Decorator to measure the execution time of a method.
Measure and log the execution time to the console in ms.
@nogsantos
nogsantos / python_decorators.py
Created October 26, 2021 17:41
Example how to create a python decorator
import time
import random
from functools import wraps
def stopwatch(func_in=None, *, show_time: bool = True, show_name: bool = True):
def do(annotated_function):
@wraps(annotated_function)
def func(*args, **kwargs):
tic = time.time()
ssh <targe-ip-address> -l <user> -D <local-host>:<local-port>:<remote-localhost>:<remote-port>
# Ex.:
ssh 10.241.242.220 -l vagrant -L localhost:1234:localhost:9392
@nogsantos
nogsantos / lauch.json
Created April 22, 2020 17:31
Vscode config to enable debug Vue unit tests
{
"version": "0.2.0",
"configurations": [
{
"name": "Debugger unit test",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"./node_modules/@vue/cli-service/bin/vue-cli-service.js",
@nogsantos
nogsantos / decodeb64.sh
Created March 2, 2020 12:26
Base64 script decoder and output the result as json. Require json_pp to output
#!/bin/bash
echo $1 | base64 -d | json_pp
@nogsantos
nogsantos / bash.md
Created November 14, 2019 19:25
Fix summer time on CentOS
yum update tzdata 
timedatectl set-timezone America/Sao_Paulo
@nogsantos
nogsantos / thread.py
Last active November 13, 2019 11:33
Simple python Thread example
import requests
import threading
import logging
base_url = 'https://swapi.co/api/people/?search=skywalker'
def get_urls():
data = requests.get(base_url).json()
logging.info("Results: %s.", data['results'])
@nogsantos
nogsantos / vagrant-cheat-sheet.md
Last active November 11, 2019 18:07 — forked from wpscholar/vagrant-cheat-sheet.md
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
@nogsantos
nogsantos / extensions.md
Last active July 19, 2019 14:10
My vscode extensions and settings configurations
  • naumovs.color-highlight
  • mikestead.dotenv
  • editorconfig.editorconfig
  • dbaeumer.vscode-eslint
  • bierner.github-markdown-preview
  • eamodio.gitlens
  • k--kato.intellij-idea-keybindings
  • alefragnani.numbered-bookmarks
  • esbenp.prettier-vscode
  • chakrounanas.turbo-console-log
@nogsantos
nogsantos / sleep.js
Created April 11, 2019 16:10
Javascript async sleep
(() => {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function work() {
console.log('Start sleeping');
await sleep(5000);
console.log('Five seconds later');