Skip to content

Instantly share code, notes, and snippets.

View CryceTruly's full-sized avatar
🎯
Focusing

cryce truly CryceTruly

🎯
Focusing
View GitHub Profile
from django.http import JsonResponse
def error_404(request, exception):
message = ("The endpoint you are trying to access might "
"have been removed, "
"had its name changed, or is temporarily unavailable. "
"Please check the documentation here : "
"/ docs and try again later.")
response = JsonResponse(data={"message": message, 'status_code': 404})
import React, { useState } from "react";
import "./App.css";
function App() {
const [form, setForm] = useState([]);
const prevIsValid = () => {
if (form.length === 0) {
return true;
}
@CryceTruly
CryceTruly / autoheight.js
Created November 1, 2020 19:22
react input component with dynamic height
import React, { useState } from "react";
import "./style.css";
const DynamicHeightInput = () => {
const [textareaHeight, setTextareaHeight] = useState(42);
const [formValue, setFormValue] = useState({});
const onChange = (event) => {
event.preventDefault();
event.persist();
import "./App.css";
import { useState } from "react";
function App() {
const options = [
{
header: {
name: "Account",
},
@CryceTruly
CryceTruly / useRef.js
Created December 16, 2020 05:08
Implementing componentDidUpdate using hooks.
const initialItemsRef = useRef([]);
useEffect(() => {
if (userItems.length) {
const prev = initialItemsRef.current;
initialWalletsRef.current = <whatToCheckForChanges>;
const newones = initialItemsRef.current;
if (newones.length - prev.length === 1) {
const difference = newones.find((x) => !prev.map((i) => i.AccountNumber).includes(x.AccountNumber));
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
import envs from '../config/env';
import {LOGOUT} from '../constants/routeNames';
import * as RootNavigation from '../navigations/RootNavigation';
let headers = {};
const axiosInstance = axios.create({
baseURL: envs.BACKEND_URL,
Here is how you can do it when the items in the arrays are objects.
The idea is to find the array of only the keys in an inner array using the map function
Then foreach of those check if they contain a spectific element key in the outer array.
const existsInBothArrays = array1.filter((element1) =>
array2.map((element2) => element2._searchKey).includes(element1._searchKey),
);
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios, {AxiosError} from 'axios';
import {logOutUserLocal} from 'redux/actions/auth/logout/clearAllUser';
import store from 'redux/store';
import envs from 'config/env';
// Getting token from local Storage
async function getLocalToken() {
const token = await AsyncStorage.getItem('token');
return `Bearer ${token}`;
~<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
class LogoutView(View):
def get(self, request):
logout(request)
return redirect('welcome')
class WelcomeView(View):
def get(self, request):
if request.user.is_authenticated:
return redirect('api-documentation')