Skip to content

Instantly share code, notes, and snippets.

View aj07mm's full-sized avatar

Julio Marins aj07mm

View GitHub Profile
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 / 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))
@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 / 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 / supervisord-example.conf
Created February 26, 2018 21:59 — forked from didip/supervisord-example.conf
Example configuration file for supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
@aj07mm
aj07mm / installing_cassandra.md
Created February 19, 2018 21:10 — forked from hkhamm/installing_cassandra.md
Installing Cassandra on Mac OS X

Installing Cassandra on Mac OS X

Install Homebrew

Homebrew is a great little package manager for OS X. If you haven't already, installing it is pretty easy:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@aj07mm
aj07mm / pycurses.py
Created February 8, 2018 15:56 — forked from claymcleod/pycurses.py
Python curses example
import sys,os
import curses
def draw_menu(stdscr):
k = 0
cursor_x = 0
cursor_y = 0
# Clear and refresh the screen for a blank canvas
stdscr.clear()
@aj07mm
aj07mm / docker-compose-node-mongo.yml
Created January 2, 2018 02:01 — forked from wesleybliss/docker-compose-node-mongo.yml
Docker Compose with example App & Mongo
version: '2'
services:
myapp:
build: .
container_name: "myapp"
image: debian/latest
environment:
- NODE_ENV=development
- FOO=bar
volumes:
@aj07mm
aj07mm / base_werkzeug_app.py
Created December 28, 2017 01:16 — forked from vskrachkov/base_werkzeug_app.py
Basic example of Werkzeug application
"""
base_werkzeug_app.py
====================
Example of a simple app written using werkzeug library.
"""
import json
import psycopg2
from werkzeug.exceptions import HTTPException
@aj07mm
aj07mm / list-constraints.sql
Created December 6, 2017 18:08 — forked from PickledDragon/list-constraints.sql
Postgres list all constraints
SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name