Skip to content

Instantly share code, notes, and snippets.

@HugeLetters
HugeLetters / example.ts
Created April 8, 2024 14:59
Drizzle ORM SQLite Trigger migrations
// has to be exported - triggers should be stored in the same folder as table schemas
export const insertTrigger = new Trigger({
name: "update_product_meta_on_new_review",
type: "INSERT",
on: review,
when: ({ newRow }) => eq(newRow.isPrivate, false),
do: ({ newRow }) =>
db
.insert(productMeta)
.values({
@alexanderson1993
alexanderson1993 / createR2UploadHandler.ts
Created April 5, 2024 15:22
A Remix upload handler for R2 buckets
import type { UploadHandlerPart } from "@remix-run/cloudflare";
export class MaxPartSizeExceededError extends Error {
constructor(public field: string, public maxBytes: number) {
super(`Field "${field}" exceeded upload size of ${maxBytes} bytes.`);
}
}
export function createR2UploadHandler({
bucket,
import type { V2_HtmlMetaDescriptor, V2_MetaFunction } from "@remix-run/node";
export const mergeMeta = (
overrideFn: V2_MetaFunction,
appendFn?: V2_MetaFunction,
): V2_MetaFunction => {
return arg => {
// get meta from parent routes
let mergedMeta = arg.matches.reduce((acc, match) => {
return acc.concat(match.meta || []);
@karantza
karantza / DraggableMarker.js
Created June 27, 2018 23:01
Draggable Marker Example
import React from "react";
import PropTypes from "prop-types";
import * as MapboxGl from "mapbox-gl";
export default class DraggableMarker extends React.Component {
marker = null;
componentDidMount() {
const { map } = this.context;
@ahtcx
ahtcx / deep-merge.js
Last active June 9, 2024 14:56
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}
@guilherme
guilherme / gist:9604324
Last active July 23, 2024 08:28
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console.log'
# CHECK
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0
then