Skip to content

Instantly share code, notes, and snippets.

Avatar

Jukka Tupamäki tukkajukka

View GitHub Profile
@tukkajukka
tukkajukka / heroku-postgres-dump-to-plain.md
Created Jul 10, 2020
How to convert a Heroku Postgres dump to plain text
View heroku-postgres-dump-to-plain.md

How to convert a Heroku Postgres dump to plain text

Sometimes you need to search within backups but don't want to restore the dump to a real database.

Backup files produced by Heroku Postgres are compressed. So they need to be converted to plain text.

  1. Download a backup file and name it e.g. input.dump
  2. Convert input.dump to plain text using pg_restore:
@tukkajukka
tukkajukka / knex-pg-check.md
Last active Apr 14, 2021
How to use check constraints with Knex.js and Postgres
View knex-pg-check.md

How to use check constraints with Knex.js and Postgres

Check constraints are useful for validating INSERT and UPDATE queries. With Knex.js, you have to use raw calls to add or drop constraints.

Add a constraint to check that my_column in my_table is at least 0:

knex.schema.raw(`
  ALTER TABLE
    my_table
  ADD CONSTRAINT
@tukkajukka
tukkajukka / psql-csv-export.md
Created Mar 8, 2020
How to export data to a CSV file in psql CLI (PostgreSQL)
View psql-csv-export.md

Open psql and connect to your database. Use the \copy command to export data from a remote or local database to a local CSV file.

\copy (select id, name from products) to 'my-local-file.csv' csv header
@tukkajukka
tukkajukka / macos-commandline-copy-paste.md
Last active Feb 20, 2020
MacOS command-line copy and paste
View macos-commandline-copy-paste.md

Commands:

  • pbcopy - Copy to clipboard
  • pbpaste - Paste from clipboard

Example: Pipe filenames to clipboard

$ ls -1 | pbcopy 

These commands are useful if copied text should be 100% the same as the output. Selecting and copying text in terminal always has more whitespace than needed or one or two characters are missing. So this is a perfect solution to avoid those.

@tukkajukka
tukkajukka / vscode-react-fragment-fix.md
Last active Feb 19, 2020
Visual Studio Code won't recognize React Fragment syntax
View vscode-react-fragment-fix.md

If <></> triggers a syntax error in Visual Studio Code, try the following:

  1. Switch file's language mode to TypeScript React
  2. Switch file's language mode back to JavaScript React

The error should be gone.

@tukkajukka
tukkajukka / 20190417131115_test-setup.ts
Last active Feb 11, 2021
Knex.js & TypeScript config example · How to setup Knex.js in a TypeScript project
View 20190417131115_test-setup.ts
import * as Knex from 'knex';
export async function up(knex: Knex): Promise<any> {
return knex.schema.createTable('test_setup', (table: Knex.TableBuilder) => {
table.integer('foobar');
});
}
export async function down(knex: Knex): Promise<any> {
return knex.schema.dropTable('test_setup');
@tukkajukka
tukkajukka / package.json
Last active May 16, 2016
An example package.json with Windows specific changes for simple-react-app project
View package.json
{
"name": "react-example-app",
"version": "1.0.0",
"description": "Demonstrates usage of React, React Router and Express.",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"ensure-dirs": "mkdirp frontend\\dist && mkdirp frontend\\dist\\scripts && mkdirp frontend\\dist\\styles && mkdirp frontend\\dist\\assets",
"prewatch": "npm run ensure-dirs && npm run copy-assets && npm run copy-index",