Skip to content

Instantly share code, notes, and snippets.

View charisTheo's full-sized avatar
⚛️
Reacting

Harry Theo charisTheo

⚛️
Reacting
View GitHub Profile
@charisTheo
charisTheo / index.js
Last active August 18, 2021 14:46
Node script for fetching Desk ticket messages over time and exporting to CSV
const fetch = require('node-fetch')
const fs = require('fs')
const csvFilePath = "./data.csv"
const API_TOKEN = "<SENDBIRD_API_TOKEN>" // Insert your API token here
const APP_ID = "<SENDBIRD_APP_ID>" // Insert your App ID here
const MESSAGE_LIMIT = 500
const REQUEST_THROTTLING_TIMEOUT = 10000
const dateRanges = [
const EMAIL_PARSE_REGEX = /(?:(?:[^<>()\[\]\\.,;:+\s@"]+(?:\.[^<>()\[\]\\.,;:+\s@"]+)*)|(?:".+"))@(?:(?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/;
const URL_PARSE_REGEX = /(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?/gi;
const convertURLToLink = token => token.match(URL_PARSE_REGEX)
? `<a href='${token}' target="_blank" rel="noreferrer">${token}</a>`
: token;
const convertEmailToLink = token => token.match(EMAIL_PARSE_REGEX) ? `<a href="${`mailto:${token}`}">${token}</a>` : token;
const convertURLsAndEmailsToLinks = message => {
const VideoAnimation = props => {
// ...
useEffect(() => {
const loadLozad = async () => {
const lozad = require('lozad')
const observer = lozad();
observer.observe();
}
loadLozad()
import BaseBlockContent from '@sanity/block-content-to-react'
import React from 'react'
import VideoAnimation from './videoAnimation'
const serializers = {
// marks: { ... },
types: {
block (props) {
// ...
@charisTheo
charisTheo / VideoAnimation.js
Created August 2, 2021 13:50
React component for rendering video animations instead of GIF images
import React, { useEffect } from 'react'
import { getPaddingFromAspectRatio } from '../../lib/helpers';
import { videoAssetFor } from '../../lib/video-url'
const VideoAnimation = ({ webm, fallback, aspectratio, alt, caption }) => {
if (!webm || !fallback) {
return null
}
const webmAsset = videoAssetFor(webm)
const fallbackAsset = videoAssetFor(fallback)
export default {
title: 'Block Content',
name: 'blockContent',
type: 'array',
of: [
{
title: 'Block',
type: 'block',
// ...
},
import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
// import post from './post'
// import postAuthor from './postAuthor'
// ...other imports
import videoAnimation from './videoAnimation'
export default createSchema({
name: 'default',
import React from "react";
import { getFileAsset } from '@sanity/asset-utils';
import { Flex, Spinner } from "@sanity/ui";
const PROJECT_ID = process.env.SANITY_STUDIO_PROJECT_ID;
const DATASET = process.env.SANITY_STUDIO_DATASET;
const VideoPreview = props => {
if (props.isLoading || !props.value.video || !props.value.video.asset) {
return (
@charisTheo
charisTheo / videoAnimation.js
Created August 2, 2021 13:48
Sanity studion video animation schema file
import { MdVideoLibrary } from "react-icons/md";
export default {
name: 'videoAnimation',
title: 'Video animation',
type: 'object',
icon: MdVideoLibrary,
fields: [
{
name: 'webm',
require('dotenv').config({ path: './.env.development' })
console.log('API_KEY: ' + process.env.API_KEY)
module.exports = function() {
// ...
}