Skip to content

Instantly share code, notes, and snippets.

View repodevs's full-sized avatar

Edi Santoso repodevs

View GitHub Profile
@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)

@repodevs
repodevs / gist:881697c59ca4665eed393230daebffe6
Created December 5, 2018 05:48
Docker macOS host cannot access to container.
For my issue. adding alias is solved
$ docker inspect YOUR-CONTAINER
get the IP and add to alias
$ sudo ifconfig lo0 alias IP
$ sudo ifconfig lo0 alias 172.17.0.1
@repodevs
repodevs / odoo-cli.py
Created June 10, 2018 09:23
Odoo CLI Helpers
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""Install, Uninstall, Upgrade a module"""
import xmlrpclib
import argparse
import getpass
import time
parser = argparse.ArgumentParser()
@repodevs
repodevs / snippet.py
Created April 13, 2018 07:36
Odoo snippet fields.Selection get text name
def get_selection_name(models, fields, value):
""" Get text value of Selection fields
:param models: models of fields
:param fields: fields name to get
:param value: fields value
:return text: Text value of the fields or ''
"""
res = dict(models.fields_get(allfields=[fields])[fields]['selection'])[value] if value else ''