Skip to content

Instantly share code, notes, and snippets.

@adalberth
adalberth / Push to ghpages
Created September 21, 2019 21:03
gh-pages
### Push
git subtree push --prefix dist origin gh-pages
### Force
git subtree split --prefix dist -b gh-pages; git push -f origin gh-pages:gh-pages; git branch -D gh-pages;
### Force (detailed)
git checkout master # you can avoid this line if you are in master...
git subtree split --prefix dist -b gh-pages # create a local gh-pages branch containing the splitted output folder
git push -f origin gh-pages:gh-pages # force the push of the gh-pages branch to the remote gh-pages branch at origin
@adalberth
adalberth / Queue.js
Last active November 20, 2018 19:16
Queue
export default class Queue {
constructor () {
this.id = this.newid()
this.queue = []
}
add (callback) {
this.queue.push({
id: this.id,
callback
})
@adalberth
adalberth / Matematik.js
Created November 7, 2018 10:56
Selection of some maths functions
export function map (n, start1, stop1, start2, stop2) {
return ((n - start1) / (stop1 - start1)) * (stop2 - start2) + start2
}
export function constrain (n, low, high) {
return Math.max(Math.min(n, high), low)
}
export function mapConstrain (n, start1, stop1, start2, stop2) {
const start = start2 !== undefined ? start2 : start1
@adalberth
adalberth / Utils.js
Created November 7, 2018 10:51
Utils functions - just nice to have around
/*
css(element, {
backgroundColor: 'red',
})
*/
export function css (el, styles) {
for (var style in styles) {
el.style[style] = styles[style]
}
}
@adalberth
adalberth / Cover.js
Created November 7, 2018 10:49
Usefull for video og image backgrounds
/*
const {x,y,width,height} = Cover (elements-width, elements-height, container-width, container-height)
element.style.top = y + 'px'
element.style.left = x + 'px'
element.style.width = width + 'px'
element.style.height = height + 'px'
* Element will fill out the container like css {background-size: cover}
* make container desired dimensions and set to overflow:hidden
@adalberth
adalberth / sketch.js
Last active January 31, 2017 22:24
Star Patterns
var sliderA, sliderB
var dim = 20
function setup() {
createCanvas(600, 600)
sliderA = createSlider(0, dim, dim * 0.75, 1);
sliderA.position(600, 0);
sliderB = createSlider(0, dim * 2, dim * 0.25, 1);
sliderB.position(600, 20);
}