Skip to content

Instantly share code, notes, and snippets.

View andreciornavei's full-sized avatar
🔥
Working on fire.

André Ciornavei andreciornavei

🔥
Working on fire.
View GitHub Profile
@andreciornavei
andreciornavei / getx_bottomsheet.dart
Last active April 30, 2024 20:57
GetX - BottomSheet - Fit Height
Get.bottomSheet(
SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
),
@andreciornavei
andreciornavei / custom_appbar.dart
Last active November 6, 2020 00:17
Flutter / Scaffold / appBar - Custom appBar widget to place on Scaffold
class CustomAppBar extends PreferredSize {
@override
Size get preferredSize => Size.fromHeight(50);
@override
Widget build(BuildContext context) {
return Container(
height: preferredSize.height,
color: Colors.white,
alignment: Alignment.center,
child: SafeArea(
@andreciornavei
andreciornavei / flutter_either.dart
Created October 25, 2020 16:24
Flutter / Either / Dartz - Execute actions based on Left/Right properties of Either
import 'package:dartz/dartz.dart';
class EitherExample {
Future<Either<Failure, Entity>> handle() async {
try{
Entity entity = new Entity()
if(entity.document == null) throw Exception("Document is null");
return Right(entity);
}catch(error){
@andreciornavei
andreciornavei / equatable_entity.dart
Created October 25, 2020 16:35
Flutter / Equatable / Entity + Model Sample
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
class UserEntity extends Equatable {
final String id;
final String username;
final String password;
final List<LinkEntity> links;
UserEntity({
@required this.id,
@andreciornavei
andreciornavei / strapi_buffer_upload.js
Created September 8, 2021 23:21
Strapi upload plugin from buffer
// The returned ID can be passed on image field on model
const uploadFileBinary = async (binary, uuid) => {
const fileInfo = { name: uuid }
const metas = {}
const { optimize } = strapi.plugins.upload.services['image-manipulation'];
const { buffer, info } = await optimize(binary);
const formattedFile = await strapi.plugins.upload.services.upload.formatFileInfo(
{
filename: uuid + '.png',
@andreciornavei
andreciornavei / deploy_docker_aws.sh
Created September 17, 2021 22:04
Deploy to AWS with docker
# 1) check if is everything ok on local machine using docker-compose
docker-compose up
# 2) run aws configure and set your credentials
aws configute
# or import your csv configuration
aws configure import --csv file://$PDW/aws-profile-credentials.csv
# 3) check if your credentials is currecly imported and configured
aws configure list
@andreciornavei
andreciornavei / docker-images.sh
Last active March 31, 2022 10:37
Examples of docker images installation
#instala uma imagem mysql na versão 5.7 atribuindo um volume existente
docker run -d --name mysql --restart always -p 3306:3306 -v mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql-secret-pw mysql:5.7 --default-authentication-plugin "mysql_native_password"
#instala uma imagem redis na versão alpine atribuindo um volume existente
docker run -d --name redis --restart always -p 6379:6379 -v redis-volume:/var/lib/redis redis:alpine redis-server --requirepass "redis-secret-pw"
@andreciornavei
andreciornavei / index.js
Created March 16, 2022 13:33
AWS S3 STREAM
// IMPORT DEPENDENCIES
const stream = require("stream")
const AWS = require('aws-sdk');
const fs = require('fs');
const s3 = new AWS.S3();
// DOWNLOAD STREAM EXAMPLE
const s3download = (bucketName, keyName, localDest) => {
@andreciornavei
andreciornavei / file.js
Created May 5, 2022 10:12
Write and Read Json File on Javascript
import { writeFile, readFile } from "fs/promises"
export const save = async (data) => {
const currentData = await read("./../database.json")
currentData.push(data)
await writeFile(databaseFile, JSON.stringify(currentData))
}
export const read = async (filename) => {
const { pathname: databaseFile } = new URL(filename, import.meta.url)
@andreciornavei
andreciornavei / formatter.js
Created May 5, 2022 10:16
Formatting with Intl on Javascript
const language = "pt-BR"
// formatting lists
const vehicles = ["Car", "Bike", "Airplan"]
new Intl.ListFormat(language, { style: "long", type: "conjunction" }).format(vehicles)
// formatting units
const kmTraveled = 10000
new Intl.NumberFormat(language, { style: "unit", unit: "kilometer" }).format(kmTraveled)