Skip to content

Instantly share code, notes, and snippets.

View aj07mm's full-sized avatar

Julio Marins aj07mm

View GitHub Profile
@aj07mm
aj07mm / super_multi_inheritance.py
Created February 27, 2018 16:30 — forked from motivic/super_multi_inheritance.py
Using super in Python 2.7
# http://stackoverflow.com/questions/222877/how-to-use-super-in-python
class SomeBaseClass(object):
def __init__(self):
print('SomeBaseClass.__init__(self) called')
class ChildClass(SomeBaseClass):
def __init__(self):
print('ChildClass.__init__(self) called')
SomeBaseClass.__init__(self)
@aj07mm
aj07mm / node-npm-in-docker.sh
Created March 4, 2018 20:25 — forked from artemgordinskiy/node-npm-in-docker.sh
Run Node/NPM in a Docker container
# For example, run "npm install"
docker run -v "$PWD":/usr/src/app -w /usr/src/app node:4 npm install
# This command creates a container (downloading one first if you don't have it locally), runs the command in a current directory and quits the container
# Great Success!
@aj07mm
aj07mm / middleware.py
Created March 17, 2018 15:55 — forked from jsanchezpando/middleware.py
Simple Django super class to track user and save creator and modifier of a Model.
from myapp.utils import set_current_user
class CurrentUserMiddleware:
def process_request(self, request):
set_current_user(getattr(request, 'user', None))
3 ways to define a JavaScript class
Introduction
JavaScript is a very flexible object-oriented language when it comes to syntax. In this article you can find three ways of defining and instantiating an object. Even if you have already picked your favorite way of doing it, it helps to know some alternatives in order to read other people's code.
It's important to note that there are no classes in JavaScript. Functions can be used to somewhat simulate classes, but in general JavaScript is a class-less language. Everything is an object. And when it comes to inheritance, objects inherit from objects, not classes from classes as in the "class"-ical languages.
1. Using a function
This is probably one of the most common ways. You define a normal JavaScript function and then create an object by using the new keyword. To define properties and methods for an object created using function(), you use the this keyword, as seen in the following example.
function Apple (type) {
@aj07mm
aj07mm / savejsoninredis.py
Created May 18, 2018 03:05 — forked from swdevbali/savejsoninredis.py
Simply json.dumps() => save to redis => redis.get => json.loads() => Python dict with proper data type created
__author__ = 'ekowibowo'
import json
import os
import redis
REDIS_HOST = os.getenv('SS_ABTEST_REDIS_HOST', '192.168.59.103')
r = redis.StrictRedis(host=REDIS_HOST)
for k in r.keys('abtest:experiments:*'):
r.delete(k)
@aj07mm
aj07mm / WhatHappenedToMyDataInRedis.md
Created June 22, 2018 01:33 — forked from JonCole/WhatHappenedToMyDataInRedis.md
What happened to my data in Redis?

What happened to my data in Redis?

This post is a FAQ for Redis, when users don’t see the data they stored in Redis.

As per the Redis project, Redis is described as an in-memory data structure store. If you are using Redis as an LRU cache, you can see following recommendation from the Redis docs: Using Redis as an LRU cache

Lately, I have received multiple questions about when Redis will lose data. This data loss can be as simple as a few keys disappearing unexpectedly or complete loss of all data in Redis. Below I will talk about the most common causes as well as a few rare cases where this can happen.

Note: These scenarios are common to all Redis hosting environments, including self-hosting Redis in your own data center.

@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
---------------------------------------------------------------------------------------
@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 / 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 / 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)