Skip to content

Instantly share code, notes, and snippets.

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

Usman Suleiman Babakolo usmansbk

🏠
Working from home
View GitHub Profile
import { useCallback, useState } from "react";
import { Platform } from "react-native";
import { ImageInfo } from "expo-image-picker";
import * as mime from "mime";
export default function useUploadAvatar() {
const [uploading, setUploading] = useState(false);
const [error, setError] = useState<Error | null>(null);
const [data, setData] = useState(null);
const { accessToken } = useAuth();
@usmansbk
usmansbk / git-ssh-error-fix.sh
Created January 17, 2022 18:09 — forked from Tamal/git-ssh-error-fix.sh
Solution for 'ssh: connect to host github.com port 22: Connection timed out' error
$ git clone [email protected]:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
$ # This should also timeout
$ ssh -T [email protected]
ssh: connect to host github.com port 22: Connection timed out
$ # but this might work
@usmansbk
usmansbk / todo-list.html
Last active July 22, 2021 15:51
Basic todo list application
<html>
<body>
<form id="form">
<input id="input" required />
</form>
<ul id="list"></ul>
<button id="clear-all">clear all completed</button>
<script>
let todos = [];
@usmansbk
usmansbk / is-it-dry-1.js
Last active July 17, 2021 08:26
IS IT DRY. We check and try to keep the code DRY.
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse' 'Lion', 'Dragon'];
// Print all pets: NOT DRY
console.log(pets[0]);
console.log(pets[1]);
console.log(pets[2]);
console.log(pets[3]);
/**
* SOLUTION
* We use a for loop to eliminate repetition
import React from 'react';
import { View, Text, Image } from 'react-native';
import emojiRegex from 'emoji-regex';
const avatarColors = [
'red',
'blue',
'green'
];
@usmansbk
usmansbk / geocoder.js
Last active November 9, 2019 21:19
Geocoder port using GeoDB cities API
const HOST = process.env.GEODB_HOST;
const KEY = process.env.GEODB_API_KEY;
const printableNumber = num => (num < 0 ? "" : "+") + num;
const parseLocation = location => {
const { lat, lng } = location;
return `${printableNumber(lat)}${printableNumber(lng)}`
};
@usmansbk
usmansbk / getSectionItemLayout.js
Last active June 2, 2019 20:39
getItemLayout from react-native SectionList
const getSectionItemLayout = ({
getItemHeight = () => 0,
getSeparatorHeight = () => 0,
getSectionHeaderHeight = () => 0,
getSectionFooterHeight = () => 0,
listHeaderHeight = 0,
listFooterHeight = 0,
}) => (sections, index) => {
let length = 0, offset = 0, currentIndex = 0;
import React from 'react';
import {
GoogleSignin,
statusCodes
} from 'react-native-google-signin';
import SimpleToast from 'react-native-simple-toast';
import Button from './Button';
export default class Container extends React.Component {
state = {
@usmansbk
usmansbk / GoogleOAuth.js
Last active May 21, 2020 11:22
react-native Google refresh token handler using react-native-google-signin npm package
import { GoogleSignin } from 'react-native-google-signin';
export default class GoogleOAuth {
refreshGoogleToken = () => {
return this._refreshGoogleTokenImpl();
}
_refreshGoogleTokenImpl = () => {
return new Promise(async (res, rej) => {
const isSignedIn = await GoogleSignin.isSignedIn();
@usmansbk
usmansbk / stripJSON.js
Last active April 22, 2021 15:32
Recursively remove json keys in an array
/**
* @function stripJSON
* @desc - This function removes selected object keys
* @param {Object} json - JavaScript object to strip
* @param {Object[]} keys - array of selected keys (string)
* @return {Object} - deep copy of object without keys
*/
function stripJSON(json, keys) {
if (json === null || json === undefined) return json;
let obj = {}, key;