Skip to content

Instantly share code, notes, and snippets.

View robksawyer's full-sized avatar
🎯
Focusing

Rob Sawyer robksawyer

🎯
Focusing
View GitHub Profile
@robksawyer
robksawyer / excludedActivityTypes.swift
Last active March 7, 2024 09:10
A list of UIActivity.ActivityType for modern apps.
let excludedActivityTypes = [
UIActivity.ActivityType.print,
UIActivity.ActivityType.openInIBooks,
UIActivity.ActivityType.copyToPasteboard,
UIActivity.ActivityType.addToReadingList,
UIActivity.ActivityType.assignToContact,
UIActivity.ActivityType.copyToPasteboard,
UIActivity.ActivityType.mail,
UIActivity.ActivityType.markupAsPDF,
UIActivity.ActivityType.postToFacebook,
@robksawyer
robksawyer / README.md
Created August 29, 2019 12:12 — forked from novascreen/README.md
How to mock next/router in Storybook

If you use Storybook with Next.js and have components using next/link you'll have to mock next/router the same you would for testing with Jest or others. Simply create a file with the mock router as shown below and import it in your Storybook config.

This is based on some information from an issue on Next.js:

vercel/next.js#1827

@robksawyer
robksawyer / signup.jade
Last active November 26, 2022 09:05
A pretty basic registration form for KeystoneJS.
// @file signup.jade
// @path /templates/views/user/signup.jade
// @description Form that user sees when signing up.
//
extends ../../layouts/default
block intro
.container
h1= 'Sign up for Little B.O.M'
@robksawyer
robksawyer / custom_shader_example.js
Created November 18, 2022 11:58 — forked from oskarbraten/custom_shader_example.js
A three.js custom shader example
"use strict";
class MyCustomMaterial extends THREE.ShaderMaterial {
// constructor takes appropriate parameters.
// Default values using object destructuring (ES6)
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring
constructor({
color = 0xffffff,
emissive = 0x000000,
@robksawyer
robksawyer / random.jsx
Created November 16, 2022 16:07
Here's a clever/clean way to randomly position geometry.
function Noodle() {
const { viewport, camera } = useThree()
const { nodes } = useGLTF('/worms-transformed.glb')
const [geometry] = useState(() => nodes[`noodle_${Math.ceil(Math.random() * 4)}`].geometry)
const [speed] = useState(() => 0.1 + Math.random() / 10)
const position = useMemo(() => {
const z = Math.random() * -30
const bounds = viewport.getCurrentViewport(camera, [0, 0, z])
return [THREE.MathUtils.randFloatSpread(bounds.width), THREE.MathUtils.randFloatSpread(bounds.height * 0.75), z]
}, [viewport])
@robksawyer
robksawyer / organicMovement.js
Created August 24, 2020 01:09
React Three Fiber organic movement snippet
// main sphere rotates following the mouse position
useFrame(({ clock, mouse }) => {
main.current.rotation.z = clock.getElapsedTime();
main.current.rotation.y = THREE.MathUtils.lerp(
main.current.rotation.y,
mouse.x * Math.PI,
0.1
);
main.current.rotation.x = THREE.MathUtils.lerp(
main.current.rotation.x,
@robksawyer
robksawyer / useFont.js
Created November 4, 2022 01:01
Simple helper to load a font with React Three Fiber
import { FontLoader } from 'three-stdlib';
import { useLoader } from '@react-three/fiber';
export const useFont = (src) => {
return useLoader(FontLoader, src);
}
@robksawyer
robksawyer / useIsoLayoutEffect.js
Last active September 13, 2022 04:48
A hook for checking the scroll speed with smooth scrollbar.
/**
* @file useIsoLayoutEffect.js
* Hook to suppress useLayoutEffect error on SSR.
*/
import { useLayoutEffect, useEffect } from 'react';
const useIsoLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
import * as THREE from 'three';
(function () {
'use strict';
var root = this;
var has_require = typeof require !== 'undefined';
// var THREE = root.THREE || (has_require && require('three'));
@robksawyer
robksawyer / UnrealBloomPass.js
Created August 24, 2022 15:26
Unreal Bloom Pass with transparency.
import {
AdditiveBlending,
Color,
LinearFilter,
MeshBasicMaterial,
RGBAFormat,
ShaderMaterial,
Texture,
UniformsUtils,
Vector2,