Skip to content

Instantly share code, notes, and snippets.

View WrathChaos's full-sized avatar
❤️‍🔥
Working Hard

FreakyCoder WrathChaos

❤️‍🔥
Working Hard
View GitHub Profile
@WrathChaos
WrathChaos / difference-between-two-timestamps.md
Last active December 19, 2022 14:08
How to get the difference between two dates with MomentJS? Article: WIP
// These are our dynamic variables
const format = "MM/DD/YYYY HH:mm:ss"
const start = moment(1578240964000); // Input starting timestamp
const end = moment(1578244564000); // Input ending timestamp
// Main Difference Logic
const countDownStart = start.add(1, "second");
const then = moment(countDownStart).format(format);
const now = moment(end).format(format);
const ms = moment(now, format).diff(
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
npx react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios/assets
@WrathChaos
WrathChaos / handle-error-retrofit-android.md
Created December 14, 2019 16:10
How to handle 401 error on RetroFit
// Add other Interceptors
httpClient.addInterceptor(new Interceptor() {
    @Override
    public Response intercept(Interceptor.Chain chain) throws IOException {
        Request original = chain.request();
        Request request = original.newBuilder()
                .header("Authorization", token_type + " " + access_token)
                .method(original.method(), original.body())
 .build();
@WrathChaos
WrathChaos / close_keyboard.md
Created December 14, 2019 15:30
React Native: How to close the keyboard programmatically?
import { Keyboard } from "react-native";

// USAGE

<TouchableOpacity onPress={() => Keyboard.dismiss()} /> 

// Simply
Keyboard.dismiss();
@WrathChaos
WrathChaos / componentDidUpdate.md
Created November 7, 2019 20:35
React Hooks: componentDidUpdate
// Class
componentDidUpdate() {
    console.log('componentDidUpdate');
}

// React Hooks: componentDidUpdate
useEffect(() => {
    console.log('React Hooks: componentDidUpdate');
})
@WrathChaos
WrathChaos / componentWillReceiveProps.md
Created November 7, 2019 20:29
React Hooks: componentWillReceiveProps
// Class
componentWillReceiveProps(nextProps) {
    if (nextProps.data !== this.props.data) {
        console.log('Prop Received: ', nextProps.data);
    }
}

// React Hooks: componentWillReceiveProps
useEffect(() =&gt; {
@WrathChaos
WrathChaos / componentWillUnmount.md
Last active November 7, 2019 20:31
React Hooks: componentWillUnmount
// Class
componentWillUnmount() {
    console.log('componentWillUnmount');
}

// React Hooks: componentWillUnmount
useEffect(() => {
    return () => console.log('React Hooks: componentWillUnmount');
}, [])
@WrathChaos
WrathChaos / componentDidMount.md
Last active November 7, 2019 20:31
React Hooks: componentDidMount
// Class
componentDidMount() {
    console.log('componentDidMount');
}

// React Hooks: componentDidMount
useEffect(() => {
    console.log('React Hooks: componentDidMount');
}, [])
@WrathChaos
WrathChaos / metro.config.md
Created October 3, 2019 07:06
React Native metro.config.js
/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {