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 / http_status_mapper.dart
Last active February 18, 2025 20:18
All possible Http status code
class HttpStatusMapper {
// can't be 'continue' because it is reserved name
static const Map<String, dynamic> continueCode = {
'status': 'continue',
'code': 100,
};
static const Map<String, dynamic> switchingProtocols = {
'status': 'Switching Protocols',
'code': 101,
};
@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;
@rafaelqueiroz88
rafaelqueiroz88 / hasNullProperty.dart
Created August 7, 2023 00:04
Check if a class has a null value
bool isInept() {
return [
district,
extraInfo,
name,
number,
].contains(null);
}
@rafaelqueiroz88
rafaelqueiroz88 / file_with_listview.dart
Created June 8, 2023 14:37
ScrollController triggers when ListView ends
// maybe this file must be a StateFull
late final scrollController = ScrollController()..addListener(onScroll);
void onScroll() {
if (scrollController.position.pixels == 0) {
fetchSearch();
}
}
@rafaelqueiroz88
rafaelqueiroz88 / *_spec.rb
Last active June 6, 2023 22:16
Manipulates time inside Rspec tests
# some spec suit
RSpec.describe SomeClass do
it 'travel back' do
travel_to Time.local(1994) do
puts Time.zone.now
# outputs: '1994-mm-dd ...'
end
end
end
@rafaelqueiroz88
rafaelqueiroz88 / settings.json
Created June 6, 2023 14:05
Visual Studio Code Limiter Rulers (add to config)
"editor.rulers": [
{
"column": 80,
"color": "#337633"
},
{
"column": 100,
"color": "#C8CA33"
},
{
@rafaelqueiroz88
rafaelqueiroz88 / example.rb
Created March 10, 2023 14:01
Listing all models in a Rails project
Rails.application.eager_load!
ActiveRecord::Base.descendants # all models and its attributes
ApplicationRecord.descendants.collect(&:name) # filtering model names
@rafaelqueiroz88
rafaelqueiroz88 / install-hooks.bash
Created November 12, 2022 02:18
Creating a Hook installer
#!/usr/bin/env bash
GIT_DIR=$(git rev-parse --git-dir)
echo "Preparing hooks..."
# These commands will create symlink to our pre-commit script
ln -s ../../.github/pre-commit.bash $GIT_DIR/hooks/pre-commit
ln -s ../../.github/pre-push.bash $GIT_DIR/hooks/pre-push
ln -s ../../.github/post-checkout.bash $GIT_DIR/hooks/post-checkout
@rafaelqueiroz88
rafaelqueiroz88 / post-checkout.bash
Created November 12, 2022 02:18
Creating a Post-Checkout Hook
#!/bin/bash
# File checkout
if [ "$3" == "0" ]; then exit; fi
NUM_CHECKOUTS=`git reflog --date=local | grep -o ${BRANCH_NAME} | wc -l`
# If the refs of the previous and new heads are the same
# AND the number of checkouts equals one, a new branch has been created
if [ "$1" == "$2" ] && [ ${NUM_CHECKOUTS} -eq 1 ]; then
@rafaelqueiroz88
rafaelqueiroz88 / pre-commit.bash
Created November 12, 2022 02:17
Creating a Pre-Commit Hook
#!/usr/bin/env bash
echo "Running pre-commit hook"
.github/run-rubocop.bash
# $? stores exit value of the last command
if [ $? -ne 0 ]; then
echo "Rubocop detected offences in your code. Check it out before proceed"
exit 1
fi