Skip to content

Instantly share code, notes, and snippets.

View ooduor's full-sized avatar
🏠
Working from home

Antony Oduor ooduor

🏠
Working from home
View GitHub Profile
@ooduor
ooduor / disk-usage-alert.sh
Created December 22, 2021 03:07 — forked from M1ke/disk-usage-alert.sh
A shell script to check your disk usage and alert you if it hits a limit. Change the value (percentage) in the "if" statement on line 7 to alter the threshold. Change the email address to your email address. See readme for mail.cf instructions and crontab.
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
used=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $used -ge 80 ]; then
echo "The partition \"$partition\" on $(hostname) has used $used% at $(date)" | mail -s "Disk space alert: $used% used" your@email.com
fi
done
#!/usr/bin/env python
'''Crop an image to just the portions containing text.
Usage:
./crop_morphology.py path/to/image.jpg
This will place the cropped image in path/to/image.crop.png.
For details on the methodology, see
@bigsnarfdude
bigsnarfdude / gist:d811e31ee17495f82f10db12651ae82d
Last active May 19, 2022 12:18
[boundingBox] opencv example python - Contours – bounding box, minimum area rectangle, and minimum enclosing circle
import cv2
import numpy as np
# read and scale down image
# wget https://bigsnarf.files.wordpress.com/2017/05/hammer.png #black and white
# wget https://i1.wp.com/images.hgmsites.net/hug/2011-volvo-s60_100323431_h.jpg
img = cv2.pyrDown(cv2.imread('2011-volvo-s60_100323431_h.jpg', cv2.IMREAD_UNCHANGED))
# threshold image
ret, threshed_img = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY),
@macdja38
macdja38 / Discord Join Messages
Created April 21, 2017 07:12
All the discord join messages
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN: "[!!{username}!!](usernameOnClick) just joined the server - glhf!",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_01: "[!!{username}!!](usernameOnClick) just joined. Everyone, look busy!",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_02: "[!!{username}!!](usernameOnClick) just joined. Can I get a heal?",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_03: "[!!{username}!!](usernameOnClick) joined your party.",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_04: "[!!{username}!!](usernameOnClick) joined. You must construct additional pylons.",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_05: "Ermagherd. [!!{username}!!](usernameOnClick) is here.",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_06: "Welcome, [!!{username}!!](usernameOnClick). Stay awhile and listen.",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_07: "Welcome, [!!{username}!!](usernameOnClick). We were expecting you ( ͡° ͜ʖ ͡°)",
SYSTEM_MESSAGE_GUILD_MEMBER_JOIN_08: "Welcome, [!!{username}!!](usernameOnClick). We hope you brought pi
@carlsmith
carlsmith / replace.py
Created April 5, 2017 02:08
A Python function that does multiple string replace ops in a single pass.
import re
def replace(string, substitutions):
substrings = sorted(substitutions, key=len, reverse=True)
regex = re.compile('|'.join(map(re.escape, substrings)))
return regex.sub(lambda match: substitutions[match.group(0)], string)
@Spindel
Spindel / model.py
Last active March 22, 2023 01:19
Interview question model.
import uuid
import random
from afase.models.meta import Base
from sqlalchemy import (
Column,
Text,
Date,
ForeignKey,
@pylover
pylover / a2dp.py
Last active May 27, 2024 21:51
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04, 16.10 and also debian jessie, with bluez5.
#! /usr/bin/env python3
"""Fixing bluetooth stereo headphone/headset problem in debian distros.
Workaround for bug: https://bugs.launchpad.net/ubuntu/+source/indicator-sound/+bug/1577197
Run it with python3.5 or higher after pairing/connecting the bluetooth stereo headphone.
This will be only fixes the bluez5 problem mentioned above .
Licence: Freeware
@vitorfs
vitorfs / example.html
Last active August 23, 2023 05:44
Startswith Template Filter
{% load startswith %}
<li{% if request.path|startswith:'/settings/' %} class="active"{% endif %}>
@poppingtonic
poppingtonic / passphrase_gen.py
Last active August 1, 2019 19:45
This script generates a list of 9 words as a "strong-enough" passphrase generator. My attempt, based on python 3.6's secrets module, to justifiably disobey the Diceware recommendation against computer-based RNGs: http://world.std.com/~reinhold/diceware.html
#!/usr/bin/env python
# requires python 3.6 and requests
import os
import re
import secrets
import requests
wordlist_file = 'diceware.wordlist.asc'
@miohtama
miohtama / deform.py
Created January 15, 2016 20:49
Imperative creation of Deform forms
@simple_route("/review/{delivery_uuid}", route_name="review_public", renderer='views/review.html', append_slash=False)
def review(request, delivery_uuid):
"""Let user to leave a product for delivery.
One delivery can contain several product. Each product has Review SQL object instance generated at the time of creation. This form will let review
"""
delivery_uuid = slug_to_uuid(delivery_uuid)
delivery = DBSession.query(models.Delivery).filter_by(uuid=delivery_uuid).first()