Skip to content

Instantly share code, notes, and snippets.

@max8hine
Last active June 25, 2020 03:15

Revisions

  1. max8hine revised this gist Jun 25, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions helper.php
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,9 @@ function dumpObject($object) {
    var_dump($method);
    echo "<br>";
    };
    }

    if( $image ){
    print_r($image->getUrl());
    print_r($image->extension); die();
    }
  2. max8hine revised this gist Apr 29, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions helper.js
    Original file line number Diff line number Diff line change
    @@ -144,6 +144,8 @@ export const getCurrentDate = () => {
    };
    };

    // replaceUrlSuffixTo('.png')('anything.jpg') => 'anything.png'
    export const replaceUrlSuffixTo = suffixWithDot => filePath => filePath.replace(/\.[\w]+$/, suffixWithDot)

    export const isUrlImage = url => {
    const validImageSuffix = new RegExp(/\.(jpeg|jpg|gif|png|svg)$/, "");
  3. max8hine revised this gist Apr 29, 2020. 1 changed file with 82 additions and 0 deletions.
    82 changes: 82 additions & 0 deletions helper.js
    Original file line number Diff line number Diff line change
    @@ -73,3 +73,85 @@ export isUrlImage = url => {
    const validImageSuffix = new RegExp(/\.(jpeg|jpg|gif|png|svg)$/, "");
    return url.match(validImageSuffix) !== null
    }

    export is/**
    * A errorHandler function
    * Handle Axios request error
    * Handle Javascript Error instance
    * Handle Javascript TypeError
    * Handle Any error and return default error message
    * @param {Object || Any} error
    * @returns {String}
    */
    export const errorHandler = (
    error,
    message = "An error occurred, please try again later"
    ) => {
    if (!error) return message;
    if (error.response) {
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
    console.info(error.response.data);
    console.info(error.response.status);
    console.info(error.response.headers);
    if (error.response.data.error) {
    if (typeof error.response.data.error === "string") {
    message = error.response.data.error;
    }
    }
    return message;
    }
    if (error.request) {
    // The request was made but no response was received
    // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
    // http.ClientRequest in node.js
    console.info(error.request);
    return message;
    }
    // Something happened in setting up the request that triggered an Error
    if (error.config) console.info(error.config);
    if (error.message) {
    console.info(error.message);
    if (typeof error.message === "string") {
    message = error.message;
    }
    }
    return message;
    };


    /**
    * A Craft Date generator
    * @returns {Object}
    */
    export const getCurrentDate = () => {
    const now = new Date();

    let hour = now.getHours();
    let minute = now.getMinutes();
    let ap = "AM";

    if (hour > 11) ap = "PM";
    if (hour > 12) hour = hour - 12;
    if (hour == 0) hour = 12;
    if (hour < 10) hour = "0" + hour;

    if (minute < 10) minute = "0" + minute;

    return {
    date: new Date().toLocaleDateString('en-GB'),
    time: `${hour}:${minute} ${ap}`,
    };
    };


    export const isUrlImage = url => {
    const validImageSuffix = new RegExp(/\.(jpeg|jpg|gif|png|svg)$/, "");
    return url.match(validImageSuffix) !== null
    }

    export const isInputFileImage = file => {
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml']);
    const fileType = file['type']
    return validImageTypes.includes(fileType)
    }
  4. max8hine revised this gist Apr 29, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions helper.js
    Original file line number Diff line number Diff line change
    @@ -67,3 +67,9 @@ export const getCurrentDate = () => {
    time: `${hour}:${minute} ${ap}`,
    };
    };


    export isUrlImage = url => {
    const validImageSuffix = new RegExp(/\.(jpeg|jpg|gif|png|svg)$/, "");
    return url.match(validImageSuffix) !== null
    }
  5. max8hine revised this gist Apr 14, 2020. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions helper.js
    Original file line number Diff line number Diff line change
    @@ -42,3 +42,28 @@ export const errorHandler = (
    }
    return message;
    };


    /**
    * A Craft Date generator
    * @returns {Object}
    */
    export const getCurrentDate = () => {
    const now = new Date();

    let hour = now.getHours();
    let minute = now.getMinutes();
    let ap = "AM";

    if (hour > 11) ap = "PM";
    if (hour > 12) hour = hour - 12;
    if (hour == 0) hour = 12;
    if (hour < 10) hour = "0" + hour;

    if (minute < 10) minute = "0" + minute;

    return {
    date: new Date().toLocaleDateString('en-GB'),
    time: `${hour}:${minute} ${ap}`,
    };
    };
  6. max8hine revised this gist Feb 18, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion helper.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    */
    export const errorHandler = (
    error,
    message = "Error occur, Please try again"
    message = "An error occurred, please try again later"
    ) => {
    if (!error) return message;
    if (error.response) {
  7. max8hine revised this gist Feb 18, 2020. 1 changed file with 44 additions and 0 deletions.
    44 changes: 44 additions & 0 deletions helper.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    /**
    * A errorHandler function
    * Handle Axios request error
    * Handle Javascript Error instance
    * Handle Javascript TypeError
    * Handle Any error and return default error message
    * @param {Object || Any} error
    * @returns {String}
    */
    export const errorHandler = (
    error,
    message = "Error occur, Please try again"
    ) => {
    if (!error) return message;
    if (error.response) {
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
    console.info(error.response.data);
    console.info(error.response.status);
    console.info(error.response.headers);
    if (error.response.data.error) {
    if (typeof error.response.data.error === "string") {
    message = error.response.data.error;
    }
    }
    return message;
    }
    if (error.request) {
    // The request was made but no response was received
    // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
    // http.ClientRequest in node.js
    console.info(error.request);
    return message;
    }
    // Something happened in setting up the request that triggered an Error
    if (error.config) console.info(error.config);
    if (error.message) {
    console.info(error.message);
    if (typeof error.message === "string") {
    message = error.message;
    }
    }
    return message;
    };
  8. max8hine created this gist Sep 24, 2019.
    9 changes: 9 additions & 0 deletions helper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function dumpObject($object) {
    $class_name = get_class($object);
    $methods = get_class_methods($class_name);
    foreach($methods as $method)
    {
    var_dump($method);
    echo "<br>";
    };
    }