This file contains hidden or 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 reset --hard HEAD~1 | |
This would delete last commit https://stackoverflow.com/a/1338744 |
This file contains hidden or 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
# trying to commit without needing to add all those extra files? just clean them | |
git clean -n -d # to see the files and folders to be deleted first before applying command below | |
git clean -f -d # -f force clean and -d cleaning directories. git just deletes. | |
This file contains hidden or 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
# using truncate | |
TRUNCATE TABLE table_name RESTART IDENTITY; # to reset index counts | |
TRUNCATE TABlE table_name CASCADE; # to delete foreign key dependencies |
This file contains hidden or 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
# We want to get the keys which failed this could be applied to other situations | |
# Python 3 | |
dict_of_elements = {1: 'john', 2: 'peter', 3: 'luke', 4: 'mark'} # can equally be a list? | |
failed_keys = set() | |
for list in dict_of_elements: | |
try: | |
dict_of_elements[9] # trying to access keys that don't exist | |
except Exception as e: | |
f_k = e.args[0] | |
failed_keys.add(f_k) |
This file contains hidden or 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
# After an import of data sometimes when you try to create new records, postgres creates same ids and cause clashes from time to time | |
# To correct the sequence and tell postgres where to start counting next run this | |
SELECT pg_catalog.setval(pg_get_serial_sequence('table_name', 'id'), MAX(id)) FROM table_name; # replace table_name with required table |
This file contains hidden or 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 fetch origin # gets latest changes made to master | |
git checkout branch_name # switch to your branch | |
git merge master # merge with master | |
# manually resolve any merge conflicts here | |
git push origin branch_name # push branch and update the pull request | |
# branch_name is the name of the branch you you have the conflict on |
This file contains hidden or 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
Recently upgraded to lattest version of High sierra and had permission issues in trying to upgrade node | |
sudo chown -R $(whoami) /usr/local # does not work any more | |
sudo chown -R $(whoami) $(brew --prefix)/* # this works |
This file contains hidden or 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 DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser; # newdb and originaldb are names of the new database and old database | |
# getting an error ? | |
ERROR: source database "originaldb" is being accessed by other users | |
# run this query to stop error before running create data base query | |
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'originaldb' AND pid <> pg_backend_pid(); # change originaldb with name of old database |
This file contains hidden or 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
https://stackoverflow.com/questions/32812463/setting-schema-for-all-queries-of-a-connection-in-psycopg2-getting-race-conditi | |
cheat sheet | |
http://www.postgresqltutorial.com/postgresql-cheat-sheet/ | |
Postgres setup with django |
This file contains hidden or 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 COUNT(*) FROM (SELECT DISTINCT column_name FROM table_name) AS temp; |