Skip to content

Instantly share code, notes, and snippets.

View AshishPandagre's full-sized avatar

Ashish Pandagre AshishPandagre

View GitHub Profile
@AshishPandagre
AshishPandagre / admin.py
Created October 19, 2020 10:06
creating a custom user model in django-allauth.
#---------some_app/admin.py-------------
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
class CustomUserAdmin(UserAdmin):
@AshishPandagre
AshishPandagre / __init__.py
Last active October 20, 2020 16:19
Using signals in django
# some_app/__init__.py
# some_app is the name of the app.
default_app_config = 'some_app.apps.'
@AshishPandagre
AshishPandagre / my_template.html
Last active May 30, 2021 18:18
Creating a custom template tag in Django.
{% load my_template_tag %} <!-- Loading the file we defined our template tags in -->
{% for pdt in products %}
<tr>
<td>{{pdt.name}}</td>
<td>{{pdt.price}}</td>
<td>{{pdt.sold_by}}</td>
<td>{% n_reviews pdt.id %}</td>
<!-- our template tag, pdt.id is passed as argument in n_reviews function -->
</tr>
@AshishPandagre
AshishPandagre / index.html
Created May 31, 2021 05:48
Sending a POST request from javascript to django views.
<html>
<title>Tweets page</title>
<head></head>
<body>
{% for tweet in tweets %}
{{ tweet.tweet }}
{{ tweet.likes }}
<button data-tweet="{{ tweet.id }}" data-action='like'>Like</button>
<br><br>
@AshishPandagre
AshishPandagre / app_admin.py
Last active March 7, 2024 05:40
Add tinymce editor in django (along with drag and drop image upload)
from django.contrib import admin
from .models import Post
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
class Media:
js = ('tinyInject.js',)
@AshishPandagre
AshishPandagre / basic-docker.txt
Created January 23, 2022 04:56
basic docker commands
docker pull redis // can be found from docker hub
docker images // all existing images
docker run redis:4.0 // pulls image and starts container
docker run redis // starts the image in a container
docker run -p6000:6379 redis // starts container at 6000 laptop port -> 6379 container port.
docker run -d redis // runs container in detached (bg) mode, and only returns id of container
docker stop <id> // stops a running container
docker start <id> // starts a previously stopped container
@AshishPandagre
AshishPandagre / basic-psql.txt
Created January 23, 2022 04:57
basic psql commands
-- \l gives the details of databases in psql.
// create a database
CREATE DATABASE test;
//close the prompt and start again.
// enter db name to be test
// to create a table
// App.js
import React from 'react'
import './App.css'
const App = () => {
return (
<>
<img className='img' src='./images/1.jpg'/>
// some of the most commonly used status codes.
const status_code = {
'OK': 200,
'CREATED': 201,
'NO_CONTENT': 204,
'NOT_MODIFIED': 304,
'BAD_REQUEST': 400,
@AshishPandagre
AshishPandagre / check_odd_even.cpp
Created October 25, 2022 12:08
Bit Manipulation C++
int x = 10;
if(x & 1) cout<<"odd";
else cout<<"even";
cout<<endl;