How to add an image to a gist
- Create or find a gist that you own.
- Clone your gist (replace
<hash>
with your gist's hash):# with ssh git clone git@gist.github.com:<hash>.git mygist # with https git clone https://gist.github.com/<hash>.git mygist
<hash>
with your gist's hash):
# with ssh
git clone git@gist.github.com:<hash>.git mygist
# with https
git clone https://gist.github.com/<hash>.git mygist
{ | |
"version": "1.2.3", | |
"scripts": { | |
"get-version": "awk -F'\"' '/\"version\": \".+\"/{ print $4; exit; }' package.json" | |
} | |
} |
{ | |
"version": "1.2.3", | |
"scripts": { | |
"get-version": "node -p \"require('./package').version\"" | |
} | |
} |
{ | |
"version": "1.2.3", | |
"scripts": { | |
"get-version": "jq -r .version package.json" | |
} | |
} |
{ | |
"version": "1.2.3", | |
"scripts": { | |
"get-version": "echo $npm_package_version" | |
} | |
} |
An example that shows the difference between creating a JavaScript class and subclass in ES5 and ES6.
function checkBoundaryCollision(image) { | |
var hasCollision = false; | |
// left or right collision | |
if (position.x < 0 || position.x + image.width > width) { | |
velocity.x *= -1; | |
hasCollision = true; | |
} | |
// top or bottom collision | |
if (position.y < 0 || position.y + image.height > height) { | |
velocity.y *= -1; |
function draw() { | |
background('#111'); | |
var image = images[imageIndex]; | |
var hasCollision = checkBoundaryCollision(image); | |
if (hasCollision) { | |
imageIndex++; | |
if (imageIndex + 1 > images.length) { | |
imageIndex = 0; | |
} | |
image = images[imageIndex]; |
function setup() { | |
createCanvas(window.innerWidth, window.innerHeight); | |
} |