Skip to content

Instantly share code, notes, and snippets.

View manuthu's full-sized avatar

Mike manuthu

View GitHub Profile
@manuthu
manuthu / mac_os_pic.py
Last active October 18, 2016 15:56
Take a picture on a mac using cv2
# The following gist uses python opencv2 (http://opencv.org) to take a pic
import cv2
def capture_image(image_file):
video = cv2.VideoCapture()
video.open(0)
_, image = video.retrieve()
video.release()
cv2.imwrite(image_file, image)
# install dependencies
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y cmake
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y pkg-config
sudo apt-get install -y python-numpy python-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libjpeg-dev libpng-dev libtiff-dev libjasper-dev
@manuthu
manuthu / delete-etl-dss-data.py
Last active July 4, 2017 05:48
Deletes data from jobs already executed by etl. Pre [Macros](https://doc.dataiku.com/dss/latest/operations/macros.html) this worked
ubuntu@etl:/etc/cron.daily$ cat delete-etl-dss-data-job.py
#!/usr/bin/env python
import datetime
import glob
import logging
import logging.handlers
import shutil
import subprocess
@manuthu
manuthu / ssl_server.py
Last active January 26, 2018 09:43
Simple Python SSL Server
"""
Generate a server.key and server.cert.
>> mike:tmp$ openssl req -nodes -new -x509 -keyout server.key -out server.cert
Combine the generated keys.
>> mike:tmp$ cat server.key server.cert > server.pem
Now run the script
@manuthu
manuthu / vagrant-ssh-configurations.sh
Created August 17, 2017 11:44
vagrant ssh configurations
~: vagrant ssh-config
Host webserver1
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/Mike/projects/sandbox/haproxylab/.vagrant/machines/webserver1/virtualbox/private_key
IdentitiesOnly yes
@manuthu
manuthu / get-ip-address.md
Last active October 2, 2017 18:54
libvirt fetch IP address from a domain

View running domains

~ virsh list --all
 Id    Name                           State
----------------------------------------------------
 15    compute.local                  running
 16    storage.local                  running
@manuthu
manuthu / gist:daa278db35ba7ab25e8dbbe68208b060
Created December 21, 2017 17:53 — forked from mbirtwell/gist:aaccdb7972e1a7ed094b
SQLAlchemy Enum recipe enhanced for use in postgresql arrays
# Based on http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/
import six
from sqlalchemy.dialects import postgresql
from sqlalchemy.types import SchemaType, TypeDecorator, Enum
from sqlalchemy import __version__, text, cast
import re
if __version__ < '0.6.5':
raise NotImplementedError("Version 0.6.5 or higher of SQLAlchemy is required.")
import logging
import json
from flask import Flask, current_app, jsonify
from flask import request
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)
@manuthu
manuthu / blockips.py
Last active April 2, 2018 12:34
Block IP with a connection to the server on Port 80, 443, 22. If there are more than specified connections, use iptables drop the connections.
#!/root/env/bin/python
import argparse
import iptc
import logging
import time
from bash import bash
from ipwhois import IPWhois
@manuthu
manuthu / ipblock.py
Created December 4, 2018 16:03
IP Block with signal handling
#!/opt/venv/ipblock/env/bin/python
__author__ = 'Mike Manuthu <muragumichael@gmail.com>'
"""
A simple script to disable the number of connections to the server.
Uses IPTables to block the IPS with more than the threshold connections.
Uses Fail2Ban as the default IP Blocker.
usage: IP Blocker :: [-h] [-i IP] [-I IPRANGE] [-c CONNECTIONS] [-B]
[-f FREQUENCY]