Skip to content

Instantly share code, notes, and snippets.

@jneidel
Last active February 26, 2019 17:10
Show Gist options
  • Select an option

  • Save jneidel/1fec38f5309f8c1ca6af5551c21c22fc to your computer and use it in GitHub Desktop.

Select an option

Save jneidel/1fec38f5309f8c1ca6af5551c21c22fc to your computer and use it in GitHub Desktop.

Revisions

  1. jneidel revised this gist Feb 26, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -36,3 +36,9 @@ let b = "b";
    // https://github.com/30-seconds/30-seconds-of-code#hextorgb-
    // RGBToHex
    // https://github.com/30-seconds/30-seconds-of-code#rgbtohex

    // uuidv4
    // https://github.com/30-seconds/30-seconds-of-code#uuidgeneratornode

    // colorize
    // https://github.com/30-seconds/30-seconds-of-code#colorize
  2. jneidel revised this gist Feb 26, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -34,3 +34,5 @@ let b = "b";

    // hexToRGB
    // https://github.com/30-seconds/30-seconds-of-code#hextorgb-
    // RGBToHex
    // https://github.com/30-seconds/30-seconds-of-code#rgbtohex
  3. jneidel revised this gist Feb 26, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -31,3 +31,6 @@ const zip = rows => rows[0].map( ( _, c ) => rows.map( row => row[c] ) );
    let a = "a";
    let b = "b";
    [ b, a ] = [ a, b ];

    // hexToRGB
    // https://github.com/30-seconds/30-seconds-of-code#hextorgb-
  4. jneidel revised this gist Jul 25, 2018. 1 changed file with 3 additions and 10 deletions.
    13 changes: 3 additions & 10 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,10 @@ function range( min, max ) {
    }

    // Return a random number from specified range
    function randomNum( min, max ) {
    return Math.floor( ( Math.random() * max ) + min );
    }
    const randomNum = ( min, max ) => Math.floor( ( Math.random() * max ) + min );

    // Get width of window
    function windowWidth() {
    return "innerWidth" in window ? window.innerWidth : document.documentElement.offsetWidth;
    }
    const windowWidth = () => "innerWidth" in window ? window.innerWidth : document.documentElement.offsetWidth;

    // Return name of current function
    function funcName() {
    @@ -25,11 +21,8 @@ function sortNumbers( array ) {
    array.sort( function( a, b ) { return a - b; } );
    }


    // Capitalize single word
    function capitalize( str ) {
    return str.charAt( 0 ).toUpperCase + str.slice( 1 );
    }
    const capitalize = str => str.charAt( 0 ).toUpperCase + str.slice( 1 );

    // Interweve two array, see pythons zip
    const zip = rows => rows[0].map( ( _, c ) => rows.map( row => row[c] ) );
  5. jneidel revised this gist May 29, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,9 @@ function capitalize( str ) {
    return str.charAt( 0 ).toUpperCase + str.slice( 1 );
    }

    // Interweve two array, see pythons zip
    const zip = rows => rows[0].map( ( _, c ) => rows.map( row => row[c] ) );

    // Swap item values
    let a = "a";
    let b = "b";
  6. jneidel revised this gist Feb 17, 2018. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -30,3 +30,8 @@ function sortNumbers( array ) {
    function capitalize( str ) {
    return str.charAt( 0 ).toUpperCase + str.slice( 1 );
    }

    // Swap item values
    let a = "a";
    let b = "b";
    [ b, a ] = [ a, b ];
  7. jneidel created this gist Jan 6, 2018.
    32 changes: 32 additions & 0 deletions utils.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // Return an array of numbers for specified range
    function range( min, max ) {
    min -= 2;
    return Array.from( new Array( max - min - 1 ), ( x,i ) => i - min );
    }

    // Return a random number from specified range
    function randomNum( min, max ) {
    return Math.floor( ( Math.random() * max ) + min );
    }

    // Get width of window
    function windowWidth() {
    return "innerWidth" in window ? window.innerWidth : document.documentElement.offsetWidth;
    }

    // Return name of current function
    function funcName() {
    const stack = new Error().stack;
    return stack.split( "" )[2].replace( /at/, "" ).replace( /\(.*?\)/, "" ).trim();
    }

    // Sort Numbers in actual order
    function sortNumbers( array ) {
    array.sort( function( a, b ) { return a - b; } );
    }


    // Capitalize single word
    function capitalize( str ) {
    return str.charAt( 0 ).toUpperCase + str.slice( 1 );
    }
    7 changes: 7 additions & 0 deletions utils.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # Get path of current file
    def filePath():
    return os.path.dirname( os.path.abspath( __file__ ) )

    # Convert negative int into positive
    def toPositive( num ):
    return int( str( num ).strip( "-" )