Skip to content

Instantly share code, notes, and snippets.

View katoozi's full-sized avatar
🏡
Working from home

mohammad katoozi katoozi

🏡
Working from home
  • Tehran, Iran
View GitHub Profile
@katoozi
katoozi / arrays.ts
Created June 21, 2020 08:11
react native hook and context helpers
/**
createArraySubsets generate array subsets.
@param {Array} array - source array.
@param {number} subsets - number of subsets. default is 2
@returns array with number of given subsets.
@example
createArraySubsets([1,2,3,4,5,6,7,8], 2); // output: [[1,2],[3,4],[5,6],[7,8]]
createArraySubsets([1,2,3,4], 3); // output: [[1,2,3], [4]]
createArraySubsets([1,2,3,4,5,6,7,8], 4); // output: [[1,2,3,4], [5,6,7,8]]
*/
@katoozi
katoozi / api.ts
Last active June 21, 2020 08:16
react native api module with axios
import axios, { AxiosInstance, ResponseType, Method, AxiosResponse, AxiosRequestConfig } from 'axios';
import { storeData, getData } from '../helpers';
export const STORAGE_TOKEN_KEY_NAME = 'token';
const PROTOCOL = 'https://'; // protocols: 'http', 'https'
const BASE_URL = 'example.com/'; // include just domain or sub domain and domain name.
const LEVEL_ONE_ENDPOINT = 'api/v1/'; // first level uri. include versioning etc.
const TOKEN_PRIFIX = 'token '; // do not remove the space. samples: token, Bearer, etc.