Skip to content

Instantly share code, notes, and snippets.

View petarnikolovski's full-sized avatar

Petar Nikolovski petarnikolovski

View GitHub Profile
@petarnikolovski
petarnikolovski / virtualenv_py.md
Last active July 26, 2017 09:03
Setting up and activating virtualenv (Python 3.X)

Installing virtualenv

Virtualenv can be installed using pip:

pip3 install virtualenv

If this approach fails, try:

@petarnikolovski
petarnikolovski / .gitignore
Created August 5, 2017 14:41
Gitignore for virtualenv, selenium, and Ubuntu
# Ignore system files and folders - Ubuntu
*.*~
# Ignore Python related files
*.py[cod]
__pycache__/
.cache/
# Ignore virtualenv files and folders
pip-selfcheck.json
@petarnikolovski
petarnikolovski / recommendations.md
Last active July 18, 2021 22:49
Few Recommendations for Python Beginners
@petarnikolovski
petarnikolovski / prometheus.md
Last active October 12, 2021 01:19
Prometheus 2.x installation on Ubuntu 16.04 server.

Installing Prometheus on Ubuntu 16.04

This gist is a compilation of two tutorials. You can find the original tutorials here and here. What should you know before using this? Everything can be executed from the home folder. For easier cleanup at the end you can make directory where you'll download everything, and then just use rm -rf .. Although, you should be careful. If some strange bugs arise unexpectedly somewhere sometimes, just keep in mind that some user names have underscores in them (this is probably nothing to worry about).

Create Users

sudo adduser --no-create-home --disabled-login --shell /bin/false --gecos "Prometheus Monitoring User" prometheus
sudo adduser --no-create-home --disabled-login --shell /bin/false --gecos "Node Exporter User" node_exporter
sudo adduser --no-create-home --disabled-login --shell /bin/false --gecos "Alertm
@petarnikolovski
petarnikolovski / prometheus.sh
Last active March 28, 2021 23:59
Prometheus 2.x installation on Ubuntu 16.04 server.
#!/bin/bash
# Ubuntu 16.04
# Prometheus installation. It's a lousy script though.
# Example:
# chmod +x prometheus.sh
# sudo pwd
# ./prometheus.sh
@petarnikolovski
petarnikolovski / http-get-dos.conf
Last active July 13, 2021 09:44
Fail2ban Configuration
# Fail2Ban configuration file
#
# NOTE
# You should set up in the jail.conf file, the maxretry and findtime carefully in order to avoid false positives.
#
# Author: http://www.go2linux.org
# Modified by: samnicholls.net
# * Mon 6 Jun 2016 - Updated failregex to capture HOST group correctly
[Definition]
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 9000
class MyHandler(BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
@petarnikolovski
petarnikolovski / server.py
Created July 25, 2018 15:33 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):
@petarnikolovski
petarnikolovski / corsdevserver.py
Created July 25, 2018 15:48 — forked from igniteflow/corsdevserver.py
A simple CORS compliant web server in Python, useful for development (with @alex-moon)
import BaseHTTPServer
import cgi
from pprint import pformat
PORT = 6969
FILE_TO_SERVE = 'path/to/your/response/content.json'
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""
@petarnikolovski
petarnikolovski / users.py
Created December 7, 2018 21:40
Python permissions checks using decorator
import sqlite3
from pathlib import Path
from functools import wraps
"""
This is a dummy implementation of the privilege-based checks based on the following article:
https://lostechies.com/derickbailey/2011/05/24/dont-do-role-based-authorization-checks-do-activity-based-checks/
"""