Skip to content

Instantly share code, notes, and snippets.

@didacus
didacus / useWindowSize.js
Created January 29, 2021 16:12
React hook to capture window size (Debounced).
import { useState, useEffect } from "react"
// Debounce function
function debounce(func, wait, immediate) {
var timeout
return function () {
var context = this,
args = arguments
var later = function () {
timeout = null
@didacus
didacus / script.js
Created August 21, 2020 12:17
UI Picker Spark AR
const NativeUI = require('NativeUI');
const Textures = require('Textures');
const Patches = require('Patches');
Promise.all([
Textures.findFirst('icon_1'),
Textures.findFirst('icon_2'),
Textures.findFirst('icon_3'),
]).then(onReady);
var api = 'https://api.giphy.com/v1/gifs/search?';
var apiKey = '&api_key=dc6zaTOxFJmzC';
var query = '&q=rainbow';
function setup() {
noCanvas();
var url = api + apiKey + query;
loadJSON(url, gotData);
}
@didacus
didacus / random_colour.js
Created January 29, 2020 22:26
Random colour function
function getRandomColor() {
var letters = "0123456789ABCDEF";
var color = "#";
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
@didacus
didacus / grid.js
Created January 12, 2020 12:43
P3 — Basic grid based on size
void setup() {
size(800,800);
}
void draw() {
int tilesX = 10;
int tilesY = 1;
int tileW = int(width/tilesX);
@didacus
didacus / araxa.json
Created January 10, 2020 22:10
ARAXA.json
{"v":"5.5.10","fr":30,"ip":0,"op":360,"w":1920,"h":1920,"nm":"main","ddd":0,"assets":[{"id":"comp_0","layers":[{"ddd":0,"ind":1,"ty":4,"nm":"ARAXA Outlines","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[960,960,0],"ix":2},"a":{"a":0,"k":[670.5,55.5,0],"ix":1},"s":{"a":0,"k":[142,142,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[43.568,-54.5],[24.961,-54.5],[4.838,-14.406],[23.756,-14.406]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[-6.486,9.251],[-25.094,9.251],[-47.443,54.5],[-28.524,54.5]],"c":true},"ix":2},"nm":"Path 2","mn":"ADBE Vector Shape - Group","hd":false},{"ind":2,"ty":"sh","ix":3,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[-43.179,-54.5],[-20.829,-54.5],[47.443,54.5],[24.9
@didacus
didacus / Parallax.tsx
Created May 16, 2019 07:58
Framer X — Parallax
import { Override, motionValue, useTransform } from "framer"
const contentOffsetY = motionValue(0)
// Apply this override to your scroll component
export function TrackScroll(): Override {
return { contentOffsetY: contentOffsetY }
}
// Apply this override to your parallax layer
@didacus
didacus / watch-changes.js
Last active June 12, 2019 14:03
ReactJS — Watch for changes and fetch
// New
const [clear, setClear] = useCycle(false, true)
useEffect(() => {
//props to watch for changes
const watchlist = ["clear"]
if (watchlist.some(prop => props[prop] !== clear)) {
console.log("clear is", clear, "props.clear is", props.clear)
}
@didacus
didacus / css.js
Created February 7, 2019 12:39
ReactJS (Framer X) — Extends CSS properties
const styles = {
container: {
position: 'relative',
height: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
color: '#8855FF',
@didacus
didacus / times.js
Created February 7, 2019 08:59
ES2015 Spread operator — Do it 'x' times
const dotIt = number => {
const res = [ ...Array(number) ].map((_, i) => {
return i * number
})
return res
}