Skip to content

Instantly share code, notes, and snippets.

@bnjm
bnjm / array-set-perf.js
Last active December 28, 2022 15:15
Array vs Set lookup benchmark
function bench(cb, arg, label) {
console.time(label)
cb(arg)
console.timeEnd(label)
}
function createArray(length) {
return Array.from({ length }, (_, i) => i)
}
@bnjm
bnjm / useVueComponent.js
Last active June 22, 2019 20:17
Render Vue components in React 🤪
// What: Render a Vue component in React
// How: Returns a wrapped Vue component which can be rendered as a React component
// When to use this? Almost certainly, never
// Example usage: https://codesandbox.io/s/usevuecomponentexample-tmmln
import Vue from 'vue'
import React, { useRef, useEffect, useCallback } from 'react'
const getWrappedVueComponent = component => props => {
const container = useRef()
import Vue from 'vue'
import React, { useRef, useEffect, useCallback } from 'react'
const getWrappedVueComponent = component => props => {
const container = useRef()
const instance = useRef()
useEffect(() => {
instance.current = new Vue({ ...component, el: container.current })
}, [])
useEffect(() => {
(async()=>{
let blob = await new Promise(resolve=>document.querySelector('canvas').toBlob(resolve))
let url = URL.createObjectURL(blob)
window.open(url)
let a = document.createElement('a')
a.href = url
a.download = ''
a.click()
})()
import React, { Component } from 'react'
import { Platform, StyleSheet, Text, View } from 'react-native'
import { ARKit } from 'react-native-arkit'
export default class App extends Component<Props> {
render() {
return (
<View style={{ flex: 1 }}>
<ARKit
style={{ flex: 1 }}
@bnjm
bnjm / ModelWithDownload.js
Last active November 9, 2018 15:50 — forked from macrozone/ModelWithDownload.js
Example how to download a 3dmodel from the internet using react-native-arkit
// @flow
import { ARKit } from 'react-native-arkit'
import { branch, compose, lifecycle, renderComponent } from 'recompose'
import { unzip } from 'react-native-zip-archive'
import RNFetchBlob from 'react-native-fetch-blob'
import React from 'react'
const getModelPath = modelId => (
`${RNFetchBlob.fs.dirs.CacheDir}/models/${modelId}/`
)
@bnjm
bnjm / simplified-furniture-conversion.js
Last active March 29, 2018 15:28
Example of how to convert 3d.io buffer files for SceneKit
const { exec } = require('child_process')
const { promisify } = require('util')
const { furniture, storage, utils } = require('3dio')
const { save, forEachFileInDirectory } from './file'
const run = promisify(exec)
async function getColladaFiles({ query, directory }) {
const redChairs = await furniture.search(query)
@bnjm
bnjm / Furniture3dModel.js
Created February 13, 2018 14:35
Loading a 3d model in React Native Arkit
// @flow
import { ARKit } from 'react-native-arkit'
import { Text, View } from 'react-native'
import { compose, lifecycle, onlyUpdateForKeys } from 'recompose'
import { unzip } from 'react-native-zip-archive'
import RNFetchBlob from 'react-native-fetch-blob'
import React from 'react'
import type { Point3D } from '../../../types'
(function(e){
var n
var a = []
var walk = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null, false)
while (n = walk.nextNode()){
a.push(n)
return a
}
})(document.body).forEach(x => {