Skip to content

Instantly share code, notes, and snippets.

View manjurulhoque's full-sized avatar
🏠
Working from home

Manjurul Hoque Rumi manjurulhoque

🏠
Working from home
View GitHub Profile
public static String getDate(long time) {
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
cal.setTimeInMillis(time);
return DateFormat.format("EEE, dd/MM/yyyy", cal).toString(); // EEE is for day of the week
}
import {withRouter} from 'react-router'
class Nav extends Component {
render () {
const { match, location, history } = this.props
return <h2>The Nav</h2>
}
}
djangoapp/
__init__.py
models.py
...
templatetags/
__init__.py
custom_tags.py
Note:: After adding a new template tags module, you will need to restart
the Django development server in order to use the new template tags and filters.
For python3 you would need to use
>>> exec(open('myscript.py').read())
or
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
django.setup()
# now your code can go here...
class Register(CreateView):
model = User
form_class = UserRegistrationForm
template_name = 'accounts/form.html'
success_url = '/'
extra_context = {
'title': 'Register'
}
class Login(FormView):
"""
Provides the ability to login as a user with a username and password
"""
success_url = '/'
form_class = UserLoginForm
template_name = 'accounts/form.html'
extra_context = {
'title': 'Login'
class LogoutView(RedirectView):
"""
Provides users the ability to logout
"""
url = '/login'
def get(self, request, *args, **kwargs):
auth.logout(request)
messages.success(request, 'You are now logged out')
return super(LogoutView, self).get(request, *args, **kwargs)
from django.urls import path
from . import views
app_name = 'accounts'
urlpatterns = [
path('login', views.Login.as_view(), name='login'),
path('register', views.Register.as_view(), name='register'),
path('logout', views.LogoutView.as_view(), name='logout'),
@manjurulhoque
manjurulhoque / custom_exception.py
Created April 9, 2019 12:22 — forked from harunurkst/custom_exception.py
Custom exception handler for Django rest framework
def format_code(code_name):
"""Format django error code to Circle Error code"""
if code_name == 'blank':
return "BLANK_FIELD"
elif code_name == 'invalid':
return "INVALID_DATA"
elif code_name == 'required':
return "KEY_ERROR"
else:
@manjurulhoque
manjurulhoque / docker-help.md
Created June 12, 2019 17:11 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info