Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
Setting browsers on fire!!!

Emeke Ajeh Godofbrowser

🔥
Setting browsers on fire!!!
View GitHub Profile
@Godofbrowser
Godofbrowser / a-short-ajax-error-story-2-of-4.js
Last active Nov 11, 2019
This gist is part of an article and may not covey the actual message on it's own. Link to article: https://medium.com/@ejjay/a-short-ajax-story-on-error-handlers-8baeeccbc062
View a-short-ajax-error-story-2-of-4.js
import axios from 'axios';
import {notifier} from './util';
axios.interceptors.response.use(undefined, function (error) {
const statusCode = error.response ? error.response.status : null;
if (statusCode === 404) {
notifier.error('The requested resource does not exist or has been deleted')
}
@Godofbrowser
Godofbrowser / a-short-ajax-error-story-3-of-4.js
Last active Nov 11, 2019
This gist is part of an article and may not covey the actual message on it's own. Link to article: https://medium.com/@ejjay/a-short-ajax-story-on-error-handlers-8baeeccbc062
View a-short-ajax-error-story-3-of-4.js
import axios from 'axios';
import {notifier} from './util';
// errorComposer will compose a handleGlobally function
const errorComposer = (error) => {
return () => {
const statusCode = error.response ? error.response.status : null;
if (statusCode === 404) {
notifier.error('The requested resource does not exist or has been deleted')
}
@Godofbrowser
Godofbrowser / a-short-ajax-error-story-4-of-4.ts
Last active Nov 11, 2019
This gist is part of an article and may not covey the actual message on it's own. Link to article: https://medium.com/@ejjay/a-short-ajax-story-on-error-handlers-8baeeccbc062
View a-short-ajax-error-story-4-of-4.ts
import axios, {AxiosError} from 'axios';
import {notifier} from './util';
interface ComposedError {
readonly message: string;
readonly error: AxiosError;
handleGlobally(): void;
getError(): AxiosError;
}
@Godofbrowser
Godofbrowser / a-short-ajax-error-story-1-of-4.js
Last active Nov 11, 2019
This gist is part of an article and may not covey the actual message on it's own. Link to article: https://medium.com/@ejjay/a-short-ajax-story-on-error-handlers-8baeeccbc062
View a-short-ajax-error-story-1-of-4.js
import axios from 'axios';
import {notifier} from './util';
// Fetch some missing information
axios.get('/api/articles/not-found').then(resp => {
// So something with article information
}).catch(error => {
const statusCode = error.response ? error.response.status : null;
@Godofbrowser
Godofbrowser / react-native-metro
Created Sep 18, 2019
Reconnect to network after device disconnect from react=native development server (metro)
View react-native-metro
Check that the device is reconnected to the machine with:
`adb devices`
Reroute the connection to the development server with:
`adb reverse tcp:8081 tcp:8081`
@Godofbrowser
Godofbrowser / command.md
Last active Dec 7, 2020
Launch android emulator from terminal without opening android studio (useful for developments with react native, ionic native, etc)
View command.md

Change dir to sdk tools bin cd %ANDROID_SDK_ROOT%/tools

List and get device name

emulator -list-avds

Now you have list of available avds, copy one of the avd name and do next step

Launch the emulator

@Godofbrowser
Godofbrowser / README.md
Created Aug 22, 2019 — forked from lopspower/README.md
Hexadecimal color code for transparency
View README.md

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

All hex value from 100% to 0% alpha:

@Godofbrowser
Godofbrowser / heroku-auto-set-env.md
Last active Dec 7, 2020
Heroku auto set env (for laravel and apps using .env files)
View heroku-auto-set-env.md

$ cd <application name>

Where is the dir where you have the .env file.

heroku config:set $(cat .env | sed '/^$/d; /#[[:print:]]*$/d')

@Godofbrowser
Godofbrowser / Google cloud storage credentials for Now.sh
Created Jun 29, 2019
This gist shows how to use the env var GCLOUD_CREDENTIALS provided by now.sh after google cloud storage integration
View Google cloud storage credentials for Now.sh
const {Storage} = require('@google-cloud/storage');
const fromB64 = (string) => Buffer.from(string, 'base64').toString();
const credentials = JSON.parse(fromB64(process.env.GCLOUD_CREDENTIALS))
const storage = new Storage(credentials ? {credentials} : undefined)
@Godofbrowser
Godofbrowser / axios.refresh_token.1.js
Last active Aug 11, 2022 — forked from Culttm/axios.refresh_token.js
Axios interceptor for refresh token when you have multiple parallel requests. Demo implementation: https://github.com/Godofbrowser/axios-refresh-multiple-request
View axios.refresh_token.1.js
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);