Skip to content

Instantly share code, notes, and snippets.

// Created by gil_birman on 11/22/19.
import Combine
import FirebaseFirestore
import FirebaseStorage
import Foundation
enum FirebaseCombineError: Error {
case encodeImageFailed
case nilResultError
class ImageUtils {
static func copiedImage(_ image: UIImage) -> UIImage? {
UIGraphicsBeginImageContext(image.size)
image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
guard let copy = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
UIGraphicsEndImageContext()
return copy
}
}
Verifying my Blockstack ID is secured with the address 1HUSxH3NLAtpGWFqKKZJSLCeNQTWSB7aL6 https://explorer.blockstack.org/address/1HUSxH3NLAtpGWFqKKZJSLCeNQTWSB7aL6
@gilbox
gilbox / cache-map.js
Last active October 18, 2015 21:17
cacheMap
// cache an immutable list
// Ie: if an item changes, it's cacheKey *must* change as well
const cache = {};
function cacheMap(objectKey, mapFn) {
const objectCache = cache[objectKey] || {};
const nextObjectCache = cache[objectKey] = {};
return this.map(item =>
nextObjectCache[item.cacheKey] =
objectCache[item.cacheKey] || mapFn(item)
@gilbox
gilbox / spinning-cube.js
Last active October 18, 2015 19:16
three.js spinning cube
const renderer = new THREE.WebGLRenderer( {canvas: document.getElementById('canvas')} );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.autoClear = false;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
@gilbox
gilbox / react-scroll-animation-idea.js
Last active August 29, 2015 14:27
Idea for functional react scroll-based animation
const identity = x => x;
const topTop = containerRect => rect =>
~~(rect.top - containerRect.top);
const translate3dFormatter = value => `translate3d(${value.join('px,')}px)`;
const translate3d = (...args) => ({
value: args,
formatter: translate3dFormatter,
factory: translate3d
})
@gilbox
gilbox / classy-react-phone-input-demo.js
Created June 30, 2015 05:19
Classy React: Phone Input Demo
const React = require('react');
const {Component} = React;
const {elegant, subedit} = require('elegant-react/classy')({debug: true});
const {fromJS} = require('immutable');
const initialState = fromJS({
phone: '6665552222'
});
const parsePhone = v => v.replace(/\D/g, '').substr(0,10);
@gilbox
gilbox / classy-react-elegant-decorator.js
Last active August 29, 2015 14:23
Classy React: elegant decorator
import {shouldComponentUpdate} from '../component-render-mixin';
import {componentWillMount, componentWillReceiveProps} from '../statics-mixin';
function elegant(DecoratedComponent) {
return class ElegantDecorator extends React.Component {
static displayName = `Elegant(${getDisplayName(DecoratedComponent)})`;
static DecoratedComponent = DecoratedComponent;
shouldComponentUpdate(nextProps, nextState) {
return shouldComponentUpdate.call(this, nextProps, nextState);
@gilbox
gilbox / functional-react-component-function.js
Created June 30, 2015 04:56
Functional React: component function
// @param additionalMixins? {Array|Object}
// @param renderFn {Function}
// @returns Component
function component(additionalMixins, renderFn) {
renderFn = renderFn || additionalMixins;
additionalMixins = (additionalMixins instanceof Function) ? [] : [].concat(additionalMixins);
const mixins = [ComponentRenderMixin,
staticFunctionsMixin]
.concat(additionalMixins);
@gilbox
gilbox / classy-react-creating-a-component.js
Created June 30, 2015 04:48
Classy Functional React: Creating a Component
@elegant
class Hello extends Component {
render() {
const {name} = this.props;
return <div>Hello, {name}!</div>
}
}