Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Sardo frankiesardo

View GitHub Profile
View gist:3e9820a0f2854035c03e271d10ab5ba3
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
@frankiesardo
frankiesardo / deps.edn
Last active Feb 23, 2021 — forked from athos/deps.edn
Try `clojure -Sdeps '{:deps {hello-clojure {:git/url "https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202" :sha "1c9a05106171f97f9b8e8ac8f58c7bd8dbe021f9"}}}' -m hello-clojure` on your terminal
View deps.edn
{:paths ["."]
:deps {clansi {:mvn/version "1.0.0"}}}
View firebase.rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /rooms/{roomId} {
allow get
allow create: if
request.resource.data.keys().hasOnly(['hostId', 'timestamp']) &&
request.resource.data.hostId == request.auth.uid &&
request.resource.data.timestamp == request.time
View useReconciler.cljs
(defn useReconciler [reconciler effect-handler initial-state]
(let [[state&effects set-state] (react/useState {:state initial-state})
[state effects] ((juxt get dissoc) state&effects :state)
dispatch (uix/callback
(fn [action] (set-state (fn [{:keys [state]}] (merge {:state state} (reconciler state action)))))
[reconciler])]
(uix/effect!
(fn []
(when-not (empty? effects)
(doseq [effect effects :let [[type payload] effect]]
@frankiesardo
frankiesardo / index.test.js
Created Sep 19, 2020
Evenly interleave two arrays
View index.test.js
Array.prototype.chunk = function (groupsize) {
var sets = [];
var chunks = this.length / groupsize;
for (var i = 0, j = 0; i < chunks; i++, j += groupsize) {
sets[i] = this.slice(j, j + groupsize);
}
return sets;
};
var interleave = (a1, a2) => {
View App.js
import React from 'react';
import './App.css';
const actionType = {
SHOW: "show",
HIDE: "hide"
}
function reducer(state, action) {
@frankiesardo
frankiesardo / ColocatingEffectsAndReducers.js
Last active Jul 28, 2020
Colocating effects and reducers
View ColocatingEffectsAndReducers.js
// This is an example on how to use the library
import React from 'react';
// This is the hook
function useReducerWithEffects(reducer, handlers, initialState) {
const [{ state, ...effects }, setState] = React.useState({ state: initialState })
const dispatch = React.useCallback(action => setState(({ state }) => ({ state, ...reducer(state, action) })), [reducer])
React.useEffect(function () {
View reducer-context.core.cljs
(ns reducer-context.core
(:require ["react" :as react :rename {createElement $}]
["react-dom" :as dom]
[goog.object :as obj]))
(extend-type object
ILookup
(-lookup
([o k] (obj/get o (name k)))
([o k not-found] (obj/get o (name k) not-found))))
View wrapper.cljc
(ns react.wrapper
#?(:cljs (:require ["react" :as react]
[goog.object :as obj])))
#?(:cljs
(defn component [display-name render]
(let [f (fn [props] (apply render (obj/get props "value")))
m (react/memo f #(= (obj/get %1 "value") (obj/get %2 "value")))]
(obj/set f "displayName" display-name)
View effective-reducer.cljs
(ns example.app
(:require
["expo" :as ex]
["react-native" :as rn]
["react" :as react :rename {createElement $}]
[shadow.expo :as expo]))
(defn useEffectiveReducer [reducer handlers initial-state]
(let [[state set-state] (react/useState initial-state)
[queue update-queue] (react/useReducer (fn [state action] (action state)) [])