Skip to content

Instantly share code, notes, and snippets.

@danyshaanan
Last active December 19, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyshaanan/6007480 to your computer and use it in GitHub Desktop.
Save danyshaanan/6007480 to your computer and use it in GitHub Desktop.
Javascript snippets
'use strict'
// Create a random color:
function color() {
return '#'+(Math.random().toString(16) + '000000').slice(2, 8)
}
for (var i=0; i<10; i++) console.log(color())
////////////////////////////////////////////////////////////////////////////////
var consoleImage = function(url) {
var image = new Image();
image.onload = function() {
function px(s){return s+'px ';}
var css = {
'font-size': px(1),
'padding': px(this.height/2) + px(this.width/2),
'line-height': px(this.height),
'background': 'url('+this.src+')',
'background-size': px(this.width) + px(this.height)
};
console.log('%c', Object.keys(css).map(function(key){return key+':'+css[key]+';'}).join(''));
};
image.src = url;
};
////////////////////////////////////////////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment