Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Giuliano Oliveira giuliano-oliveira

🏠
Working from home
  • Brazil
View GitHub Profile
View print_json.go
package main
import (
"encoding/json"
"fmt"
)
func printJson(data interface{}) {
bs, err := json.MarshalIndent(data, "", " ")
if err != nil {
@giuliano-oliveira
giuliano-oliveira / download_file.rs
Last active Oct 25, 2021
Download large files in rust with progress bar using reqwest, future_util and indicatif
View download_file.rs
// 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-oliveira
giuliano-oliveira / custom_commands.sh
Created Nov 2, 2020
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.
View custom_commands.sh
function notify_when_online(){
host=$1
while true; do
ping -c1 $host > /dev/null && break;
done && notify-send --icon=dialog-information "$host is online"
}
View download_folder.py
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-oliveira
giuliano-oliveira / gdown_folder_regex.py
Last active Oct 25, 2020
Shallow download files from Google Drive folder with requests,bs4 and regex
View gdown_folder_regex.py
import re
from bs4 import BeautifulSoup
import requests
import gdown
import json
import argparse
parser=argparse.ArgumentParser()
parser.add_argument("url")
@giuliano-oliveira
giuliano-oliveira / gdown_folder.py
Created Oct 25, 2020
Shallow download files from Google drive folder using gdown and selenium
View gdown_folder.py
from bs4 import BeautifulSoup
from selenium import webdriver
import gdown
import argparse
parser=argparse.ArgumentParser()
parser.add_argument("url")
args=parser.parse_args()
@giuliano-oliveira
giuliano-oliveira / psyche.py
Created Oct 7, 2020
using contextlib+signals to make a with timeout with statement
View psyche.py
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:
View notebook.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View tenha_uma_boa_semana.py
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()
View make_blobs_test.py
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],