Last active
February 26, 2019 17:10
-
-
Save jneidel/1fec38f5309f8c1ca6af5551c21c22fc to your computer and use it in GitHub Desktop.
Utilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
const randomNum = ( min, max ) => Math.floor( ( Math.random() * max ) + min ); | |
// Get width of window | |
const windowWidth = () => "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 | |
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] ) ); | |
// Swap item values | |
let a = "a"; | |
let b = "b"; | |
[ b, a ] = [ a, b ]; | |
// hexToRGB | |
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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( "-" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment