Skip to content

Instantly share code, notes, and snippets.

Avatar
🌱

Ash juice49

🌱
View GitHub Profile
@juice49
juice49 / create-permission-resources-for-update-only-role.ts
Last active Mar 17, 2022
Sanity Update-Only Role Creation Scripts
View create-permission-resources-for-update-only-role.ts
import getIt from 'get-it'
import base from 'get-it/lib/middleware/base'
import jsonRequest from 'get-it/lib/middleware/jsonRequest'
import jsonResponse from 'get-it/lib/middleware/jsonResponse'
import promise from 'get-it/lib/middleware/promise'
import headers from 'get-it/lib/middleware/headers'
import httpErrors from 'get-it/lib/middleware/httpErrors'
const API_VERSION = 'v2021-10-04'
const PROJECT_ID = 'xxxxxxxx'
@juice49
juice49 / stitches-create-scale-variant.tsx
Created Oct 19, 2021
Stitches Create Scale Variant
View stitches-create-scale-variant.tsx
import { CSS } from '@stitches/react'
import { theme } from './stitches.config'
function createScaleVariant<Scale extends string & keyof typeof theme>(
property: string,
scale: Scale,
): Record<keyof typeof theme[Scale], CSS> {
return Object.keys(theme.space).reduce(
(reduced, value) => ({
...reduced,
View next-plain-image.tsx
import React from 'react'
import {
ImageConfig,
imageConfigDefault,
LoaderValue,
VALID_LOADERS,
} from 'next/dist/server/image-config'
if (typeof window === 'undefined') {
View use-lazy-module.js
// Sadly a full dynamic import is not compatible
// with webpack's `import()`.
import { useState } from 'react'
const useLazyModule = path => {
const [ module, setModule ] = useState()
;(async () => {
const module = await import(path)
@juice49
juice49 / index.js
Created Jun 6, 2019
Fluent calculator
View index.js
class Calculator {
constructor (value = 0) {
this.value = value
}
add (value = 0) {
this.value += value
return this
}
@juice49
juice49 / index.js
Created May 10, 2019
Fluid values mixin for CSS-in-JS
View index.js
const fluid = (properties, [ minVw, maxVw ], [ minVal, maxVal ]) => properties
.map(property => `
${property}: ${minVal};
@media (min-width: ${minVw}) {
${property}: calc(${minVal} + ${parseFloat(maxVal) - parseFloat(minVal)} * (100vw - ${minVw}) / ${parseFloat(maxVw) - parseFloat(minVw)});
}
@media (min-width: ${maxVw}) {
${property}: ${maxVal};
View sql-fns.js
/* sql-tag
mysql2
minigrate */
// from redux
function compose(...funcs) {
if (funcs.length === 0) {
return arg => arg
}
View IterableUtils.php
<?php
abstract class IterableUtils
{
public static function reduce(Iterable $collection, Callable $accumulator, $result = null)
{
foreach ($collection as $item) {
$result = $accumulator($result, $item);
}
@juice49
juice49 / index.js
Last active Jun 14, 2018
React auto render
View index.js
import React from 'react'
import { render } from 'react-dom'
import Foo from './components/foo'
const components = {
foo: Foo
}
Object.keys(components)
.map(name => {
View promise-once-sort-of.js
function promiseOnce () {
let promise = null
return function (createPromise) {
if (promise) {
return promise
}
promise = createPromise()