Skip to content

Instantly share code, notes, and snippets.

View mansha99's full-sized avatar

Manish Sharma mansha99

View GitHub Profile
export const fanSpeedInitial = {
level: 0,
status: 'OFF'
};
export const ROTATE_RIGHT_ACTION =
{ type: 'ROTATE_RIGHT' };
export const ROTATE_LEFT_ACTION =
{ type: 'ROTATE_LEFT' }
export function fanSpeedReducer(fanSpeed: any, action: any) {
if (action.type == 'ROTATE_RIGHT') {
"use client";
import { useReducer } from "react";
import { fanSpeedInitial, fanSpeedReducer } from "./page-reducer";
export default function Home() {
const [fanSpeedCurrent, fanSpeedHandler] = useReducer(fanSpeedReducer, fanSpeedInitial);
return (
<main style={{ padding: 20 }}>
<div>
@mansha99
mansha99 / settings.py
Created July 4, 2023 13:50
notice_app/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'notices'
]
@mansha99
mansha99 / settings.py
Created July 4, 2023 13:53
notice_app/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'notice_app',
'USER': 'root',
'PASSWORD': 'VeryStrongPa55Word$%',
'HOST': 'localhost',
'PORT': '3306',
}
}
@mansha99
mansha99 / settings.py
Created July 4, 2023 13:54
notice_app
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
}
@mansha99
mansha99 / models.py
Created July 4, 2023 14:00
notice_app/notices/models.py
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from .managers import CustomUserManager
from django.core.validators import RegexValidator
phone_validator = RegexValidator(r"^[7-9]{1}[0-9]{9}$", "Exactly 10 digits are required")
class CustomUser(AbstractBaseUser, PermissionsMixin):
mobile = models.CharField(max_length=16, validators=[phone_validator], unique=True)
@mansha99
mansha99 / managers.py
Created July 4, 2023 17:12
notice_app/notices/managers.py
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import gettext_lazy as _
class CustomUserManager(BaseUserManager):
def create_user(self, mobile, password, **extra_fields):
if not mobile:
raise ValueError(_("The mobile must be set"))
user = self.model(mobile=mobile, **extra_fields)
user.set_password(password)
@mansha99
mansha99 / models.py
Created July 4, 2023 17:17
notice_app/notices/models.py
class Notice(models.Model):
title = models.CharField(max_length=80,unique=True)
description = models.CharField(max_length=255,unique=True)
@mansha99
mansha99 / serializers.py
Created July 4, 2023 17:26
notice_app/notices/serializers.py
class NoticeSerializer(serializers.ModelSerializer):
class Meta:
model = Notice
fields = ('__all__')
@mansha99
mansha99 / notices.json
Created July 4, 2023 17:28
notice_app/notices/fixtures/notices.json
[
{
"model": "notices.Notice",
"pk": 1,
"fields": {
"title": "This is Notice 1",
"description": "This is description of Notice 1"
}
},
{