Skip to content

Instantly share code, notes, and snippets.

@saniaky
saniaky / Readme.md
Last active April 23, 2024 00:42
Docker + nginx-proxy + let's encrypt + watchtower + fail2ban

Complete solution for websites hosting

This gist contains example of how you can configure nginx reverse-proxy with autmatic container discovery, SSL certificates generation (using Let's Encrypt) and auto updates.

Features:

  • Automatically detect new containers and reconfigure nginx reverse-proxy
  • Automatically generate/update SSL certificates for all specified containers.
  • Watch for new docker images and update them.
  • Ban bots and hackers who are trying to bruteforce your website or do anything suspicious.
@dideler
dideler / bot.rb
Last active May 23, 2024 17:31
Sending a notification message to Telegram using its HTTP API via cURL
# Use this script to test that your Telegram bot works.
#
# Install the dependency
#
# $ gem install telegram_bot
#
# Run the bot
#
# $ ruby bot.rb
#
@mbrochh
mbrochh / 01_utils.py
Last active September 24, 2023 10:45
Using pagination with Django, graphene and Apollo
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# First we create a little helper function, becase we will potentially have many PaginatedTypes
# and we will potentially want to turn many querysets into paginated results:
def get_paginator(qs, page_size, page, paginated_type, **kwargs):
p = Paginator(qs, page_size)
try:
page_obj = p.page(page)
except PageNotAnInteger:
@dungdt88
dungdt88 / firewall-cmd-rich-rule.md
Last active September 26, 2023 22:42
Allow docker to access all containers within host with firewall-cmd rich rule in Centos 7
@tapanpandita
tapanpandita / celery.py
Created October 8, 2016 03:56
Transaction aware celery abstract task
class TransactionAwareTask(Task):
'''
Task class which is aware of django db transactions and only executes tasks
after transaction has been committed
'''
abstract = True
def apply_async(self, *args, **kwargs):
'''
Unlike the default task in celery, this task does not return an async
@ilkka
ilkka / README.md
Created April 1, 2015 10:54
GitLab + Jenkins in one command

GitLab + Jenkins in one command

$ docker-compose up

Here's a Docker Compose config file that'll give you Gitlab (SSH on 10022, HTTP on 10080) and Jenkins (HTTP on 10081) running and connected. Just add the GitLab CI and Git plugins to Jenkins and you're good to go.

Note that when setting Jenkins as your GitLab CI on the GitLab side, you have to use the container's IP since the link only goes the other way. Also GitLab can't send emails as is, I'm working on that.

@venkatesh22
venkatesh22 / django custom signal
Created June 26, 2013 05:37
django custom signals creation example
#signals.py
from django.dispatch import Signal
user_login = Signal(providing_args=["request", "user"])
#views.py
from foo import signals
@douglasmiranda
douglasmiranda / gist:5408278
Created April 17, 2013 22:26
Leading zeros in django templates
{{ variable|stringformat:"02d" }}
@betweenbrain
betweenbrain / gist:2284129
Created April 2, 2012 14:56
Git command to export only changed files between two commits
git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)
@vstoykov
vstoykov / force_default_language_middleware.py
Last active August 8, 2023 08:24
Force Django to use settings.LANGUAGE_CODE for default language instead of request.META['HTTP_ACCEPT_LANGUAGE']
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
class ForceDefaultLanguageMiddleware(MiddlewareMixin):
"""
Ignore Accept-Language HTTP headers