Skip to content

Instantly share code, notes, and snippets.

View giuliano-macedo's full-sized avatar

Giuliano Macedo giuliano-macedo

  • Brazil
View GitHub Profile
@giuliano-macedo
giuliano-macedo / quadratic_bezier.rs
Last active November 18, 2021 16:49
Quadratic bézier function in rust (not the most performant, focused in readability)
use std::fmt;
#[derive(Debug, Clone, Copy)]
struct Point {
x: f64,
y: f64,
}
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@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 July 13, 2025 13:56
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:
Loading
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()