Skip to content

Instantly share code, notes, and snippets.

View repodevs's full-sized avatar

Edi Santoso repodevs

View GitHub Profile
@repodevs
repodevs / django_undo_migration.md
Created February 2, 2020 18:45
How to undo migration in Django

Let say you have migrations like this

project/apps/accounts/migrations
├── 0001_initial.py
├── 0002_historicalprofile_historicaluser.py
├── 0003_auto_20190807_1559.py
├── 0004_auto_20190811_1013.py
@repodevs
repodevs / django_hide_sensitive_in_debug.md
Created October 9, 2019 18:19
Django hide sensitive information when Debug mode

Make sure all sensitive variables use one of the keywords:

API
KEY
PASS
SECRET
SIGNATURE
TOKEN
@repodevs
repodevs / nohup.sh
Created September 8, 2019 12:43
Linux command to run script (program) in background without killed
# when we running script in background using `&` after we logout, the script will be killed,
# to prevent the script being killed we can use `nohup`
$ nohup bash -c "time python myapp.py" > myapp.log 2>&1 &
# this command will run our script in background (even we logout from terminal session)
# and we can still watching the log from `myapp.log`
# e.g `tail -f myapp.log`
@repodevs
repodevs / SketchSystems.spec
Created July 31, 2019 09:53
Traffic Light*
Traffic Light*
Green*
timer -> Red
Red
timer -> Yellow
Walk
tick -> Stop
Stop
tick -> Yellow
@repodevs
repodevs / example.py
Created July 10, 2019 04:19
Django multiple insert data / bulk create
"""
This is simple snippet to insert multiple data / bulk create in django
"""
# take example, we have a list of dict data
datas = [{
"name": "A",
"number: 1,
}, {
"name": "B",
@repodevs
repodevs / alter-enum.js
Created June 25, 2019 08:31
Sequelize add or remove enum values
module.exports = {
up: (queryInterface, DataTypes) => {
return queryInterface.sequelize.query("ALTER TYPE enum_students_id_card_type ADD VALUE 'driving_license';");
},
down: (queryInterface, DataTypes) => {
// FIXME: Removing enum value is not supported by PostgreSQL,
// but there is any tricky way to do this.
// ref: https://stackoverflow.com/a/46244969, https://stackoverflow.com/a/25812436
return queryInterface.sequelize.query("UPDATE students SET id_card_type = 'ktp' WHERE id_card_type = 'driving_license';")
.then(() => {
@repodevs
repodevs / pgsql_backup.sh
Created May 18, 2019 19:50 — forked from sirbrillig/pgsql_backup.sh
Postgresql daily backup script.
#!/bin/bash
#
# Backup a Postgresql database into a daily file.
#
BACKUP_DIR=/pg_backup
DAYS_TO_KEEP=14
FILE_SUFFIX=_pg_backup.sql
DATABASE=
USER=postgres
@repodevs
repodevs / gpg-keybase.sh
Created April 15, 2019 11:32
Setup GPG Key macOS from keybase.io
## Download first your keybase-private.key and keybase-public.key
gpg --allow-secret-key-import --import keybase-private.key
gpg --import keybase-public.key
## check list gpg
gpg --list-secret-keys
## fix io error
export GPG_TTY=$(tty)
@repodevs
repodevs / macOS.sh
Created December 12, 2018 14:56
gpg: signing failed: Inappropriate ioctl for device macOS
❱ git config user.signingKey 38AF394C
❱ git config commit.gpgSign true
❱ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
test
gpg: signing failed: Inappropriate ioctl for device
gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device
@repodevs
repodevs / orm.md
Last active December 10, 2018 04:48
Odoo ORM one2many or many2many domain

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write values on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)