This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Useful celery config. | |
app = Celery('tasks', | |
broker='redis://localhost:6379', | |
backend='redis://localhost:6379') | |
app.conf.update( | |
CELERY_TASK_RESULT_EXPIRES=3600, | |
CELERY_QUEUES=( | |
Queue('default', routing_key='tasks.#'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git rm --cache /path/to/file | |
git commit -am "Remove file" | |
git push | |
#### | |
# remove a mistakenly committed file named 'queries.sql' | |
git reset HEAD queries.sql | |
git rm --cached queries.sql | |
# make a new branch and commit data to it | |
git status && git checkout -b branch-name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS accumulates ( | |
added_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, | |
added_by BIGINT NOT NULL, | |
id BIGSERIAL NOT NULL, | |
enabled BOOLEAN NOT NULL, | |
user_id BIGINT NOT NULL, | |
transaction BIGINT NOT NULL, | |
tablemeta JSONB NOT NULL, | |
CONSTRAINT pk_accumulates PRIMARY KEY (id) | |
--, CONSTRAINT fk_accumulates_user_id_users FOREIGN KEY(user_id) REFERENCES users (id) ON UPDATE CASCADE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- create the needed sequence | |
CREATE SEQUENCE table_id_seq; | |
-- change the public to schema of choice | |
CREATE OR REPLACE FUNCTION public.next_id(OUT result bigint) AS $$ | |
DECLARE | |
our_epoch bigint := 1314220021721; | |
seq_id bigint; | |
now_millis bigint; | |
shard_id int := 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN; | |
DROP TRIGGER IF EXISTS accumulate_ait | |
on accumulate; | |
DROP FUNCTION IF EXISTS adapt_to_service(); | |
DROP TABLE IF EXISTS accumulate CASCADE; | |
CREATE TABLE IF NOT EXISTS accumulate ( | |
id bigint NOT NULL, | |
monies bigint, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.list_public_tables() | |
RETURNS TABLE(name character varying) | |
LANGUAGE plpgsql | |
AS $function$ | |
BEGIN | |
FOR name IN SELECT quote_ident(table_name) FROM information_schema.tables WHERE table_schema = 'public' LOOP | |
RETURN NEXT; | |
END LOOP; | |
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT step.n | |
FROM generate_series(1, 5) AS step (n), | |
generate_series(1, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN; | |
DROP FUNCTION IF EXISTS slugify CASCADE; | |
DROP TRIGGER IF EXISTS slugify | |
ON talks; | |
DROP TABLE IF EXISTS talks CASCADE; | |
CREATE | |
OR REPLACE FUNCTION slugify(intake TEXT) | |
RETURNS TEXT AS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT routine_name FROM information_schema.routines | |
WHERE routine_type='FUNCTION' AND specific_schema='public' ORDER BY routine_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
( n % 2 ) :: TEXT, | |
ARRAY_AGG ( n ) | |
FROM | |
generate_series ( 1, 10 ) n | |
GROUP BY | |
( n % 2 ) :: TEXT; |
OlderNewer