Skip to content

Instantly share code, notes, and snippets.

@tantaman
tantaman / Board_index.tsx.diff
Last active November 30, 2023 15:02
live-store vs vulcan linearite
diff --git a/livestore/livestore/examples/linearlite/src/pages/Board/index.tsx b/vulcan/linearite/src/pages/Board/Index.tsx
index a8960c0..6ed7689 100644
--- a/livestore/livestore/examples/linearlite/src/pages/Board/index.tsx
+++ b/vulcan/linearite/src/pages/Board/Index.tsx
@@ -1,24 +1,14 @@
import TopFilter from '../../components/TopFilter'
import IssueBoard from './IssueBoard'
-// import { useFilterState } from '../../utils/filterState'
-import { Issue } from '../../types'
-import { querySQL, sql } from '@livestore/livestore'
// Automatically-generated file
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_parens)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(non_camel_case_types)]

Schema

Example of a storage agnostic schema layer that can drive queries, graphql, privacy, mutations and other concerns. We'll call it Ent (short for entity).

A Facebook team from Tel Aviv did open-source an Ent framework for Go. It is heavily inspired by the framework used by the rest of the company except that EntGo:

  1. Only supports Go as a target language
  2. Only supports SQL and Gremlin as backends
  3. Schema definitions are written in Go rather than a DSL or something like Yaml.

I never got around to asking them why they didn't use the existing framework.

@tantaman
tantaman / sid.md
Last active March 4, 2021 20:15
Generate short uuids in the browser

UUIDs are nice in that they're globally unique. They have problems when it comes to storage (take up > 64 bits) and performance (id space is random, leading to poor usage of B-trees).

See performance analysis here: https://www.percona.com/blog/2019/11/22/uuids-are-popular-but-bad-for-performance-lets-discuss/

We can, however, generate UUIDs that fit into the unsigned 64 bit integer space and are prefixed by timestamp to keep queries on recent data performant.

Below is a method to generate short UUIDs in the browser.

Keybase proof

I hereby claim:

  • I am tantaman on github.
  • I am tantaman (https://keybase.io/tantaman) on keybase.
  • I have a public key ASDn8NSdwQYapDu2-gTplHTnWRDWMK7J4mvKrBMCo1cy6Ao

To claim this, I am signing this object:

@tantaman
tantaman / Policy.md
Last active February 22, 2020 16:54
Using Intersection and Union types to add policy awareness to code

Problem

With the advent of regulation, app development has gotten an order of magnitude more complicated. Every time we interact with a user we have to check that we're not violating any agreements (email opt out, cookie opt out, only using their phone number for 2fac, etc) made with that user. In addition, functions that used to apply to all users now have restrictions inside of them, causing them to only apply to certain users.

Example

Take sending an email to a user as an example. In the infancy of your app it may have been ok to email all of your users but as you grew you needed to give users a way to opt out of emails. The simplest approach here is to add a line in the email out code that checks if the user is allowed to receive emails.

function sendEmailTo(user) {
  if (!canReceiveEmails(user)) {
    return;
@tantaman
tantaman / gist:10798202
Last active August 29, 2015 13:59
Rx Observable that doesn't start publishing until it has a subscriber. Observers that subscribe after the first subscriber only see items that are emitted after they have subscribed.
public class Temp {
public static final ScheduledExecutorService s = Executors.newScheduledThreadPool(1);
public static void main(String[] args) throws InterruptedException {
final ConnectableObservable<Long> source = Observable.create(new OnSubscribe<Long>() {
@Override
public void call(final Subscriber<? super Long> t1) {
final AtomicInteger n = new AtomicInteger(0);
s.scheduleAtFixedRate(new Runnable() {
@tantaman
tantaman / yeoman-notes.md
Last active January 1, 2016 17:09
Yeoman notes

Yeoman generators stink

They are not composable. If I use yo webapp and make some progress, I can't later do yo angular or yo requirejs

This also leads to a bunch of out of date generators. If the "yeoman style" changes I can't be certain that all the generators that are out there have updated as well.

Generators should be additive. yo angular should depend on yo webapp, for example. This way when updates are made to the webapp generator then the angular generator (or any generator that builds on webapp) will also get them.

@tantaman
tantaman / polymer-requirejs
Last active April 5, 2018 07:29
polymer + requirejs : originally by Scott Miles from: http://jsbin.com/efojap/2/edit
<!doctype html>
<html>
<head>
<title>Polymer and RequireJS</title>
<script src="http://polymer.github.io/cdn/polymer.min.js"></script>
</head>
<body>
<!-- #foo -->
<div id="foo">the foo has no joy.</div>
@tantaman
tantaman / IndexedDB-storing-and-retrieving-files.js
Last active April 4, 2021 22:10 — forked from robnyman/IndexedDB-storing-and-retrieving-files.js
Download an image, save it to IndexedDB, read it out, display the image via createObjectURL - works in Chrome and Firefox. Based on https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/ but with fixes made for Chrome.
(function () {
// IndexedDB
function BrowserType() {
var n = navigator.appName;
var ua = navigator.userAgent;
var tem;
var m = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
if (m && (tem = ua.match(/version\/([\.\d]+)/i)) != null) m[2] = tem[1];
m = m ? [m[1], m[2]] : [n, navigator.appVersion, '-?'];