Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
joshdholtz / ATinySampleApp.swift
Last active March 29, 2024 23:27
Super basic SwiftUI app (70 lines of code) with paywall using RevenueCat
import SwiftUI
import RevenueCat
struct Constants {
static let apiKey = "<your_api_key>" // Will look like: appl_bunchofotherstuffhere
static let entitlementName = "<your_entitlement_name>" // I use something like "pro"
}
@main
struct ATinySampleApp: App {
@bramses
bramses / contact.js
Last active May 19, 2024 23:40
Create a Contact Form in NextJS/Vercel
// frontend - react
import { useState } from "react";
import Alert from "@reach/alert";
export default function Contact() {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [message, setMessage] = useState("");
const [messageSent, setMessageSent] = useState(false);
@BrunoQuaresma
BrunoQuaresma / nextapimock.ts
Last active July 18, 2023 17:12
NextApiResponse and NextApiRequest mocks
import { IncomingMessage } from 'http'
import {
NextApiRequestCookies,
NextApiRequestQuery,
} from 'next/dist/next-server/server/api-utils'
import { Socket } from 'net'
import { ServerResponse } from 'http'
import { NextApiRequest, NextApiResponse } from 'next'
import { Env } from 'next/dist/lib/load-env-config'
@fortwo
fortwo / groupByMultipleKeys.js
Last active November 26, 2020 21:10
Based on the very well written https://gist.github.com/robmathers/1830ce09695f759bf2c4df15c29dd22d, this is a groupBy method that supports multiple keys.
const groupBy = (data, keys) => { // `data` is an array of objects, `keys` is the array of keys (or property accessor) to group by
// reduce runs this anonymous function on each element of `data` (the `item` parameter,
// returning the `storage` parameter at the end
return data.reduce((storage, item) => {
// returns an object containing keys and values of each item
const groupValues = keys.reduce((values, key) => {
values[key] = item[key];
return values;
}, {});
@romansorin
romansorin / .storybook
Created November 10, 2019 00:52
Gatsby, TailwindCSS, Storybook configuration
- addons.js
- config.js
- webpack.config.js
@nateberkopec
nateberkopec / correction.md
Last active February 14, 2024 16:22
A Simple Correction

In yesterday's post I said, in relation to "how does .present? work on ActiveRecord::Relation", I said that present? performs an existence check SELECT 1 AS one FROM ... LIMIT 1 because it calls exists? underneath. This is actually wrong - it loads the relation.

Jonathan Mast corrected me on Twitter. It turns out, I should have paid closer attention! Here is the actual implementation of blank? on ActiveRecord::Relation on Rails master:

# Returns true if relation is blank.
def blank?
  records.blank?
end
@cameronblandford
cameronblandford / knexPostgresFullTextSearch.js
Last active November 8, 2023 07:35
Implement full text search using Knex + Objection
// Because we're using an ORM (Objection), it's a pain to add a tsvector when inserting,
// since tsvectors and FTS aren't supported by Objection. Instead, I've added a hook that
// fires on insert which auto-generates the tsvector field for each newly inserted entry.
// This is an example knex migration file for said behavior.
const addUserIndex = `
ALTER TABLE public.user ADD "document" tsvector;
CREATE FUNCTION my_trigger_function()
RETURNS trigger AS $$
@nitinhayaran
nitinhayaran / restore.md
Created December 22, 2017 14:00
How to restore specific tables on heroku from backup

How to restore specific tables on heroku from backup

  1. Create a new database instance attached to current application
  2. Restore latest database backup on newly created database
  3. Get the connection url of this backup database. Use this URL in later sql queries.
  4. Connect to database where we have incorrect data
heroku pg:psql --app ck-api-prod
  1. On postgres prompt run following queries. This will create copy table from data in backup database.