Skip to content

Instantly share code, notes, and snippets.

@hos
hos / firestore-new-id.sql
Created February 11, 2023 05:48
Firestore's newId function implemented in PostgreSQL. Converted using ChatGPT.
create or replace function public.gen_id()
returns text as $$
declare
chars text := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
max_multiple integer := floor(256 / char_length(chars)) * char_length(chars);
i integer;
auto_id text := '';
target_length integer := 20;
bytes bytea;
begin
@hos
hos / copy-firestore-collection.mjs
Created December 20, 2022 15:35
Copy from one firestore collection to another
import admin from "firebase-admin";
import fs from "fs/promises";
const serviceAccount1 = JSON.parse(await fs.readFile("./service-account-1.json"));
const serviceAccount2 = JSON.parse(await fs.readFile("./service-account-2.json"));
const admin1 = admin.initializeApp({ credential: admin.credential.cert(serviceAccount1) }, "one");
const admin2 = admin.initializeApp({ credential: admin.credential.cert(serviceAccount2) }, "two");
const db1 = admin1.firestore();
import Container from 'components/Container';
import Text from 'components/Text';
import Title from 'components/Title';
import { TERMS_PRIVACY } from 'localization/constants';
import { useI18n } from 'localization/helpers';
import { GetServerSideProps } from 'next';
import React, { FC } from 'react';
import FormRow from 'sections/FormRow';
import useStyles from '../screens/terms-privacy-policy/styles';
const ReplaceFieldType: Plugin = (builder) => {
// Process the output fields
builder.hook("GraphQLObjectType:fields:field", (field, build, context) => {
const { getTypeByName, graphql } = build;
const { GraphQLList, GraphQLNonNull } = graphql;
const {
scope: { pgFieldIntrospection: attr },
} = context;
@hos
hos / codes.json
Created April 23, 2021 08:48
Response codes of Ameria Bank REST API. Maybe also can be used for ARCA response codes.
{
"0-1": {
"description": "Processing center response timeout",
"message": "sv_unavailable"
},
"0-100": {
"description": "No payment attempts",
"message": "no_payments_yet"
},
"0-2000": {
import { Plugin } from "graphile-build";
import {
PgAttribute,
PgClass,
PgIntrospectionResultsByKind,
} from "graphile-build-pg";
import {
embed,
gql,
makeExtendSchemaPlugin,
// RECOMMENDED: Disconnect HEROKU from Github before doing this (though not strictly necessary, I think).
//See https://stackoverflow.com/a/61272173/6569950 for more info.
// PARAMETERS
const TOKEN = ""; // MUST BE `repo_deployments` authorized
const REPO = ""; // e.g. "repository"
const USER_OR_ORG = ""; // e.g. "your-name"
// GLOBAL VARS
const URL = `https://api.github.com/repos/${USER_OR_ORG}/${REPO}/deployments`;
@hos
hos / remove-by-node-id-lodash.ts
Last active February 23, 2021 16:22
Postgraphile plugin to remove all mutation containing ByNodeId
import { omitBy } from "lodash";
import { Plugin } from "postgraphile";
export const RemoveByNodeIdPlugin: Plugin = (builder) => {
builder.hook("GraphQLObjectType:fields", (fields, _) => {
return omitBy(fields, (_, key) => key.endsWith?.("ByNodeId"));
});
};
export default RemoveByNodeIdPlugin;
#!/usr/bin/env sh
set -e
export TEST_SQL="select user || ' connection to ' || (select current_database()) || ' ✅'"
### GET CONNECTION DETAILS AND TEST IT
echo "First please provide superuser credentials and endpoint"
@hos
hos / sequelize-to-graphile-migrate.js
Last active January 31, 2020 18:43
Script to create schema.sql from sequelize sync logs. This will only help with getting started there must be some other changes to do manually for using with graphile-migrate.
import fs from 'fs'
export function getLogger (path) {
const stream = fs.createWriteStream(path)
process.on('beforeExit', () => stream.close())
return msg => {
const _ = msg + ''
if (!/ select /i.test(_)) {