Skip to content

Instantly share code, notes, and snippets.

function isRecord(record): boolean {
// Could be improved, perhaps with use of a Symbol:
return record && record._id && (typeof record._id)=="string"
}
function isSimple(obj): boolean {
return !obj || isRecord(obj) || (typeof obj)!="object"
}
function shallowEqual(objA: any, objB: any): boolean {
@gunn
gunn / useTracker.ts
Last active February 16, 2021 01:08
declare var Package: any
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { useReducer, useState, useEffect, useRef, useMemo, DependencyList } from 'react';
// Warns if data is a Mongo.Cursor or a POJO containing a Mongo.Cursor.
function checkCursor (data: any): void {
let shouldWarn = false;
if (Package.mongo && Package.mongo.Mongo && data && typeof data === 'object') {
if (data instanceof Package.mongo.Mongo.Cursor) {

Keybase proof

I hereby claim:

  • I am gunn on github.
  • I am gunn (https://keybase.io/gunn) on keybase.
  • I have a public key ASDHb63l-bFXGCz9UjrugP7wxXjzTjUVC8NUON-63HNA4wo

To claim this, I am signing this object:

@gunn
gunn / frame.tsx
Last active May 4, 2023 15:47
Render react content in an iframe
import * as React from 'react'
import { createPortal } from 'react-dom'
type FrameProps = React.IframeHTMLAttributes<HTMLIFrameElement> & {
head?: React.ComponentType<any>
children?: React.ReactNode
}
const Frame = React.memo(({head, children, ...iframeProps}: FrameProps)=> {
const node = React.useRef<HTMLIFrameElement>()
const [doc, setDoc] = React.useState<Document>()
@gunn
gunn / inc.rb
Created December 12, 2018 12:17
Implement "i++" style incremention in ruby.
class NumberProxy < BasicObject
def initialize number
@number = number
end
def method_missing *args
@number.send *args
end
def inc!
const camelize = (text, separator="_")=> (
text.split(separator)
.map(w=> w.replace(/./, m=> m.toUpperCase()))
.join()
)
export default class LinkedList {
constructor(value, ...rest) {
this.value = value
if (rest.length) {
this.next = new LinkedList(...rest)
}
}
add(value) {
@gunn
gunn / get-version-details.js
Last active December 12, 2018 12:19
Destructure to array or object
const getVersionDetails = ()=> {
const MAJOR = 1
const MINOR = 2
const PATCH = 6
const array = [MAJOR, MINOR, PATCH]
const object = {MAJOR, MINOR, PATCH}
return Object.assign(array, object)
}
const NUMBERS = "nul one two three four five six seven ocho nine".split(" ")
const isOdd = n=> NUMBERS[n % 10].indexOf("e")!=-1
const isEven = n=> isOdd(n+1)
@gunn
gunn / index.html
Created January 17, 2017 00:32
D3 nest.sortKeys example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nest Test</title>
</head>
<body>
<h3>Sorted?</h3>
<script src="https://d3js.org/d3.v4.min.js"></script>