Skip to content

Instantly share code, notes, and snippets.

View bitlather's full-sized avatar

Jun Reiderdai bitlather

View GitHub Profile
@bitlather
bitlather / postgresql_insert_or_select.sql
Last active October 20, 2017 20:11
PostgreSQL function that inserts only if does not exist and returns row id.
-- PostgreSQL 9.3.14 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit
CREATE TABLE func_table (
id serial NOT NULL PRIMARY KEY,
value integer NOT NULL
);
--
-- Make column unique.
--
ALTER TABLE func_table ADD CONSTRAINT unique_value UNIQUE (value);
-- PostgreSQL 9.3.14 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit
-- ============================================================================
-- Returns the comments for all functions we'll create.
--
-- Precondition:
--
-- Assumes you are currently using a database.
--
-- Usage:
--
-- PostgreSQL 9.3.14 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit
-- ============================================================================
-- Create a view to easily read table comments.
--
-- Returns:
--
-- A list of table names and comments associated with them.
--
-- Usage:
--
-- PostgreSQL 9.3.14 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit
-- ============================================================================
-- Returns the comments for all columns in a table.
--
-- Precondition:
--
-- Assumes you are currently using a database.
--
-- Usage:
--
PostgreSQL 9.3.14 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit
sudo su - postgres
Run 'psql' to connect, or 'psql -E' to connect and show psql queries.
Commands:
\l | List databases
\connect db_name | Use db_name database
\dt | List tables
\dv | List views
public class Lambda { // requires >= java 1.8
interface IntegerMath {
int operation(int a, int b);
default IntegerMath swap() {
return (a, b) -> operation(b, a);
}
}
@bitlather
bitlather / create-react-app Ubuntu fix.txt
Created July 31, 2018 01:58
facebook/create-react-app - Fix for can't create app on Ubuntu
https://stackoverflow.com/questions/22475849/node-js-error-enospc#32600959
```
$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
$ sudo sysctl --system # Not sure if this is necessary
```
Source: https://github.com/facebook/create-react-app/issues/2549
@bitlather
bitlather / Symlink Tutorial.md
Created May 2, 2019 19:27
Tutorial for how to use symlinks
$ gem uninstall bundler
$ gem install bundler --version '1.3.6'