Skip to content

Instantly share code, notes, and snippets.

@3200pro
3200pro / component.tsx
Created December 4, 2022 20:42
Solution: Aspect Correct, Mobile responsive React video setup (Using React Player)
<div className="mt-30 w-screen max-w-full">
<VideoModule videoURL={url} />
</div>
@3200pro
3200pro / plan.js
Created November 1, 2022 15:33
Table setup for mobile responsive pricing schema in sanity.io
export default {
name: "plan",
type: "document",
title: "Pricing Plan",
fields: [
{
name: "title",
title: "Title",
type: "string",
},
@3200pro
3200pro / migrate-document-type.js
Created September 16, 2022 21:29
Sanity Client: Migrate Document Type
import client from 'part:@sanity/base/client';
// Run this script with: `sanity exec --with-user-token scripts/migrate-document-type.js`
const OLD_TYPE = 'siteTool';
const NEW_TYPE = 'site.tool';
const fetchDocuments = () =>
client.fetch(
`*[_type == $oldType][0...10] {..., "incomingReferences": *[references(^._id)]{...}}`,
@3200pro
3200pro / filterThenMap.js
Created September 1, 2022 15:59
Filter Array Of Items Based On _ID Containing String & Map
items.filter(item => item._id.indexOf("string") === -1).map((item, i) => {
return(
<>
...
</>
)}
@3200pro
3200pro / array-average.js
Created July 26, 2022 21:22
Calculate the average of an array
const average = (arr) => arr.reduce((a, b) => a + b) / arr.length
@3200pro
3200pro / get-selected-text.js
Created July 26, 2022 21:16
Get selected text on web page
const getSelectedText = () => window.getSelection().toString()
@3200pro
3200pro / randomize-array.js
Created July 26, 2022 21:15
randomly arrange arrays
const shuffle = arr => arr.sort(() => Math.random() > 0.5)
@3200pro
3200pro / insert-html-string-after.js
Created July 26, 2022 21:15
Insert HTML string after element
const insertHTMLAfter = (html, el) => el.insertAdjacentHTML('afterend', html)
@3200pro
3200pro / touch-support.js
Created July 26, 2022 21:14
Check for touch support on your device
const touchSupported = () => ('ontouchstart' in window || DocumentTouch && document instanceof DocumentTouch)
@3200pro
3200pro / dates-difference-in-days.js
Created July 26, 2022 21:12
Get the daily difference between two dates
const daysBetween = (date1, date2) => Math.ceil(Math.abs(date1 - date2) / (1000 * 60 * 60 * 24))