Skip to content

Instantly share code, notes, and snippets.

View RodolfoSilva's full-sized avatar
🏠
Working from home

Rodolfo Silva RodolfoSilva

🏠
Working from home
View GitHub Profile
@alican
alican / django_field_update_checker.txt
Last active September 17, 2023 08:46
check if django model fields changed after save
class DjangoModel(models.Model):
@classmethod
def from_db(cls, db, field_names, values):
instance = super().from_db(db, field_names, values)
instance._state.adding = False
instance._state.db = db
instance._old_values = dict(zip(field_names, values))
return instance
@lequanghuylc
lequanghuylc / pure-react.md
Last active January 17, 2023 14:13
[Using React & React Native without State management library] #article #react

It’s common these day when React & React Native developers use State management library (like Redux). I’ve been using React & React Native for a while now and found out that Pure React is actually not bad. In this article I will share my way of doing things with React & React Native purely, without State management library (represented by Redux). 

For those of you who are struggling learning Redux, because of the overwhelming of the whole React/JSX/Babel/Webpack/Native Component/Native Module/.. and have to add Redux to the list just to solve some of React problems, or because of the high learning curve of Redux, I hope you find this article helpful.

Some of React problems with State Management

Assuming you have some knowledge of React, I will jump right in the problems that most of us encoutered at the beginning of time learning React:

  • Flow pass data down, pass event up makes us to pass data & function via props and it's hard to manage when amount of props gets huge. (Comunication between component
import React from 'react';
import { Text, View, TouchableOpacity, VibrationVibration, Dimensions } from 'react-native';
import { Camera, Permissions, FileSystem } from 'expo';
import { Ionicons, Entypo } from '@expo/vector-icons';
const { width, height } = Dimensions.get('window');
export default class CameraScreen extends React.Component {
state = {
@beginor
beginor / snowflake-id.sql
Last active May 9, 2024 15:28
Twitter Snowflake ID for PostgreSQL
CREATE SEQUENCE public.global_id_seq;
ALTER SEQUENCE public.global_id_seq OWNER TO postgres;
CREATE OR REPLACE FUNCTION public.id_generator()
RETURNS bigint
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Font
:set guifont=Source\ Code\ Pro:h14
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Hide pointless junk at the bottom, doesn't work in .vimrc for some reason?
:set laststatus=0
:set noshowmode "don't show --INSERT--
:set noruler "don't show line numbers/column/% junk
create or replace function add_on_update_trigger
(schema_name text, table_name text, column_name text)
returns void AS $body$
declare
target_table text =
quote_ident(schema_name) || '.' || quote_ident(table_name);
trig_name text =
quote_ident(
'update_' || schema_name || '_' || table_name || '_' || column_name
);
@bvaughn
bvaughn / LICENSE.md
Last active November 9, 2023 07:13
Advanced example for manually managing subscriptions in an async-safe way using hooks

The MIT License (MIT)

Copyright © <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

@andre-bahia
andre-bahia / CurrencyPtBrInputFormatter.dart
Last active April 29, 2024 15:06
Flutter TextInputFormatter Currency pt_BR
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
class CurrencyPtBrInputFormatter extends TextInputFormatter {
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
if(newValue.selection.baseOffset == 0){
return newValue;
}
@joshsalverda
joshsalverda / useFieldArray.js
Last active May 22, 2023 09:49
Custom useFieldArray hook for formik using immutability-helper
import {useCallback, useRef, useEffect} from 'react'
import {useField, useFormikContext} from 'formik'
import update from 'immutability-helper'
const useFieldArray = props => {
const [field, meta] = useField(props)
const fieldArray = useRef(field.value)
const {setFieldValue} = useFormikContext()
useEffect(() => {
@baumandm
baumandm / Chakra-UI x React-datepicker.md
Last active March 4, 2023 20:56
Chakra-UI x React-datepicker

⚠️ I'd recommend using this fork by @igoro00 which has better theme support.


Tiny wrapper component for React-Datepicker to stylistically fit with Chakra-UI 1.x.

<DatePicker selectedDate={myDate} onChange={(d) => console.log(d)} />