Skip to content

Instantly share code, notes, and snippets.

@rsudip90
rsudip90 / nullHandle_extends.go
Last active January 3, 2024 21:46
database rows null handling in go by extending types
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"time"
"github.com/go-sql-driver/mysql"
@rsudip90
rsudip90 / nullHandle.go
Last active February 1, 2023 03:34
How I handled the null possible value in a sql database row in golang?
package main
import (
"database/sql"
"encoding/json"
"fmt"
"reflect"
"time"
"github.com/go-sql-driver/mysql"
@rsudip90
rsudip90 / models.py
Last active February 14, 2022 07:57
drf serializer class dynamic -- models.py
from django.conf import settings
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import ugettext_lazy as _
from enumfields import EnumField
from enumfields import Enum
class SystemUserRole(Enum):
SYS_ADMIN = "SYS_ADMIN"
SYS_USER = "SYS_USER"
@rsudip90
rsudip90 / serializers.py
Created May 12, 2019 10:08
drf serializer class dynamic -- serializers.py
from rest_framework import serializers
from enumfields.drf.serializers import EnumSupportSerializerMixin
from .models import User, Company
class CompanySerializer(serializers.ModelSerializer):
full_address = serializers.CharField(read_only=True)
class Meta:
model = Company
@rsudip90
rsudip90 / mixins.py
Created May 12, 2019 10:32
drf serializer class dynamic -- mixins.py
class GetSerializerClassMixin(object):
def get_serializer_class(self):
"""
A class which inhertis this mixins should have variable
`serializer_action_classes`.
Look for serializer class in self.serializer_action_classes, which
should be a dict mapping action name (key) to serializer class (value),
i.e.:
@rsudip90
rsudip90 / views.py
Last active February 14, 2022 07:56
drf serializer class dynamic -- views.py -- using serializer_action_classes
from rest_framework import viewsets
from .mixins import GetSerializerClassMixin
from .models import User, Company, SystemUserRole
from .serializers import (
CompanySerializer,
CompanyDetailSerializer,
UserSerializer,
UserDetailSerializer,
)
@rsudip90
rsudip90 / directory_structure.txt
Last active November 23, 2021 23:07
working with MySQL JSON type in prepared statements using Go
go-mysql-json-ex/
|-- dbm/ // contains all database related operations
| |-- internal/ // internal only accessible to dbm
| | |-- base.go // contains db conf, manager
| | |-- prepsql.go // all prepared statements used in entire app
| |-- conn.go // db init, close API call
| |-- delete.go // delete db resource APIs
| |-- get.go // get db resource APIs
| |-- insert.go // insert db resource APIs
| |-- models.go // models in go representing db tables structrure
@rsudip90
rsudip90 / views.py
Created May 12, 2019 11:52
drf serializer classes dynamic -- views.py -- custom user limited info
from rest_framework import viewsets
from .mixins import GetSerializerClassMixin
from .models import User, Company, SystemUserRole
from .serializers import (
CompanySerializer,
CompanyDetailSerializer,
UserSerializer,
UserDetailSerializer,
)
@rsudip90
rsudip90 / mysql-json-ex.py
Last active October 26, 2019 23:05
MySQL JSON type data handling in python
import mysql.connector
import json
config = {
"user": "",
"password": "",
"host": "localhost",
"database": "test",
"use_pure": True,
}
@rsudip90
rsudip90 / cypress_AMI_dependencies_install.sh
Last active August 14, 2019 00:56
latest system update
#!/bin/bash
# This script installs the dependencies required by cypress.io tool
# on amazon linux AMI as the required dependencies are not easily available.
# path of dynamic executable of cypress
# for ex. /home/ec2-user/.cache/Cypress/3.0.1/Cypress/
CYPRESS_EXECUTABLE_FOLDER="/home/ec2-user/.cache/Cypress/<version>/Cypress"
exitError() {