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:19 (UTC -03:00)
View GitHub Profile
@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 / interesting.md
Last active November 7, 2023 14:50
Interesting python stuff

Interesting python stuff i found messing around with it

1 hash function is random for non non-primitive objects, and it's seed is reset each time the interpreter is ran

Example: python -c "print(hash('hello world'))" generates random numbers, while python -c "print(hash(4.2))" always returns a constant value

2 list.extend method updates itself each time the iterator is called

This code will run forever ( and eat all your RAM ):

@giuliano-macedo
giuliano-macedo / compile_drop_table.py
Last active February 16, 2023 14:39
sqlalchemy createtable with cascade (with type hints), original answer: https://stackoverflow.com/a/38679457/5133524
from sqlalchemy.schema import DropTable
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects.postgresql.base import PGDDLCompiler
from typing import Any
@compiles(DropTable, "postgresql")
def _compile_drop_table(element: DropTable, compiler: PGDDLCompiler, **kwargs: Any) -> str:
return compiler.visit_drop_table(element) + " CASCADE"
T = TypeVar("T")
class MyProtocol(Protocol[T]):
def my_method(self, first_param: int, args: T) -> int:
...
@dataclass
class Imp1Args:
x: float
y: float
class Imp1(MyProtocol[Imp1Args]):
@giuliano-macedo
giuliano-macedo / with_sized_box_between.dart
Created December 18, 2022 15:18
A dart extension on a list of flutter widgets so that it can add padding between each one.
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
extension WidgetListSpacing on List<Widget> {
List<Widget> withSizedBoxBetween({double? width, double? height}) {
final box = SizedBox(width: width, height: height);
return mapIndexed((index, widget) => index == 0 || index == length ? [widget] : [box, widget]).flattened.toList();
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Clubbi code challenge',
debugShowCheckedModeBanner: false,
@giuliano-macedo
giuliano-macedo / 40-microsoft-mouse.conf
Created November 14, 2022 12:14
Microsoft Classic IntelliMouse Xorg config for I3
# put file in /etc/X11/xorg.conf.d/40-microsoft-mouse.conf
# use xinput list-props "Microsoft Microsoft® Classic IntelliMouse®" to get all options
# use xinput set-prop "Microsoft Microsoft® Classic IntelliMouse®" "OPTION" "OPTIONVALUE" to test an option
Section "InputClass"
Identifier "Microsoft Mouse"
MatchProduct "Microsoft Microsoft® Classic IntelliMouse®"
Driver "libinput"
Option "Accel Profile Enabled" "0 1"
Option "Accel Speed" "0.25"
@giuliano-macedo
giuliano-macedo / wpp_video_splitter.py
Last active September 24, 2022 04:08
Split video using ffmpeg to fit WhatsApp status
from subprocess import getstatusoutput as shell
from subprocess import Popen,PIPE,STDOUT
import shlex
import re
import argparse
import os
from tqdm import tqdm
from math import ceil,log10
def get_video_length(fname):
@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 / simpleroutertopo.py
Last active July 21, 2022 02:55
simple mininet custom topology with static routing
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Node
from mininet.log import setLogLevel, info
from mininet.cli import CLI
class LinuxRouter( Node ):
"""A Node with IP forwarding enabled.
Means that every packet that is in this node, comunicate freely with its interfaces."""