Skip to content

Instantly share code, notes, and snippets.

View bjoerge's full-sized avatar

Bjørge Næss bjoerge

View GitHub Profile
@bjoerge
bjoerge / replayer.js
Created March 16, 2016 16:20
Emit values of an array over time
export default function replayer(array, opts = {}, emit) {
let idx = 0
let timer
return {
start: next,
stop: stop,
reset: reset
}
[
{
"op": "replace",
"path": [
"nodes",
"0",
"nodes",
"0",
"characters",
"8",
@bjoerge
bjoerge / .gitignore
Last active March 14, 2017 12:07
gen-hotspot-styles
node_modules
@bjoerge
bjoerge / package.json
Last active September 13, 2017 07:29
npx test
{
"name": "gist-test",
"version": "0.0.0",
"bin": "./run.js"
}
@bjoerge
bjoerge / treeify.js
Created September 27, 2017 13:34
treeify
const assert = require('assert')
// takes a flat structure like this
const input = [
{
level: 1,
title: '1'
},
{
level: 1,
@bjoerge
bjoerge / stateContainer.js
Last active April 9, 2018 12:46
stateContainer.js
import {Subject} from 'rx/Subject'
import {of} from 'rx/observable/of'
import {publishReplay, refCount, concat} from 'rxjs/observable'
function createState(initial) {
const onChange$ = new Subject()
function onChange(...args) {
onChange$.next(args)
}
@bjoerge
bjoerge / translate.js
Last active April 21, 2021 23:01
Translate all locale strings with missing translations in a Sanity dataset - https://sanity.io
/* eslint-disable no-console */
import client from 'part:@sanity/base/client'
import reduce from 'json-reduce'
// see https://github.com/sanity-io/sanity/blob/next/packages/example-studio/schemas/languages.js for an example
import {SUPPORTED_LANGUAGES} from '../schemas/languages'
import Translate from '@google-cloud/translate'
const translateAPI = new Translate({
@bjoerge
bjoerge / .babelrc
Last active June 11, 2018 10:59
multiplex-ws
{
"presets": [
[
"env",
{
"targets": {
"node": "6",
"chrome": "59",
"safari": "10",
"firefox": "56",
@bjoerge
bjoerge / default-slug.js
Created June 25, 2018 10:53
Generate default slug w/listener
const {deburr, kebabCase} = require('lodash')
const sanityClient = require('@sanity/client')
const client = sanityClient({
projectId: '<your priojectId>',
dataset: '<your dataset>',
token: '<your auth token>',
useCdn: false
})
@bjoerge
bjoerge / ExternalDataInput.js
Created December 21, 2018 12:46
Example of a custom sanity input that allows the user to select from a list of values retrieved from an external API
import React from 'react'
import SearchableSelect from 'part:@sanity/components/selects/searchable'
import FormField from 'part:@sanity/components/formfields/default'
import {PatchEvent, set, unset} from 'part:@sanity/form-builder/patch-event'
const STREET_NAMES = [
'Thorvald Meyers gate',
'Champs-Élysées',
'Lombard Street',
'Abbey Road',