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 || []);
@trylovetom
trylovetom / parseHTMLTableToJSON.js
Last active October 9, 2024 22:12
Parse HTML Table To JSON With Cheerio.
const text = `<table cellspacing=1 bordercolordark=#666666 cellpadding=0 width=100% align=center bgcolor=#D9D9D9 bordercolorlight=#ffffff border=0><tr class='chinese blue_t2'><td height=20>球队</td><td>球员</td><td>位置</td><td>原因</td><td>日期</td><td>备注</td></tr><tr bgcolor=#FFF0DF align=center><td height=20>波特兰拓荒者</td><td> 纽基</td><td>中锋</td><td>脚部</td><td>2019/03/26</td><td>赛季报销</td></tr><tr bgcolor=#FFF0DF align=center><td height=20>波特兰拓荒者</td><td> 麦高林</td><td>后卫</td><td>膝部</td><td>2019/03/17</td><td>预计缺阵</td></tr><tr bgcolor=#FFF0DF align=center><td height=20>芝加哥公牛</td><td> 赞达拿赫捷臣</td><td>前锋</td><td>膝部</td><td>2019/01/26</td><td>赛季报销</td></tr><tr bgcolor=#FFF0DF align=center><td height=20>芝加哥公牛</td><td> 奥图波达</td><td>前锋</td><td>肩部</td><td>2019/03/26</td><td>预计缺阵</td></tr><tr bgcolor=#FFF0DF align=center><td height=20>芝加哥公牛</td><td> 云度卡达</td><td>中锋</td><td>拇指</td><td>2019/01/16</td><td>预计缺阵</td></tr><tr bgcolor=#FFF0DF align=center><td height=20>芝加哥公牛</td><td> D.华伦天尼</td><td>前锋</td><td>足踝</td><td>2018/10/19</td><td
@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 October 10, 2024 18:27
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