Skip to content

Instantly share code, notes, and snippets.

View 101t's full-sized avatar
🐍
Simple is better than complex!

Tarek Kalaji 101t

🐍
Simple is better than complex!
View GitHub Profile
@alukach
alukach / admin.py
Created January 5, 2015 04:47
Custom Django Admin Form via Fake Model
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django.shortcuts import render
from my_app.forms import CustomForm
class FakeModel(object):
class _meta:
app_label = 'my_app' # This is the app that the form will exist under
@arulrajnet
arulrajnet / MXEmailVerifier.py
Last active May 25, 2023 14:23
Verify the given mail id is valid or not, without sending mail. Verifying the email id directly from mail exchange server.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Verify the given mail id is valid or not without sending mail. Verifying the email id directly from mail exchange server.
"""
import argparse
import smtplib
import dns.resolver
@betrcode
betrcode / README.md
Created June 24, 2014 06:36
Using Python to check if remote port is open and accessible.
@gavinhungry
gavinhungry / nginx-tls.conf
Last active March 7, 2025 19:38
Nginx SSL/TLS configuration for "A+" Qualys SSL Labs rating
#
# Name: nginx-tls.conf
# Auth: Gavin Lloyd <[email protected]>
# Desc: Nginx SSL/TLS configuration for "A+" Qualys SSL Labs rating
#
# Enables HTTP/2, PFS, HSTS and OCSP stapling. Configuration options not related
# to SSL/TLS are not included here.
#
# Additional tips:
#
@denji
denji / nginx-tuning.md
Last active May 8, 2025 19:46
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

alphabet=''.join([chr(i) for i in xrange(256) if chr(i) not in '!"#$&*+-/0123456789;=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^abcdefghijklmnopqrstuvwxyz|' and i != 0])
def filt(s):
return s.translate(ident,'!"#$&*+-/0123456789;=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^abcdefghijklmnopqrstuvwxyz|')
def obfNum(n):
""" Obfuscate a number """
if n==0:
return "([]<{})"
elif n==1:
@luca-m
luca-m / py-notes
Last active September 5, 2022 18:15
# >>> ACCESS TO ALL CLASSES ---------------------------------------------------
().__class__.__bases__[0].__subclasses__()
# >>> INSTIANTIATE NEW OBJECTS ------------------------------------------------
[].__class__.__class__.__new__( <TYPE> , <SUBTYPE> )
[c for c in ().__class__.__base__.__subclasses__() if c.__name__ == '<CLASSNAME>'][0]()
@bsnux
bsnux / create_fieldfile.py
Created February 14, 2013 11:57
Creating a Django FileField from shell
from django.core.files import File
f = File(open('path_to_file','r'))
m = MyModel.objects.create(one_field='value')
m.file_field = f
m.save()
@jfinstrom
jfinstrom / asterisk.py
Last active July 14, 2021 14:37
Example of using the Asterisk Manager API in python...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# asterisk.py
#
# Copyright 2014 James Finstrom<jfinstrom at gmail>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@mnordhoff
mnordhoff / gist:2213179
Last active October 22, 2022 23:17
Python regular expressions for IPv4 and IPv6 addresses and URI-references, based on RFC 3986's ABNF.The URI-reference regular expression includes IPv6 address zone ID support (RFC 6874).
# Python regular expressions for IPv4 and IPv6 addresses and URI-references,
# based on RFC 3986's ABNF.
#
# ipv4_address and ipv6_address are self-explanatory.
# ipv6_addrz requires a zone ID (RFC 6874) follow the IPv6 address.
# ipv6_address_or_addrz allows an IPv6 address with optional zone ID.
# uri_reference is what you think of as a URI. (It uses ipv6_address_or_addrz.)
import re