Skip to content

Instantly share code, notes, and snippets.

@mav-erick
mav-erick / google-places.directive.ts
Last active August 1, 2018 17:35
google place directive
import { Directive, ElementRef, OnInit } from '@angular/core';
const google = require('@types/googlemaps');
@Directive({
selector: '[google-place]'
})
export class GooglePlacesDirective implements OnInit {
private element: HTMLInputElement;
constructor(private elRef: ElementRef) {
@mav-erick
mav-erick / app.component.css
Last active July 22, 2018 19:37
Angular Google places autocomplete app.component.css
.input-container {
text-align: center;
width: 100%;
}
.google-place-input {
width: 50%;
min-width: 280px;
height: 2rem;
font-size: 1.5rem;
@mav-erick
mav-erick / app.component.html
Last active July 29, 2018 04:50
Angular Google place autocomplete directive app.component.html
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo">
</div>
<div class="input-container">
<input
type="text"
class="google-place-input"
@mav-erick
mav-erick / views.py
Created March 19, 2018 20:46
Actors view with Serializer
from .models import Actor
from rest_framework.decorators import api_view
from .serializers import ActorSerializer
from rest_framework.response import Response
# Create your views here.
@api_view(['get'])
def fetch_actors(request):
#fetch all the actor objects
actors = Actor.objects.all()
@mav-erick
mav-erick / serializers.py
Created March 19, 2018 20:41
actors/serializers.py
from rest_framework.serializers import ModelSerializer
from .models import Actor
class ActorSerializer(ModelSerializer):
class Meta:
model = Actor
fields = '__all__'
@mav-erick
mav-erick / views.py
Created March 19, 2018 20:24
actors/views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import Actor
# Create your views here.
def fetch_actors(request):
#fetch all the actor objects
actors = Actor.objects.all()
#send the actor objects as a response
return HttpResponse(actors)
@mav-erick
mav-erick / urls.py
Created March 19, 2018 20:13
urls.py - mobileBackend
"""mobileBackend URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
@mav-erick
mav-erick / settings.py
Created March 18, 2018 23:11
mobileBackend/settings.py
...
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
@mav-erick
mav-erick / models.py
Last active March 18, 2018 23:00
actors/models
from django.db import models
# Create your models here.
class Actor(models.Model):
first_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
dp = models.CharField(max_length=512, blank=True, null=True)
age = models.IntegerField(blank=True, null=True)
@mav-erick
mav-erick / daphne_worker.config
Last active August 3, 2019 23:19
Daphne and worker processes managed by supervisord on AWS Elastic Beanstalk
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_daemon.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Get django environment variables
djangoenv=`cat /opt/python/current/env