Skip to content

Instantly share code, notes, and snippets.

View rafaelqueiroz88's full-sized avatar
🔷
Darting

Rafael Queiroz de Castro rafaelqueiroz88

🔷
Darting
View GitHub Profile
@rafaelqueiroz88
rafaelqueiroz88 / workflow.yml
Created June 10, 2024 11:53
Ruby on Rails + Github Actions
name: "Ruby on Rails trigger Github Actions"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
@rafaelqueiroz88
rafaelqueiroz88 / get_random_element.dart
Created January 24, 2024 17:14
Get some element at random from array
bool getRandomElement(List<bool> list) => list[Random().nextInt(list.length)];
import 'package:flutter_week_view/flutter_week_view.dart';
DateTime now = DateTime.now();
DateTime date = DateTime(now.year, now.month, now.day);
DayView dayView() {
return DayView(
date: now,
events: [
FlutterWeekViewEvent(
@rafaelqueiroz88
rafaelqueiroz88 / find_week_start_or_end.dart
Created October 25, 2023 13:02
Find first and last DateTime of a week
void main() {
// Find first date and last date of CURRENT WEEK
DateTime today = DateTime.now();
print(findFirstDateOfTheWeek(today));
print(findLastDateOfTheWeek(today));
// Find first date and last date of any provided date
DateTime date = DateTime.parse('2023-09-01');
print(findFirstDateOfTheWeek(date));
print(findLastDateOfTheWeek(date));
@rafaelqueiroz88
rafaelqueiroz88 / password.dart
Created October 8, 2023 14:21
Encrypting locally password before request
import 'dart:convert';
// package needed: https://pub.dev/packages/crypto
import 'package:crypto/crypto.dart';
void main() {
var passwordBytes = utf8.encode("s0me-super-cool-p@$$WorD-here");
var passwordEncrypt = sha256.convert(passwordBytes);
@rafaelqueiroz88
rafaelqueiroz88 / password_check.dart
Created October 4, 2023 00:29
Dart Regular Expression (Refex)
/**
* It forces strong passwords
* @require String password
* @return bool
*
* return true if password has:
* 1 capitalized character
* 1 special character
* 1 number
*/
@rafaelqueiroz88
rafaelqueiroz88 / test.dart
Created September 20, 2023 19:06
Flutter test internet connection
void testConnection() async {
try {
final connection = await InternetAddress.lookup('www.google.com');
if (connection.isNotEmpty && connection.first.rawAddress.isNotEmpty) {
hasConnection = true;
}
} on SocketException catch (_) {
hasConnection = false;
}
}
@rafaelqueiroz88
rafaelqueiroz88 / drawer.dart
Created August 21, 2023 15:26
Flutter Drawer Example
import 'package:flutter/material.dart';
class AppDrawer extends StatelessWidget {
const AppDrawer({super.key});
@override
Widget build(BuildContext context) {
return Drawer(
backgroundColor: Colors.white,
child: Column(
@rafaelqueiroz88
rafaelqueiroz88 / http_status_constants.dart
Created August 10, 2023 15:28
All possible Http status code
class HttpStatusConstants {
// can't be 'continue' because it is reserved name
static const int continueCode = 100;
static const int switchingProtocols = 101;
static const int processing = 102;
static const int ok = 200;
static const int created = 201;
static const int accepted = 202;
static const int nonAuthoritative = 203;
static const int noContent = 204;
@rafaelqueiroz88
rafaelqueiroz88 / response_statusCode_helper.dart
Created August 10, 2023 15:27
Get any response.StatusCode and return as integer
import 'package:your_project_name/config/http_status_constants.dart';
int responseCodeHelper(code) {
switch (code) {
case HttpStatusConstants.continueCode:
return HttpStatusConstants.continueCode;
case HttpStatusConstants.switchingProtocols:
return HttpStatusConstants.switchingProtocols;
case HttpStatusConstants.processing:
return HttpStatusConstants.processing;