Skip to content

Instantly share code, notes, and snippets.

View CodeWitchBella's full-sized avatar

Isabella Skořepová CodeWitchBella

View GitHub Profile
@CodeWitchBella
CodeWitchBella / Readme.md
Last active July 30, 2023 21:04
Migrating prisma data from sqlite to postgres

This was quiet an ordeal, but a combination of preexisting tools and a few lines of custom scripting made it possible.

I really benefitted from having a script to create whole database from scratch, heavily recommended. That part is inspired by: https://mgdm.net/weblog/postgresql-in-a-nix-shell/

What you need: postgres server, psql, pg_dump (all of those come standard with postgres installation) and pgloader. The postgresql starting script is written for nodejs but you could easily replace it...

The basic process is as follows

  1. load the data from sqlite to postgres as is
  2. fix any incompatibilities that'd break step 5
@CodeWitchBella
CodeWitchBella / jpeg-parser.ts
Created September 5, 2022 20:10
Minimal JFIF parser. Note that it does not work for all types of JPEG
// if in browser, just use https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap
// you probably have to read the pixel data at some point anyway...
function parseImageMeta(image: Uint8Array) {
// https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format
if (jfif.every((value, index) => value < 0 || image[index] === value)) {
const view = new DataView(image.buffer)
let offset = 2
while (true) {
@CodeWitchBella
CodeWitchBella / find-react-factories.js
Last active February 9, 2022 17:14
simple regex-based script to find factory usages
const fs = require('fs')
const path = require('path')
let files = 0
let lines = 0
function rd(dir) {
for (const dirent of fs.readdirSync(dir, { withFileTypes: true })) {
const fname = path.join(dir, dirent.name)
if (dirent.isDirectory()) {
rd(fname)
// files was created by running
// grep -R createFactory modules > files
const fs = require('fs')
const files = Array.from(
new Set(
fs
.readFileSync('files', 'utf-8')
.trim()
.split('\n')
@CodeWitchBella
CodeWitchBella / create-element-to-jsx.js
Last active February 7, 2022 17:30
Patched create-element-to-jsx
/**
* Copyright 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
@CodeWitchBella
CodeWitchBella / json-html.js
Created September 4, 2020 18:38
JSON html viewer
/**
* @return {string}
*/
export function jsonHtml(json) {
let indentSize = 0
function indent() {
return `<span style="font-size: 0px; position: absolute;">${' '.repeat(
indentSize,
)}</span>`
}
@CodeWitchBella
CodeWitchBella / README.md
Last active July 26, 2021 10:21
Match Path