Skip to content

Instantly share code, notes, and snippets.

@jonaswide
jonaswide / GLSL-Noise.md
Created October 28, 2022 13:07 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
@jonaswide
jonaswide / async-notes.js
Created January 25, 2018 09:35
How to async (personal note)
// Asuming both asyncProcess1 & asyncProcess2 takes 1 second each to proces
// .. Foo would take 2 seconds to execute
async function foo () {
const dep1 = await asyncProcess1()
const dep2 = await asyncProcess2()
console.log(dep1, dep2)
}
// .. Bar would take 1 second tu execute
@jonaswide
jonaswide / add-prop-to-obj.js
Last active January 24, 2018 12:40
Currying utility to add property to object
export const addPropToObj = key => obj => val => ({ ...obj, [key]: val })
// Example
const firstObj = { a: 1, b: 2, c: 3 }
addPropToObj("d", firstObj, 4) // { a: 1, b: 2, c: 3, d: 4 }
@jonaswide
jonaswide / get-prior-month.js
Created January 24, 2018 12:24
Recursive function for getting prior month on format YYYY-MM
export const getPriorMonth = (date, range, goingBackwards = true) => {
if (range === 0) return date
let dateArr = date.split("-")
if (dateArr[1] === "01" && goingBackwards) return getPriorMonth(`${dateArr[0] - 1}-12`, range - 1)
else if (dateArr[1] === "12" && !goingBackwards)
return getPriorMonth(`${dateArr[0] + 1}-01`, range - 1)
else {
let month = goingBackwards ? Number(dateArr[1]) - 1 : Number(dateArr[1]) + 1
if (month.toString().length === 1) month = `0${month}`
@jonaswide
jonaswide / concat-curryer.js
Last active January 24, 2018 12:36
Currying utility for concatenating either arrays or objects to an array
export const concatCurryer = pre => cur => {
const preToConcat = Array.isArray(pre) ? pre : [pre]
const curToConcat = Array.isArray(cur) ? cur : [cur]
return [...preToConcat, ...curToConcat]
}
// Examples
const arr1 = [{ val: "a" }, { val: "b" }]
const arr2 = [{ val: "c" }, { val: "d" }]
const obj1 = { val: 1 }