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
  • 12:35 (UTC -03:00)
View GitHub Profile
@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"
@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 ):

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 / tab_controller_with_on_change.dart
Last active December 29, 2021 11:22
Flutter TabController with onChange callback
import 'package:flutter/material.dart';
class TabControllerWithOnChange extends TabController {
TabControllerWithOnChange({
int initialIndex = 0,
required int length,
required TickerProvider vsync,
required void Function(int) onChange,
}) : super(initialIndex: initialIndex, length: length, vsync: vsync) {
addListener(() {
@giuliano-macedo
giuliano-macedo / scanner.dart
Created December 17, 2021 20:52
QrCode/Barcode scanner using qr_code_scanner in flutter
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
class ScannerWidget extends StatefulWidget {
final BarcodeFormat format;
final void Function(String?) onScan;
ScannerWidget({
@giuliano-macedo
giuliano-macedo / cubic_bezier.rs
Last active November 15, 2021 22:38
Cubic 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 / 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 {