Skip to content

Instantly share code, notes, and snippets.

View aj07mm's full-sized avatar

Julio Marins aj07mm

View GitHub Profile
@aj07mm
aj07mm / gist:c746d8ee0329e48acb62a211b955b1d0
Created October 18, 2018 16:32 — forked from vpetro/gist:1174019
Return multiple items from a mocked function with Python's mock.
import mock
def returnList(items):
def func():
for item in items:
yield item
yield mock.DEFAULT
generator = func()
@aj07mm
aj07mm / port_test.py
Created October 10, 2018 16:44
Python script to test open outgoing ports from local network
#!/usr/bin/env python
"""Port test
Python script to test open outgoing ports from local network
"""
import socket
for port in range(1,65000):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@aj07mm
aj07mm / sets python
Created October 5, 2018 14:02
sets python
S & Z - intersection
S | Z - union
S - Z - difference
S ^ Z - symetric difference
@aj07mm
aj07mm / decorators.py
Last active September 29, 2018 20:44
decorators.py
def decorator(fn):
def inner(name):
return '<a>' + fn(name) + '</a>'
return inner
def decorator_parameterized(html_tag):
def decorator(fn):
def inner(name):
return '<{}>'.format(html_tag) + fn(name) + '</{}>'.format(html_tag)
return inner
@aj07mm
aj07mm / example_related_manager.py
Last active August 27, 2018 12:44
example_related_manager.py
@aj07mm
aj07mm / refs
Created August 24, 2018 04:03
refs
+refs/heads/dev:refs/heads/dev +refs/pull/*:refs/remotes/origin/pr/*
@aj07mm
aj07mm / login_required.py
Created August 24, 2018 01:19 — forked from robgolding/login_required.py
Django Class-Based View Mixins: Part 1
class LoginRequiredMixin(object):
"""
View mixin which requires that the user is authenticated.
"""
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(
self, request, *args, **kwargs)
@aj07mm
aj07mm / middleware.py
Created August 17, 2018 20:48 — forked from j4mie/middleware.py
Django middleware to log the total number of queries run and query time for every request
from django.db import connection
from django.utils.log import getLogger
logger = getLogger(__name__)
class QueryCountDebugMiddleware(object):
"""
This middleware will log the number of queries run
and the total time taken for each request (with a
status code of 200). It does not currently support
@aj07mm
aj07mm / regex_greed.txt
Created August 14, 2018 00:46
regex_greed.txt
+-------------------+-----------------+------------------------------+
| Greedy quantifier | Lazy quantifier | Description |
+-------------------+-----------------+------------------------------+
| * | *? | Star Quantifier: 0 or more |
| + | +? | Plus Quantifier: 1 or more |
| ? | ?? | Optional Quantifier: 0 or 1 |
| {n} | {n}? | Quantifier: exactly n |
| {n,} | {n,}? | Quantifier: n or more |
| {n,m} | {n,m}? | Quantifier: between n and m |
+-------------------+-----------------+------------------------------+
@aj07mm
aj07mm / Regex Patterns
Created August 14, 2018 00:46 — forked from cozingo/Regex Patterns
Regex regex
\d - digit [0,9]
\w - digit, ASCII letter or underscore
\s - whitespace, i.e. space, tab, newline(\n), carriage return(\r), vertical tab(Ctrl + K) <-vertical tab not useful anymore
\D == [^\d] - 1 character which is not digit
\W == [^\w] - 1 character which is not ASCII letter, digit and underscore
\S == [^\s] - 1 character which is not type of whitespace
---------------------------------------------------------------------------------------