Skip to content

Instantly share code, notes, and snippets.

@fnimick
fnimick / supabase_profile_sync.sql
Last active April 25, 2024 11:35
Create a `public.profile` table and keep it in sync with supabase `auth.users` for selected fields in both directions.
/**
* USERS
* Note: This table contains user data. Users should only be able to view and update their own data.
* Some data is synced back and forth to `auth.users` as described below.
*
* `full_name`: synced in both directions
* `email`: synced from user metadata to profile only
* `avatar_url`: synced from user metadata to profile only
* `terms_accepted_at`: synced from profile to user metadata only
*/
type ChurchInput<T> = (t: T) => T;
type ChurchNumeral<T> = (fn: ChurchInput<T>) => (t: T) => T;
function churchToInt(c: ChurchNumeral<number>) {
return c((x: number) => x + 1)(0);
}
function ZERO<T>(f: any) {
return (x: T) => x;
}
@fnimick
fnimick / README.md
Last active April 15, 2022 22:00 — forked from itsMapleLeaf/README.md
Typed remix helpers

Typed helpers for low-boilerplate type inference with Remix data.

  • I suffix them with *Typed so I don't accidentally import the core remix helpers.
  • This doesn't support regular Response objects to prevent accidentally using them with the typed helpers.
@fnimick
fnimick / sequelize+5.21.12.patch
Created June 9, 2020 14:31
Sequelize patch to enable unique indices (including partial indices) for ON CONFLICT DO UPDATE with postgres or sqlite
diff --git a/node_modules/sequelize/lib/dialects/abstract/query-generator.js b/node_modules/sequelize/lib/dialects/abstract/query-generator.js
index d2c865d..b668f38 100755
--- a/node_modules/sequelize/lib/dialects/abstract/query-generator.js
+++ b/node_modules/sequelize/lib/dialects/abstract/query-generator.js
@@ -302,9 +302,16 @@ class QueryGenerator {
if (this._dialect.supports.inserts.updateOnDuplicate && options.updateOnDuplicate) {
if (this._dialect.supports.inserts.updateOnDuplicate == ' ON CONFLICT DO UPDATE SET') { // postgres / sqlite
// If no conflict target columns were specified, use the primary key names from options.upsertKeys
- const conflictKeys = options.upsertKeys.map(attr => this.quoteIdentifier(attr));
const updateKeys = options.updateOnDuplicate.map(attr => `${this.quoteIdentifier(attr)}=EXCLUDED.${this.quoteIdentifier(attr)}`);
@fnimick
fnimick / sequelize+5.21.1.patch
Created October 25, 2019 14:38
Sequelize patch to enable unique indices (including partial indices) for ON CONFLICT DO UPDATE with postgres
diff --git a/node_modules/sequelize/lib/dialects/abstract/query-generator.js b/node_modules/sequelize/lib/dialects/abstract/query-generator.js
index d2c865d..b668f38 100755
--- a/node_modules/sequelize/lib/dialects/abstract/query-generator.js
+++ b/node_modules/sequelize/lib/dialects/abstract/query-generator.js
@@ -302,9 +302,16 @@ class QueryGenerator {
if (this._dialect.supports.inserts.updateOnDuplicate && options.updateOnDuplicate) {
if (this._dialect.supports.inserts.updateOnDuplicate == ' ON CONFLICT DO UPDATE SET') { // postgres / sqlite
// If no conflict target columns were specified, use the primary key names from options.upsertKeys
- const conflictKeys = options.upsertKeys.map(attr => this.quoteIdentifier(attr));
const updateKeys = options.updateOnDuplicate.map(attr => `${this.quoteIdentifier(attr)}=EXCLUDED.${this.quoteIdentifier(attr)}`);

Keybase proof

I hereby claim:

  • I am fnimick on github.
  • I am fnimick (https://keybase.io/fnimick) on keybase.
  • I have a public key whose fingerprint is 5BF1 FE7A 40A1 48D2 6BD4 0CEB 7F0E 5BFE F211 F09D

To claim this, I am signing this object:

@fnimick
fnimick / church.java
Last active July 7, 2016 15:31
Church encodings implemented in Java 8. Includes natural numbers and arithmetic, booleans, conditionals, recursion, and a demonstration using the factorial function.
package church;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import org.junit.Test;
public class church {
@fnimick
fnimick / church.js
Last active February 7, 2020 01:29
Church encodings in Javascript. Natural numbers and arithmetic, booleans, conditionals, recursion, and a demonstration using the factorial function.
#!/usr/bin/env node
'use strict'
let churchToInt = c => c(x => x + 1)(0)
let ZERO = f => x => x
let ONE = f => x => f(x)
let TWO = f => x => f(f(x))
let increment = n => f => x => f(n(f)(x))
let THREE = increment(TWO)