Skip to content

Instantly share code, notes, and snippets.

View giuliano-macedo's full-sized avatar
🏠
Working from home

Giuliano Macedo giuliano-macedo

🏠
Working from home
  • Brazil
  • 07:11 (UTC -03:00)
View GitHub Profile
@giuliano-macedo
giuliano-macedo / print_json.go
Last active September 20, 2021 01:21
print_json.go
package main
import (
"encoding/json"
"fmt"
)
func printJson(data interface{}) {
bs, err := json.MarshalIndent(data, "", " ")
if err != nil {
@giuliano-macedo
giuliano-macedo / download_file.rs
Last active January 25, 2024 08:52
Download large files in rust with progress bar using reqwest, future_util and indicatif
// you need this in your cargo.toml
// reqwest = { version = "0.11.3", features = ["stream"] }
// futures-util = "0.3.14"
// indicatif = "0.15.0"
use std::cmp::min;
use std::fs::File;
use std::io::Write;
use reqwest::Client;
use indicatif::{ProgressBar, ProgressStyle};
@giuliano-macedo
giuliano-macedo / custom_commands.sh
Created November 2, 2020 17:40
some common custom shell commands i use, you can add to your home directory and add "source custom_commands.sh" on your .bashrc file to add them.
function notify_when_online(){
host=$1
while true; do
ping -c1 $host > /dev/null && break;
done && notify-send --icon=dialog-information "$host is online"
}
from .download import download
from bs4 import BeautifulSoup
import json
import re
import requests
import sys
if sys.version_info.major < 3:
from pathlib2 import Path
else:
@giuliano-macedo
giuliano-macedo / gdown_folder_regex.py
Last active September 7, 2022 14:43
Shallow download files from Google Drive folder with requests,bs4 and regex
import re
from bs4 import BeautifulSoup
import requests
import gdown
import json
import argparse
parser=argparse.ArgumentParser()
parser.add_argument("url")
@giuliano-macedo
giuliano-macedo / gdown_folder.py
Created October 25, 2020 21:34
Shallow download files from Google drive folder using gdown and selenium
from bs4 import BeautifulSoup
from selenium import webdriver
import gdown
import argparse
parser=argparse.ArgumentParser()
parser.add_argument("url")
args=parser.parse_args()
@giuliano-macedo
giuliano-macedo / psyche.py
Created October 7, 2020 22:25
using contextlib+signals to make a with timeout with statement
import signal
from contextlib import contextmanager
class TimeOutError(RuntimeError):pass
@contextmanager
def timeout(duration):
def timeout_handler(signum, frame):
raise TimeOutError()
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(duration)
try:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from io import StringIO
from random import gauss,randrange
max_chars=63206 #https://sproutsocial.com/insights/social-media-character-counter/
wrong="9"
right="6"
f=StringIO()
from sklearn.datasets import make_blobs
# import pandas as pd
import numpy as np
centers=[
[.1,.1],
[.2,.1],
[.3,.1],
[.4,.1],
[.5,.1],