Skip to content

Instantly share code, notes, and snippets.

Avatar

Edi Santoso repodevs

View GitHub Profile
@repodevs
repodevs / prune-node_modules.sh
Created May 27, 2020
Remove unnecessary files from node_modules
View prune-node_modules.sh
# Install `node-prune` from https://github.com/tj/node-prune
curl -sf https://gobinaries.com/tj/node-prune | sh
# Find all `node_modules` directory
# and prune it.
find . -name "node_modules" -type d -exec node-prune {} \;
View sequelize-mapToModel-example.js
/**
* @param {UUID} sourceId An ID to find.
*
* @returns {Object} an single object instance of Sequelize Model.
*/
async function getMyTableData(sourceId) {
const sequelize = await this.hub.api('DbConnector', 'Sequelize');
const mytable = await sequelize
.query(`SELECT *
FROM "my_table_name"
@repodevs
repodevs / django_undo_migration.md
Created Feb 2, 2020
How to undo migration in Django
View django_undo_migration.md

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 Oct 9, 2019
Django hide sensitive information when Debug mode
View django_hide_sensitive_in_debug.md

Make sure all sensitive variables use one of the keywords:

API
KEY
PASS
SECRET
SIGNATURE
TOKEN
@repodevs
repodevs / nohup.sh
Created Sep 8, 2019
Linux command to run script (program) in background without killed
View nohup.sh
# 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`
View SketchSystems.spec
Traffic Light*
Green*
timer -> Red
Red
timer -> Yellow
Walk
tick -> Stop
Stop
tick -> Yellow
@repodevs
repodevs / example.py
Created Jul 10, 2019
Django multiple insert data / bulk create
View example.py
"""
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 Jun 25, 2019
Sequelize add or remove enum values
View alter-enum.js
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 — forked from sirbrillig/pgsql_backup.sh
Postgresql daily backup script.
View pgsql_backup.sh
#!/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 Apr 15, 2019
Setup GPG Key macOS from keybase.io
View gpg-keybase.sh
## 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)
You can’t perform that action at this time.