Skip to content

Instantly share code, notes, and snippets.

@l4sh
l4sh / nginx.conf
Created January 7, 2019 03:45 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@l4sh
l4sh / python_decorator_guide.md
Created December 3, 2018 01:39 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

def find_bad_cfds(cfds):
invoice_types = ['Ingreso', 'Egreso']
bad_cfds = []
for cfd in cfds:
comprobante = {}
for invoice_type in invoice_types:
comprobante = cfd.metadata.get('IR', {}).get(invoice_type, {}).get('Comprobante')
if comprobante:
break
descuento = comprobante.get('Descuento', 0)
@l4sh
l4sh / ansible-bootstrap-ubuntu-16.04.yml
Created April 11, 2018 01:59 — forked from gwillem/ansible-bootstrap-ubuntu-16.04.yml
Get Ansible to work on bare Ubuntu 16.04 without python 2.7
# Add this snippet to the top of your playbook.
# It will install python2 if missing (but checks first so no expensive repeated apt updates)
# gwillem@gmail.com
- hosts: all
gather_facts: False
tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
@l4sh
l4sh / iptables_squid.sh
Created March 18, 2018 19:14
iptables rules for redirecting traffic from router to squid server
INTERNAL_NETWORK=192.168.1.0/24
LAN=br-lan
LANIP=192.168.1.1
SQUIDIP=192.168.1.10
SQUIDPORT=3128
iptables -t nat -A prerouting_rule -i $LAN ! -s $SQUIDIP -p tcp --dport 80 -j DNAT --to $SQUIDIP:$SQUIDPORT
iptables -t nat -A postrouting_rule -o $LAN -s $INTERNAL_NETWORK -d $SQUIDIP -j SNAT --to $LANIP
iptables -A forwarding_rule -s $INTERNAL_NETWORK -d $SQUIDIP -i $LAN -o $LAN -p tcp --dport $SQUIDPORT -j ACCEPT
@l4sh
l4sh / anope.conf
Created March 18, 2018 19:00
Example configuration files for unrealircd with anope
# Example configuration file for Services. After making the appropriate
# changes to this file, place it in the Services data directory (as
# specified in the "configure" script, default /home/username/services)
# under the name "services.conf".
#
# The format of this file is fairly simple: a line beginning with a # is a
# comment, and any other non-blank line is expected to be a directive and
# parameters, separated by spaces or tabs. For example:
#
# Directive Parameter-1 Parameter-2 ...

Keybase proof

I hereby claim:

  • I am l4sh on github.
  • I am l4sh (https://keybase.io/l4sh) on keybase.
  • I have a public key ASB3P7m0PCWafpFCmR-zQA9vDGckrmWAUK7giET-LiFJMQo

To claim this, I am signing this object:

[{"model": "cfd.taxregime", "pk": "b2226b17-062f-4d3c-a831-9efe6455740f", "fields": {"metadata": {}, "private_metadata": {}, "created": "2017-09-25T22:49:33.118Z", "updated": "2017-09-28T16:20:13.374Z", "label": "general-de-ley-personas-morales", "description": "Aplica para tipo de persona Moral.", "name": "General de Ley Personas Morales", "key": "601"}}, {"model": "cfd.taxregime", "pk": "a0ac7a0d-7ce0-4d9e-8c45-2ba8c8b0e676", "fields": {"metadata": {}, "private_metadata": {}, "created": "2017-09-28T16:21:33.549Z", "updated": "2017-09-28T16:21:33.549Z", "label": "personas-morales-con-fines-no-lucrativos", "description": "", "name": "Personas Morales con Fines no Lucrativos", "key": "603"}}, {"model": "cfd.taxregime", "pk": "9fd6f984-4409-41d9-8f53-36d839b384df", "fields": {"metadata": {}, "private_metadata": {}, "created": "2017-09-28T16:22:37.187Z", "updated": "2017-09-28T16:22:37.187Z", "label": "sueldos-y-salarios-e-ingresos-asimilados-a-salarios", "description": "", "name": "Sueldos y Salarios e ingresos
@l4sh
l4sh / dump_objects.py
Created October 23, 2017 21:18
Dump objects from django database
import json
from uuid import UUID
from django.core import serializers
from django.core.management.base import BaseCommand, CommandError
from django.apps import apps
class Command(BaseCommand):
help = 'Dumps the specified model data to stdout'
@l4sh
l4sh / tempswap.sh
Created October 19, 2017 19:23
Create and enable a temporary swap file
#! /bin/bash
# Create and enable a temporary swap file
SWAPFILE="/tmp/swapfile1"
if [[ $1 == "on" ]]
then
echo Creating swap file on $SWAPFILE
dd if=/dev/zero of=$SWAPFILE bs=1024 count=524288
mkswap $SWAPFILE