Skip to content

Instantly share code, notes, and snippets.

View KenanBek's full-sized avatar
🐎

Kanan Rahimov KenanBek

🐎
View GitHub Profile
@KenanBek
KenanBek / Status check script for Docker Compose for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis - initial.sh
Last active April 4, 2018 22:36
Docker Compose run order for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis. More at http://bit.ly/docker-order
#!/bin/bash
# wait-for-postgres.sh
# Stop execution if we have an error
set -e
# Get host:port from parameters list
host="$1"
# Remove first argument from list of parameters (host)
@KenanBek
KenanBek / Dockerfile for Docker Compose for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis
Last active April 4, 2018 22:37
Docker Compose run order for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis. More at http://bit.ly/docker-order
# Use base python image with python 2.7
FROM python:2.7
# Install postgres client to check status of db cotainers
# This peace of script taken from Django's official repository
# It is deprecated in favor of the python repository
# https://hub.docker.com/_/django/
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
@KenanBek
KenanBek / Status check script for Docker Compose for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis.sh
Last active April 4, 2018 22:37
Docker Compose run order for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis. More at http://bit.ly/docker-order
#!/bin/bash
# wait-for-postgres.sh
# Stop execution if we have an error
set -e
# Get host:port from parameters list
host="$1"
# Remove first argument from list of parameters (host)
@KenanBek
KenanBek / Entrypoint for Docker Compose for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis.sh
Last active April 4, 2018 22:37
Docker Compose run order for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis. More at http://bit.ly/docker-order
#!/bin/bash
#python manage.py test
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
exec "$@"
@KenanBek
KenanBek / Docker Compose for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis - initial version.yml
Last active April 4, 2018 22:37
Docker Compose run order for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis. More at http://bit.ly/docker-order
version: "3"
services:
# PostgreSQL
db:
image: postgres:9.4
hostname: db
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
@KenanBek
KenanBek / PythonForEachEnumerate.py
Last active April 29, 2018 08:52
Use enumerate instead of range or custom countrer
# Example list to enumerate
cars = ['nissan', 'infiniti', 'mitsubishi', 'toyota']
# Instead of this
for i in range(len(cars)):
car = cars[i]
print('{}: {} is fast'.format(i, car))
# Or this
i = 0
@KenanBek
KenanBek / Docker Compose for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis - final version.yml
Last active June 3, 2018 12:47
Docker Compose run order for Django REST Framework and Celery with PostgreSQL, RabbitMQ and Redis. More at http://bit.ly/docker-order
version: "3"
services:
# PostgreSQL
db:
image: postgres:9.4
hostname: db
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
package mongo
import (
"log"
"os"
"strconv"
"testing"
"github.com/ory/dockertest"
"github.com/stretchr/testify/assert"
@KenanBek
KenanBek / server.js
Last active November 4, 2020 22:23
Simple JSON API using Node.js and Express.js. More: https://kananrahimov.com/post/example-backend-api-in-node-js-video-tutorial/
const express = require('express');
const app = express();
const hostname = '127.0.0.1';
const port = 3000;
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'application/json');
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
let body = {