Skip to content

Instantly share code, notes, and snippets.

View repodevs's full-sized avatar

Edi Santoso repodevs

View GitHub Profile
@repodevs
repodevs / .env
Created December 5, 2020 16:59
python-decouple casting octal number 0o in python3
# by default this is will be converted to string
# if you want cast to octal number you need custom cast function
FILE_UPLOAD_PERMISSIONS=0o644
@repodevs
repodevs / find_and_fix_permission.sh
Created December 5, 2020 16:16
Linux command to find and fix permission file
#!/bin/bash
find -type f -not -perm 644 -exec chmod 644 {} \;
@repodevs
repodevs / prune-node_modules.sh
Created May 27, 2020 05:34
Remove unnecessary files from node_modules
# 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 {} \;
@repodevs
repodevs / sequelize-mapToModel-example.js
Created April 27, 2020 05:11
sequelize mapToModel example
/**
* @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 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(() => {